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,3 @@
import type { AppRouteHandlerFn, AppRouteHandlers } from '../module';
import { type HTTP_METHOD } from '../../../web/http';
export declare function autoImplementMethods(handlers: AppRouteHandlers): Record<HTTP_METHOD, AppRouteHandlerFn>;
@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "autoImplementMethods", {
enumerable: true,
get: function() {
return autoImplementMethods;
}
});
const _http = require("../../../web/http");
const AUTOMATIC_ROUTE_METHODS = [
'HEAD',
'OPTIONS'
];
function handleMethodNotAllowedResponse() {
return new Response(null, {
status: 405
});
}
function autoImplementMethods(handlers) {
// Loop through all the HTTP methods to create the initial methods object.
// Each of the methods will be set to the 405 response handler.
const methods = _http.HTTP_METHODS.reduce((acc, method)=>({
...acc,
// If the userland module implements the method, then use it. Otherwise,
// use the 405 response handler.
[method]: handlers[method] ?? handleMethodNotAllowedResponse
}), {});
// Get all the methods that could be automatically implemented that were not
// implemented by the userland module.
const implemented = new Set(_http.HTTP_METHODS.filter((method)=>handlers[method]));
const missing = AUTOMATIC_ROUTE_METHODS.filter((method)=>!implemented.has(method));
// Loop over the missing methods to automatically implement them if we can.
for (const method of missing){
// If the userland module doesn't implement the HEAD method, then
// we'll automatically implement it by calling the GET method (if it
// exists).
if (method === 'HEAD') {
if (handlers.GET) {
// Implement the HEAD method by calling the GET method.
methods.HEAD = handlers.GET;
// Mark it as implemented.
implemented.add('HEAD');
}
continue;
}
// If OPTIONS is not provided then implement it.
if (method === 'OPTIONS') {
// TODO: check if HEAD is implemented, if so, use it to add more headers
// Get all the methods that were implemented by the userland module.
const allow = [
'OPTIONS',
...implemented
];
// If the list of methods doesn't include HEAD, but it includes GET, then
// add HEAD as it's automatically implemented.
if (!implemented.has('HEAD') && implemented.has('GET')) {
allow.push('HEAD');
}
// Sort and join the list with commas to create the `Allow` header. See:
// https://httpwg.org/specs/rfc9110.html#field.allow
const headers = {
Allow: allow.sort().join(', ')
};
// Implement the OPTIONS method by returning a 204 response with the
// `Allow` header.
methods.OPTIONS = ()=>new Response(null, {
status: 204,
headers
});
// Mark this method as implemented.
implemented.add('OPTIONS');
continue;
}
throw Object.defineProperty(new Error(`Invariant: should handle all automatic implementable methods, got method: ${method}`), "__NEXT_ERROR_CODE", {
value: "E211",
enumerable: false,
configurable: true
});
}
return methods;
}
//# sourceMappingURL=auto-implement-methods.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/route-modules/app-route/helpers/auto-implement-methods.ts"],"sourcesContent":["import type { AppRouteHandlerFn, AppRouteHandlers } from '../module'\n\nimport { HTTP_METHODS, type HTTP_METHOD } from '../../../web/http'\n\nconst AUTOMATIC_ROUTE_METHODS = ['HEAD', 'OPTIONS'] as const\n\nfunction handleMethodNotAllowedResponse(): Response {\n return new Response(null, { status: 405 })\n}\n\nexport function autoImplementMethods(\n handlers: AppRouteHandlers\n): Record<HTTP_METHOD, AppRouteHandlerFn> {\n // Loop through all the HTTP methods to create the initial methods object.\n // Each of the methods will be set to the 405 response handler.\n const methods: Record<HTTP_METHOD, AppRouteHandlerFn> = HTTP_METHODS.reduce(\n (acc, method) => ({\n ...acc,\n // If the userland module implements the method, then use it. Otherwise,\n // use the 405 response handler.\n [method]: handlers[method] ?? handleMethodNotAllowedResponse,\n }),\n {} as Record<HTTP_METHOD, AppRouteHandlerFn>\n )\n\n // Get all the methods that could be automatically implemented that were not\n // implemented by the userland module.\n const implemented = new Set(HTTP_METHODS.filter((method) => handlers[method]))\n const missing = AUTOMATIC_ROUTE_METHODS.filter(\n (method) => !implemented.has(method)\n )\n\n // Loop over the missing methods to automatically implement them if we can.\n for (const method of missing) {\n // If the userland module doesn't implement the HEAD method, then\n // we'll automatically implement it by calling the GET method (if it\n // exists).\n if (method === 'HEAD') {\n if (handlers.GET) {\n // Implement the HEAD method by calling the GET method.\n methods.HEAD = handlers.GET\n\n // Mark it as implemented.\n implemented.add('HEAD')\n }\n continue\n }\n\n // If OPTIONS is not provided then implement it.\n if (method === 'OPTIONS') {\n // TODO: check if HEAD is implemented, if so, use it to add more headers\n\n // Get all the methods that were implemented by the userland module.\n const allow: HTTP_METHOD[] = ['OPTIONS', ...implemented]\n\n // If the list of methods doesn't include HEAD, but it includes GET, then\n // add HEAD as it's automatically implemented.\n if (!implemented.has('HEAD') && implemented.has('GET')) {\n allow.push('HEAD')\n }\n\n // Sort and join the list with commas to create the `Allow` header. See:\n // https://httpwg.org/specs/rfc9110.html#field.allow\n const headers = { Allow: allow.sort().join(', ') }\n\n // Implement the OPTIONS method by returning a 204 response with the\n // `Allow` header.\n methods.OPTIONS = () => new Response(null, { status: 204, headers })\n\n // Mark this method as implemented.\n implemented.add('OPTIONS')\n\n continue\n }\n\n throw new Error(\n `Invariant: should handle all automatic implementable methods, got method: ${method}`\n )\n }\n\n return methods\n}\n"],"names":["autoImplementMethods","AUTOMATIC_ROUTE_METHODS","handleMethodNotAllowedResponse","Response","status","handlers","methods","HTTP_METHODS","reduce","acc","method","implemented","Set","filter","missing","has","GET","HEAD","add","allow","push","headers","Allow","sort","join","OPTIONS","Error"],"mappings":";;;;+BAUgBA;;;eAAAA;;;sBAR+B;AAE/C,MAAMC,0BAA0B;IAAC;IAAQ;CAAU;AAEnD,SAASC;IACP,OAAO,IAAIC,SAAS,MAAM;QAAEC,QAAQ;IAAI;AAC1C;AAEO,SAASJ,qBACdK,QAA0B;IAE1B,0EAA0E;IAC1E,+DAA+D;IAC/D,MAAMC,UAAkDC,kBAAY,CAACC,MAAM,CACzE,CAACC,KAAKC,SAAY,CAAA;YAChB,GAAGD,GAAG;YACN,wEAAwE;YACxE,gCAAgC;YAChC,CAACC,OAAO,EAAEL,QAAQ,CAACK,OAAO,IAAIR;QAChC,CAAA,GACA,CAAC;IAGH,4EAA4E;IAC5E,sCAAsC;IACtC,MAAMS,cAAc,IAAIC,IAAIL,kBAAY,CAACM,MAAM,CAAC,CAACH,SAAWL,QAAQ,CAACK,OAAO;IAC5E,MAAMI,UAAUb,wBAAwBY,MAAM,CAC5C,CAACH,SAAW,CAACC,YAAYI,GAAG,CAACL;IAG/B,2EAA2E;IAC3E,KAAK,MAAMA,UAAUI,QAAS;QAC5B,iEAAiE;QACjE,oEAAoE;QACpE,WAAW;QACX,IAAIJ,WAAW,QAAQ;YACrB,IAAIL,SAASW,GAAG,EAAE;gBAChB,uDAAuD;gBACvDV,QAAQW,IAAI,GAAGZ,SAASW,GAAG;gBAE3B,0BAA0B;gBAC1BL,YAAYO,GAAG,CAAC;YAClB;YACA;QACF;QAEA,gDAAgD;QAChD,IAAIR,WAAW,WAAW;YACxB,wEAAwE;YAExE,oEAAoE;YACpE,MAAMS,QAAuB;gBAAC;mBAAcR;aAAY;YAExD,yEAAyE;YACzE,8CAA8C;YAC9C,IAAI,CAACA,YAAYI,GAAG,CAAC,WAAWJ,YAAYI,GAAG,CAAC,QAAQ;gBACtDI,MAAMC,IAAI,CAAC;YACb;YAEA,wEAAwE;YACxE,oDAAoD;YACpD,MAAMC,UAAU;gBAAEC,OAAOH,MAAMI,IAAI,GAAGC,IAAI,CAAC;YAAM;YAEjD,oEAAoE;YACpE,kBAAkB;YAClBlB,QAAQmB,OAAO,GAAG,IAAM,IAAItB,SAAS,MAAM;oBAAEC,QAAQ;oBAAKiB;gBAAQ;YAElE,mCAAmC;YACnCV,YAAYO,GAAG,CAAC;YAEhB;QACF;QAEA,MAAM,qBAEL,CAFK,IAAIQ,MACR,CAAC,0EAA0E,EAAEhB,QAAQ,GADjF,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF;IAEA,OAAOJ;AACT","ignoreList":[0]}
@@ -0,0 +1,7 @@
/**
* Cleans a URL by stripping the protocol, host, and search params.
*
* @param urlString the url to clean
* @returns the cleaned url
*/
export declare function cleanURL(url: string | URL): URL;
@@ -0,0 +1,24 @@
/**
* Cleans a URL by stripping the protocol, host, and search params.
*
* @param urlString the url to clean
* @returns the cleaned url
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "cleanURL", {
enumerable: true,
get: function() {
return cleanURL;
}
});
function cleanURL(url) {
const u = new URL(url);
u.host = 'localhost:3000';
u.search = '';
u.protocol = 'http';
return u;
}
//# sourceMappingURL=clean-url.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/route-modules/app-route/helpers/clean-url.ts"],"sourcesContent":["/**\n * Cleans a URL by stripping the protocol, host, and search params.\n *\n * @param urlString the url to clean\n * @returns the cleaned url\n */\n\nexport function cleanURL(url: string | URL): URL {\n const u = new URL(url)\n u.host = 'localhost:3000'\n u.search = ''\n u.protocol = 'http'\n return u\n}\n"],"names":["cleanURL","url","u","URL","host","search","protocol"],"mappings":"AAAA;;;;;CAKC;;;;+BAEeA;;;eAAAA;;;AAAT,SAASA,SAASC,GAAiB;IACxC,MAAMC,IAAI,IAAIC,IAAIF;IAClBC,EAAEE,IAAI,GAAG;IACTF,EAAEG,MAAM,GAAG;IACXH,EAAEI,QAAQ,GAAG;IACb,OAAOJ;AACT","ignoreList":[0]}
@@ -0,0 +1,7 @@
/**
* Get pathname from absolute path.
*
* @param absolutePath the absolute path
* @returns the pathname
*/
export declare function getPathnameFromAbsolutePath(absolutePath: string): string;
@@ -0,0 +1,29 @@
/**
* Get pathname from absolute path.
*
* @param absolutePath the absolute path
* @returns the pathname
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getPathnameFromAbsolutePath", {
enumerable: true,
get: function() {
return getPathnameFromAbsolutePath;
}
});
function getPathnameFromAbsolutePath(absolutePath) {
// Remove prefix including app dir
let appDir = '/app/';
if (!absolutePath.includes(appDir)) {
appDir = '\\app\\';
}
const [, ...parts] = absolutePath.split(appDir);
const relativePath = appDir[0] + parts.join(appDir);
// remove extension
const pathname = relativePath.split('.').slice(0, -1).join('.');
return pathname;
}
//# sourceMappingURL=get-pathname-from-absolute-path.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/route-modules/app-route/helpers/get-pathname-from-absolute-path.ts"],"sourcesContent":["/**\n * Get pathname from absolute path.\n *\n * @param absolutePath the absolute path\n * @returns the pathname\n */\nexport function getPathnameFromAbsolutePath(absolutePath: string) {\n // Remove prefix including app dir\n let appDir = '/app/'\n if (!absolutePath.includes(appDir)) {\n appDir = '\\\\app\\\\'\n }\n const [, ...parts] = absolutePath.split(appDir)\n const relativePath = appDir[0] + parts.join(appDir)\n\n // remove extension\n const pathname = relativePath.split('.').slice(0, -1).join('.')\n return pathname\n}\n"],"names":["getPathnameFromAbsolutePath","absolutePath","appDir","includes","parts","split","relativePath","join","pathname","slice"],"mappings":"AAAA;;;;;CAKC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,4BAA4BC,YAAoB;IAC9D,kCAAkC;IAClC,IAAIC,SAAS;IACb,IAAI,CAACD,aAAaE,QAAQ,CAACD,SAAS;QAClCA,SAAS;IACX;IACA,MAAM,GAAG,GAAGE,MAAM,GAAGH,aAAaI,KAAK,CAACH;IACxC,MAAMI,eAAeJ,MAAM,CAAC,EAAE,GAAGE,MAAMG,IAAI,CAACL;IAE5C,mBAAmB;IACnB,MAAMM,WAAWF,aAAaD,KAAK,CAAC,KAAKI,KAAK,CAAC,GAAG,CAAC,GAAGF,IAAI,CAAC;IAC3D,OAAOC;AACT","ignoreList":[0]}
@@ -0,0 +1,2 @@
import type { AppRouteModule } from '../module.compiled';
export declare function isStaticGenEnabled(mod: AppRouteModule['routeModule']['userland']): boolean;
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "isStaticGenEnabled", {
enumerable: true,
get: function() {
return isStaticGenEnabled;
}
});
function isStaticGenEnabled(mod) {
return mod.dynamic === 'force-static' || mod.dynamic === 'error' || mod.revalidate === false || mod.revalidate !== undefined && mod.revalidate > 0 || typeof mod.generateStaticParams == 'function';
}
//# sourceMappingURL=is-static-gen-enabled.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/route-modules/app-route/helpers/is-static-gen-enabled.ts"],"sourcesContent":["import type { AppRouteModule } from '../module.compiled'\n\n// route handlers are only statically optimized if they define\n// one of these top-level configs manually\n// - dynamic = 'force-static'\n// - dynamic = 'error'\n// - revalidate > 0\n// - revalidate = false\n// - generateStaticParams\nexport function isStaticGenEnabled(\n mod: AppRouteModule['routeModule']['userland']\n) {\n return (\n mod.dynamic === 'force-static' ||\n mod.dynamic === 'error' ||\n mod.revalidate === false ||\n (mod.revalidate !== undefined && mod.revalidate > 0) ||\n typeof mod.generateStaticParams == 'function'\n )\n}\n"],"names":["isStaticGenEnabled","mod","dynamic","revalidate","undefined","generateStaticParams"],"mappings":";;;;+BASgBA;;;eAAAA;;;AAAT,SAASA,mBACdC,GAA8C;IAE9C,OACEA,IAAIC,OAAO,KAAK,kBAChBD,IAAIC,OAAO,KAAK,WAChBD,IAAIE,UAAU,KAAK,SAClBF,IAAIE,UAAU,KAAKC,aAAaH,IAAIE,UAAU,GAAG,KAClD,OAAOF,IAAII,oBAAoB,IAAI;AAEvC","ignoreList":[0]}
@@ -0,0 +1,8 @@
import type { ParsedUrlQuery } from 'querystring';
/**
* Converts the query into params.
*
* @param query the query to convert to params
* @returns the params
*/
export declare function parsedUrlQueryToParams(query: ParsedUrlQuery): Record<string, string | string[]>;
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "parsedUrlQueryToParams", {
enumerable: true,
get: function() {
return parsedUrlQueryToParams;
}
});
function parsedUrlQueryToParams(query) {
const params = {};
for (const [key, value] of Object.entries(query)){
if (typeof value === 'undefined') continue;
params[key] = value;
}
return params;
}
//# sourceMappingURL=parsed-url-query-to-params.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/route-modules/app-route/helpers/parsed-url-query-to-params.ts"],"sourcesContent":["import type { ParsedUrlQuery } from 'querystring'\n\n/**\n * Converts the query into params.\n *\n * @param query the query to convert to params\n * @returns the params\n */\nexport function parsedUrlQueryToParams(\n query: ParsedUrlQuery\n): Record<string, string | string[]> {\n const params: Record<string, string | string[]> = {}\n\n for (const [key, value] of Object.entries(query)) {\n if (typeof value === 'undefined') continue\n params[key] = value\n }\n\n return params\n}\n"],"names":["parsedUrlQueryToParams","query","params","key","value","Object","entries"],"mappings":";;;;+BAQgBA;;;eAAAA;;;AAAT,SAASA,uBACdC,KAAqB;IAErB,MAAMC,SAA4C,CAAC;IAEnD,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACL,OAAQ;QAChD,IAAI,OAAOG,UAAU,aAAa;QAClCF,MAAM,CAACC,IAAI,GAAGC;IAChB;IAEA,OAAOF;AACT","ignoreList":[0]}