This commit is contained in:
Kismet Hasanaj
2026-05-02 20:07:02 +02:00
parent ce8672e283
commit 34dc9aec52
9428 changed files with 1733330 additions and 0 deletions
@@ -0,0 +1,8 @@
import { RouteMatcher } from './route-matcher';
export class AppPageRouteMatcher extends RouteMatcher {
get identity() {
return `${this.definition.pathname}?__nextPage=${this.definition.page}`;
}
}
//# sourceMappingURL=app-page-route-matcher.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/route-matchers/app-page-route-matcher.ts"],"sourcesContent":["import { RouteMatcher } from './route-matcher'\nimport type { AppPageRouteDefinition } from '../route-definitions/app-page-route-definition'\n\nexport class AppPageRouteMatcher extends RouteMatcher<AppPageRouteDefinition> {\n public get identity(): string {\n return `${this.definition.pathname}?__nextPage=${this.definition.page}`\n }\n}\n"],"names":["RouteMatcher","AppPageRouteMatcher","identity","definition","pathname","page"],"mappings":"AAAA,SAASA,YAAY,QAAQ,kBAAiB;AAG9C,OAAO,MAAMC,4BAA4BD;IACvC,IAAWE,WAAmB;QAC5B,OAAO,GAAG,IAAI,CAACC,UAAU,CAACC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAACD,UAAU,CAACE,IAAI,EAAE;IACzE;AACF","ignoreList":[0]}
@@ -0,0 +1,5 @@
import { RouteMatcher } from './route-matcher';
export class AppRouteRouteMatcher extends RouteMatcher {
}
//# sourceMappingURL=app-route-route-matcher.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/route-matchers/app-route-route-matcher.ts"],"sourcesContent":["import { RouteMatcher } from './route-matcher'\nimport type { AppRouteRouteDefinition } from '../route-definitions/app-route-route-definition'\n\nexport class AppRouteRouteMatcher extends RouteMatcher<AppRouteRouteDefinition> {}\n"],"names":["RouteMatcher","AppRouteRouteMatcher"],"mappings":"AAAA,SAASA,YAAY,QAAQ,kBAAiB;AAG9C,OAAO,MAAMC,6BAA6BD;AAAuC","ignoreList":[0]}
@@ -0,0 +1,58 @@
import { RouteMatcher } from './route-matcher';
export class LocaleRouteMatcher extends RouteMatcher {
/**
* Identity returns the identity part of the matcher. This is used to compare
* a unique matcher to another. This is also used when sorting dynamic routes,
* so it must contain the pathname part as well.
*/ get identity() {
var _this_definition_i18n;
return `${this.definition.pathname}?__nextLocale=${(_this_definition_i18n = this.definition.i18n) == null ? void 0 : _this_definition_i18n.locale}`;
}
/**
* Match will attempt to match the given pathname against this route while
* also taking into account the locale information.
*
* @param pathname The pathname to match against.
* @param options The options to use when matching.
* @returns The match result, or `null` if there was no match.
*/ match(pathname, options) {
var // If the options have a detected locale, then use that, otherwise use
// the route's locale.
_options_i18n, _this_definition_i18n;
// This is like the parent `match` method but instead this injects the
// additional `options` into the
const result = this.test(pathname, options);
if (!result) return null;
return {
definition: this.definition,
params: result.params,
detectedLocale: (options == null ? void 0 : (_options_i18n = options.i18n) == null ? void 0 : _options_i18n.detectedLocale) ?? ((_this_definition_i18n = this.definition.i18n) == null ? void 0 : _this_definition_i18n.locale)
};
}
/**
* Test will attempt to match the given pathname against this route while
* also taking into account the locale information.
*
* @param pathname The pathname to match against.
* @param options The options to use when matching.
* @returns The match result, or `null` if there was no match.
*/ test(pathname, options) {
// If this route has locale information and we have detected a locale, then
// we need to compare the detected locale to the route's locale.
if (this.definition.i18n && (options == null ? void 0 : options.i18n)) {
// If we have detected a locale and it does not match this route's locale,
// then this isn't a match!
if (this.definition.i18n.locale && options.i18n.detectedLocale && this.definition.i18n.locale !== options.i18n.detectedLocale) {
return null;
}
// Perform regular matching against the locale stripped pathname now, the
// locale information matches!
return super.test(options.i18n.pathname);
}
// If we don't have locale information, then we can just perform regular
// matching.
return super.test(pathname);
}
}
//# sourceMappingURL=locale-route-matcher.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/route-matchers/locale-route-matcher.ts"],"sourcesContent":["import type { LocaleAnalysisResult } from '../lib/i18n-provider'\nimport type { LocaleRouteDefinition } from '../route-definitions/locale-route-definition'\nimport type { LocaleRouteMatch } from '../route-matches/locale-route-match'\nimport { RouteMatcher } from './route-matcher'\n\nexport type LocaleMatcherMatchOptions = {\n /**\n * If defined, this indicates to the matcher that the request should be\n * treated as locale-aware. If this is undefined, it means that this\n * application was not configured for additional locales.\n */\n i18n?: LocaleAnalysisResult\n}\n\nexport class LocaleRouteMatcher<\n D extends LocaleRouteDefinition = LocaleRouteDefinition,\n> extends RouteMatcher<D> {\n /**\n * Identity returns the identity part of the matcher. This is used to compare\n * a unique matcher to another. This is also used when sorting dynamic routes,\n * so it must contain the pathname part as well.\n */\n public get identity(): string {\n return `${this.definition.pathname}?__nextLocale=${this.definition.i18n?.locale}`\n }\n\n /**\n * Match will attempt to match the given pathname against this route while\n * also taking into account the locale information.\n *\n * @param pathname The pathname to match against.\n * @param options The options to use when matching.\n * @returns The match result, or `null` if there was no match.\n */\n public match(\n pathname: string,\n options?: LocaleMatcherMatchOptions\n ): LocaleRouteMatch<D> | null {\n // This is like the parent `match` method but instead this injects the\n // additional `options` into the\n const result = this.test(pathname, options)\n if (!result) return null\n\n return {\n definition: this.definition,\n params: result.params,\n detectedLocale:\n // If the options have a detected locale, then use that, otherwise use\n // the route's locale.\n options?.i18n?.detectedLocale ?? this.definition.i18n?.locale,\n }\n }\n\n /**\n * Test will attempt to match the given pathname against this route while\n * also taking into account the locale information.\n *\n * @param pathname The pathname to match against.\n * @param options The options to use when matching.\n * @returns The match result, or `null` if there was no match.\n */\n public test(pathname: string, options?: LocaleMatcherMatchOptions) {\n // If this route has locale information and we have detected a locale, then\n // we need to compare the detected locale to the route's locale.\n if (this.definition.i18n && options?.i18n) {\n // If we have detected a locale and it does not match this route's locale,\n // then this isn't a match!\n if (\n this.definition.i18n.locale &&\n options.i18n.detectedLocale &&\n this.definition.i18n.locale !== options.i18n.detectedLocale\n ) {\n return null\n }\n\n // Perform regular matching against the locale stripped pathname now, the\n // locale information matches!\n return super.test(options.i18n.pathname)\n }\n\n // If we don't have locale information, then we can just perform regular\n // matching.\n return super.test(pathname)\n }\n}\n"],"names":["RouteMatcher","LocaleRouteMatcher","identity","definition","pathname","i18n","locale","match","options","result","test","params","detectedLocale"],"mappings":"AAGA,SAASA,YAAY,QAAQ,kBAAiB;AAW9C,OAAO,MAAMC,2BAEHD;IACR;;;;GAIC,GACD,IAAWE,WAAmB;YACuB;QAAnD,OAAO,GAAG,IAAI,CAACC,UAAU,CAACC,QAAQ,CAAC,cAAc,GAAE,wBAAA,IAAI,CAACD,UAAU,CAACE,IAAI,qBAApB,sBAAsBC,MAAM,EAAE;IACnF;IAEA;;;;;;;GAOC,GACD,AAAOC,MACLH,QAAgB,EAChBI,OAAmC,EACP;YAUxB,sEAAsE;QACtE,sBAAsB;QACtBA,eAAiC;QAXrC,sEAAsE;QACtE,gCAAgC;QAChC,MAAMC,SAAS,IAAI,CAACC,IAAI,CAACN,UAAUI;QACnC,IAAI,CAACC,QAAQ,OAAO;QAEpB,OAAO;YACLN,YAAY,IAAI,CAACA,UAAU;YAC3BQ,QAAQF,OAAOE,MAAM;YACrBC,gBAGEJ,CAAAA,4BAAAA,gBAAAA,QAASH,IAAI,qBAAbG,cAAeI,cAAc,OAAI,wBAAA,IAAI,CAACT,UAAU,CAACE,IAAI,qBAApB,sBAAsBC,MAAM;QACjE;IACF;IAEA;;;;;;;GAOC,GACD,AAAOI,KAAKN,QAAgB,EAAEI,OAAmC,EAAE;QACjE,2EAA2E;QAC3E,gEAAgE;QAChE,IAAI,IAAI,CAACL,UAAU,CAACE,IAAI,KAAIG,2BAAAA,QAASH,IAAI,GAAE;YACzC,0EAA0E;YAC1E,2BAA2B;YAC3B,IACE,IAAI,CAACF,UAAU,CAACE,IAAI,CAACC,MAAM,IAC3BE,QAAQH,IAAI,CAACO,cAAc,IAC3B,IAAI,CAACT,UAAU,CAACE,IAAI,CAACC,MAAM,KAAKE,QAAQH,IAAI,CAACO,cAAc,EAC3D;gBACA,OAAO;YACT;YAEA,yEAAyE;YACzE,8BAA8B;YAC9B,OAAO,KAAK,CAACF,KAAKF,QAAQH,IAAI,CAACD,QAAQ;QACzC;QAEA,wEAAwE;QACxE,YAAY;QACZ,OAAO,KAAK,CAACM,KAAKN;IACpB;AACF","ignoreList":[0]}
@@ -0,0 +1,8 @@
import { LocaleRouteMatcher } from './locale-route-matcher';
import { RouteMatcher } from './route-matcher';
export class PagesAPIRouteMatcher extends RouteMatcher {
}
export class PagesAPILocaleRouteMatcher extends LocaleRouteMatcher {
}
//# sourceMappingURL=pages-api-route-matcher.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/route-matchers/pages-api-route-matcher.ts"],"sourcesContent":["import type { PagesAPIRouteDefinition } from '../route-definitions/pages-api-route-definition'\nimport { LocaleRouteMatcher } from './locale-route-matcher'\nimport { RouteMatcher } from './route-matcher'\n\nexport class PagesAPIRouteMatcher extends RouteMatcher<PagesAPIRouteDefinition> {}\n\nexport class PagesAPILocaleRouteMatcher extends LocaleRouteMatcher<PagesAPIRouteDefinition> {}\n"],"names":["LocaleRouteMatcher","RouteMatcher","PagesAPIRouteMatcher","PagesAPILocaleRouteMatcher"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,YAAY,QAAQ,kBAAiB;AAE9C,OAAO,MAAMC,6BAA6BD;AAAuC;AAEjF,OAAO,MAAME,mCAAmCH;AAA6C","ignoreList":[0]}
@@ -0,0 +1,8 @@
import { LocaleRouteMatcher } from './locale-route-matcher';
import { RouteMatcher } from './route-matcher';
export class PagesRouteMatcher extends RouteMatcher {
}
export class PagesLocaleRouteMatcher extends LocaleRouteMatcher {
}
//# sourceMappingURL=pages-route-matcher.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/route-matchers/pages-route-matcher.ts"],"sourcesContent":["import type { PagesRouteDefinition } from '../route-definitions/pages-route-definition'\nimport { LocaleRouteMatcher } from './locale-route-matcher'\nimport { RouteMatcher } from './route-matcher'\n\nexport class PagesRouteMatcher extends RouteMatcher<PagesRouteDefinition> {}\n\nexport class PagesLocaleRouteMatcher extends LocaleRouteMatcher<PagesRouteDefinition> {}\n"],"names":["LocaleRouteMatcher","RouteMatcher","PagesRouteMatcher","PagesLocaleRouteMatcher"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,YAAY,QAAQ,kBAAiB;AAE9C,OAAO,MAAMC,0BAA0BD;AAAoC;AAE3E,OAAO,MAAME,gCAAgCH;AAA0C","ignoreList":[0]}
+44
View File
@@ -0,0 +1,44 @@
import { isDynamicRoute } from '../../shared/lib/router/utils';
import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher';
import { getRouteRegex } from '../../shared/lib/router/utils/route-regex';
export class RouteMatcher {
constructor(definition){
this.definition = definition;
if (isDynamicRoute(definition.pathname)) {
this.dynamic = getRouteMatcher(getRouteRegex(definition.pathname));
}
}
/**
* Identity returns the identity part of the matcher. This is used to compare
* a unique matcher to another. This is also used when sorting dynamic routes,
* so it must contain the pathname part.
*/ get identity() {
return this.definition.pathname;
}
get isDynamic() {
return this.dynamic !== undefined;
}
match(pathname) {
const result = this.test(pathname);
if (!result) return null;
return {
definition: this.definition,
params: result.params
};
}
test(pathname) {
if (this.dynamic) {
const params = this.dynamic(pathname);
if (!params) return null;
return {
params
};
}
if (pathname === this.definition.pathname) {
return {};
}
return null;
}
}
//# sourceMappingURL=route-matcher.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/route-matchers/route-matcher.ts"],"sourcesContent":["import type { RouteMatch } from '../route-matches/route-match'\nimport type { RouteDefinition } from '../route-definitions/route-definition'\nimport type { Params } from '../request/params'\n\nimport { isDynamicRoute } from '../../shared/lib/router/utils'\nimport {\n getRouteMatcher,\n type RouteMatchFn,\n} from '../../shared/lib/router/utils/route-matcher'\nimport { getRouteRegex } from '../../shared/lib/router/utils/route-regex'\n\ntype RouteMatchResult = {\n params?: Params\n}\n\nexport class RouteMatcher<D extends RouteDefinition = RouteDefinition> {\n private readonly dynamic?: RouteMatchFn\n\n /**\n * When set, this is an array of all the other matchers that are duplicates of\n * this one. This is used by the managers to warn the users about possible\n * duplicate matches on routes.\n */\n public duplicated?: Array<RouteMatcher>\n\n constructor(public readonly definition: D) {\n if (isDynamicRoute(definition.pathname)) {\n this.dynamic = getRouteMatcher(getRouteRegex(definition.pathname))\n }\n }\n\n /**\n * Identity returns the identity part of the matcher. This is used to compare\n * a unique matcher to another. This is also used when sorting dynamic routes,\n * so it must contain the pathname part.\n */\n public get identity(): string {\n return this.definition.pathname\n }\n\n public get isDynamic() {\n return this.dynamic !== undefined\n }\n\n public match(pathname: string): RouteMatch<D> | null {\n const result = this.test(pathname)\n if (!result) return null\n\n return { definition: this.definition, params: result.params }\n }\n\n public test(pathname: string): RouteMatchResult | null {\n if (this.dynamic) {\n const params = this.dynamic(pathname)\n if (!params) return null\n\n return { params }\n }\n\n if (pathname === this.definition.pathname) {\n return {}\n }\n\n return null\n }\n}\n"],"names":["isDynamicRoute","getRouteMatcher","getRouteRegex","RouteMatcher","constructor","definition","pathname","dynamic","identity","isDynamic","undefined","match","result","test","params"],"mappings":"AAIA,SAASA,cAAc,QAAQ,gCAA+B;AAC9D,SACEC,eAAe,QAEV,8CAA6C;AACpD,SAASC,aAAa,QAAQ,4CAA2C;AAMzE,OAAO,MAAMC;IAUXC,YAAY,AAAgBC,UAAa,CAAE;aAAfA,aAAAA;QAC1B,IAAIL,eAAeK,WAAWC,QAAQ,GAAG;YACvC,IAAI,CAACC,OAAO,GAAGN,gBAAgBC,cAAcG,WAAWC,QAAQ;QAClE;IACF;IAEA;;;;GAIC,GACD,IAAWE,WAAmB;QAC5B,OAAO,IAAI,CAACH,UAAU,CAACC,QAAQ;IACjC;IAEA,IAAWG,YAAY;QACrB,OAAO,IAAI,CAACF,OAAO,KAAKG;IAC1B;IAEOC,MAAML,QAAgB,EAAwB;QACnD,MAAMM,SAAS,IAAI,CAACC,IAAI,CAACP;QACzB,IAAI,CAACM,QAAQ,OAAO;QAEpB,OAAO;YAAEP,YAAY,IAAI,CAACA,UAAU;YAAES,QAAQF,OAAOE,MAAM;QAAC;IAC9D;IAEOD,KAAKP,QAAgB,EAA2B;QACrD,IAAI,IAAI,CAACC,OAAO,EAAE;YAChB,MAAMO,SAAS,IAAI,CAACP,OAAO,CAACD;YAC5B,IAAI,CAACQ,QAAQ,OAAO;YAEpB,OAAO;gBAAEA;YAAO;QAClB;QAEA,IAAIR,aAAa,IAAI,CAACD,UAAU,CAACC,QAAQ,EAAE;YACzC,OAAO,CAAC;QACV;QAEA,OAAO;IACT;AACF","ignoreList":[0]}