vector-framework 0.9.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/dist/cli/index.js +86 -88
- package/dist/cli/index.js.map +1 -1
- package/dist/cli.js +192 -161
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +3 -6
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +1 -2
- package/dist/core/server.js.map +1 -1
- package/dist/core/vector.d.ts.map +1 -1
- package/dist/core/vector.js +8 -4
- package/dist/core/vector.js.map +1 -1
- package/dist/dev/route-scanner.d.ts +5 -2
- package/dist/dev/route-scanner.d.ts.map +1 -1
- package/dist/dev/route-scanner.js +63 -16
- package/dist/dev/route-scanner.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/middleware/manager.d.ts.map +1 -1
- package/dist/middleware/manager.js +8 -1
- package/dist/middleware/manager.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/cli/index.ts +98 -109
- package/src/core/config-loader.ts +4 -10
- package/src/core/server.ts +1 -2
- package/src/core/vector.ts +9 -4
- package/src/dev/route-scanner.ts +76 -18
- package/src/middleware/manager.ts +7 -1
- package/src/types/index.ts +2 -0
package/dist/core/vector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector.js","sourceRoot":"","sources":["../../src/core/vector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uB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YAClB,SAAS,IAAI,KAAK,CACnB,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,CAA4B;QACjD,sBAAsB;IACxB,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,kEAAkE;QAClE,oDAAoD;IACtD,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,2CAA2C;IAC3C,MAAM,CAAC,aAAa;QAClB,MAAM,CAAC,QAAQ,GAAG,IAAW,CAAC;IAChC,CAAC;CACF;AAED,+BAA+B;AAC/B,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { GeneratedRoute } from
|
|
1
|
+
import type { GeneratedRoute } from "../types";
|
|
2
2
|
export declare class RouteScanner {
|
|
3
3
|
private routesDir;
|
|
4
|
-
|
|
4
|
+
private excludePatterns;
|
|
5
|
+
private static readonly DEFAULT_EXCLUDE_PATTERNS;
|
|
6
|
+
constructor(routesDir?: string, excludePatterns?: string[]);
|
|
5
7
|
scan(): Promise<GeneratedRoute[]>;
|
|
8
|
+
private isExcluded;
|
|
6
9
|
private scanDirectory;
|
|
7
10
|
enableWatch(callback: () => void): void;
|
|
8
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-scanner.d.ts","sourceRoot":"","sources":["../../src/dev/route-scanner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAS;
|
|
1
|
+
{"version":3,"file":"route-scanner.d.ts","sourceRoot":"","sources":["../../src/dev/route-scanner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAW;IAClC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAe9C;gBAEU,SAAS,SAAa,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE;IAOxD,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAqBvC,OAAO,CAAC,UAAU;YAuBJ,aAAa;IAuF3B,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI;CASjC"}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { existsSync, promises as fs } from
|
|
2
|
-
import { join, relative, resolve, sep } from
|
|
1
|
+
import { existsSync, promises as fs } from "node:fs";
|
|
2
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
3
3
|
export class RouteScanner {
|
|
4
4
|
routesDir;
|
|
5
|
-
|
|
5
|
+
excludePatterns;
|
|
6
|
+
static DEFAULT_EXCLUDE_PATTERNS = [
|
|
7
|
+
"*.test.ts",
|
|
8
|
+
"*.test.js",
|
|
9
|
+
"*.test.tsx",
|
|
10
|
+
"*.test.jsx",
|
|
11
|
+
"*.spec.ts",
|
|
12
|
+
"*.spec.js",
|
|
13
|
+
"*.spec.tsx",
|
|
14
|
+
"*.spec.jsx",
|
|
15
|
+
"*.tests.ts",
|
|
16
|
+
"*.tests.js",
|
|
17
|
+
"**/__tests__/**",
|
|
18
|
+
"*.interface.ts",
|
|
19
|
+
"*.type.ts",
|
|
20
|
+
"*.d.ts",
|
|
21
|
+
];
|
|
22
|
+
constructor(routesDir = "./routes", excludePatterns) {
|
|
6
23
|
// Always resolve from the current working directory (user's project)
|
|
7
24
|
this.routesDir = resolve(process.cwd(), routesDir);
|
|
25
|
+
this.excludePatterns =
|
|
26
|
+
excludePatterns || RouteScanner.DEFAULT_EXCLUDE_PATTERNS;
|
|
8
27
|
}
|
|
9
28
|
async scan() {
|
|
10
29
|
const routes = [];
|
|
@@ -16,7 +35,7 @@ export class RouteScanner {
|
|
|
16
35
|
await this.scanDirectory(this.routesDir, routes);
|
|
17
36
|
}
|
|
18
37
|
catch (error) {
|
|
19
|
-
if (error.code ===
|
|
38
|
+
if (error.code === "ENOENT") {
|
|
20
39
|
console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`);
|
|
21
40
|
return [];
|
|
22
41
|
}
|
|
@@ -24,7 +43,25 @@ export class RouteScanner {
|
|
|
24
43
|
}
|
|
25
44
|
return routes;
|
|
26
45
|
}
|
|
27
|
-
|
|
46
|
+
isExcluded(filePath) {
|
|
47
|
+
const relativePath = relative(this.routesDir, filePath);
|
|
48
|
+
for (const pattern of this.excludePatterns) {
|
|
49
|
+
// Convert glob pattern to regex
|
|
50
|
+
const regexPattern = pattern
|
|
51
|
+
.replace(/\./g, "\\.") // Escape dots
|
|
52
|
+
.replace(/\*/g, "[^/]*") // * matches anything except /
|
|
53
|
+
.replace(/\*\*/g, ".*") // ** matches anything including /
|
|
54
|
+
.replace(/\?/g, "."); // ? matches single character
|
|
55
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
56
|
+
// Check both the full relative path and just the filename
|
|
57
|
+
const filename = relativePath.split(sep).pop() || "";
|
|
58
|
+
if (regex.test(relativePath) || regex.test(filename)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
async scanDirectory(dir, routes, basePath = "") {
|
|
28
65
|
const entries = await fs.readdir(dir);
|
|
29
66
|
for (const entry of entries) {
|
|
30
67
|
const fullPath = join(dir, entry);
|
|
@@ -33,32 +70,42 @@ export class RouteScanner {
|
|
|
33
70
|
const newBasePath = basePath ? `${basePath}/${entry}` : entry;
|
|
34
71
|
await this.scanDirectory(fullPath, routes, newBasePath);
|
|
35
72
|
}
|
|
36
|
-
else if (entry.endsWith(
|
|
73
|
+
else if (entry.endsWith(".ts") || entry.endsWith(".js")) {
|
|
74
|
+
// Skip excluded files (test files, etc.)
|
|
75
|
+
if (this.isExcluded(fullPath)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
37
78
|
const routePath = relative(this.routesDir, fullPath)
|
|
38
|
-
.replace(/\.(ts|js)$/,
|
|
79
|
+
.replace(/\.(ts|js)$/, "")
|
|
39
80
|
.split(sep)
|
|
40
|
-
.join(
|
|
81
|
+
.join("/");
|
|
41
82
|
try {
|
|
42
83
|
// Convert Windows paths to URLs for import
|
|
43
|
-
const importPath = process.platform ===
|
|
84
|
+
const importPath = process.platform === "win32"
|
|
85
|
+
? `file:///${fullPath.replace(/\\/g, "/")}`
|
|
86
|
+
: fullPath;
|
|
44
87
|
const module = await import(importPath);
|
|
45
|
-
if (module.default && typeof module.default ===
|
|
88
|
+
if (module.default && typeof module.default === "function") {
|
|
46
89
|
routes.push({
|
|
47
|
-
name:
|
|
90
|
+
name: "default",
|
|
48
91
|
path: fullPath,
|
|
49
|
-
method:
|
|
92
|
+
method: "GET",
|
|
50
93
|
options: {
|
|
51
|
-
method:
|
|
94
|
+
method: "GET",
|
|
52
95
|
path: `/${routePath}`,
|
|
53
96
|
expose: true,
|
|
54
97
|
},
|
|
55
98
|
});
|
|
56
99
|
}
|
|
57
100
|
for (const [name, value] of Object.entries(module)) {
|
|
58
|
-
if (name ===
|
|
101
|
+
if (name === "default")
|
|
59
102
|
continue;
|
|
60
103
|
// Check for new RouteDefinition format
|
|
61
|
-
if (value &&
|
|
104
|
+
if (value &&
|
|
105
|
+
typeof value === "object" &&
|
|
106
|
+
"entry" in value &&
|
|
107
|
+
"options" in value &&
|
|
108
|
+
"handler" in value) {
|
|
62
109
|
const routeDef = value;
|
|
63
110
|
routes.push({
|
|
64
111
|
name,
|
|
@@ -90,7 +137,7 @@ export class RouteScanner {
|
|
|
90
137
|
}
|
|
91
138
|
}
|
|
92
139
|
enableWatch(callback) {
|
|
93
|
-
if (typeof Bun !==
|
|
140
|
+
if (typeof Bun !== "undefined" && Bun.env.NODE_ENV === "development") {
|
|
94
141
|
console.log(`Watching for route changes in ${this.routesDir}`);
|
|
95
142
|
setInterval(async () => {
|
|
96
143
|
await callback();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-scanner.js","sourceRoot":"","sources":["../../src/dev/route-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGzD,MAAM,OAAO,YAAY;IACf,SAAS,CAAS;
|
|
1
|
+
{"version":3,"file":"route-scanner.js","sourceRoot":"","sources":["../../src/dev/route-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGzD,MAAM,OAAO,YAAY;IACf,SAAS,CAAS;IAClB,eAAe,CAAW;IAC1B,MAAM,CAAU,wBAAwB,GAAG;QACjD,WAAW;QACX,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,YAAY;QACZ,YAAY;QACZ,iBAAiB;QACjB,gBAAgB;QAChB,WAAW;QACX,QAAQ;KACT,CAAC;IAEF,YAAY,SAAS,GAAG,UAAU,EAAE,eAA0B;QAC5D,qEAAqE;QACrE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,GAA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AAC,EAAE,CAAC;4BACnD,MAAM,CAAC,MAAM,EAAE,AAAD,EAAG,AAAD,EAAG,IAAI,CAAC,GAAG,KAAK,CAAC;4BACjC,MAAM,CAAC,IAAI,CAAC;gCACV,IAAI;gCACJ,IAAI,EAAE,QAAQ;gCACd,MAAM,EAAE,MAAgB;gCACxB,OAAO,EAAE;oCACP,MAAM,EAAE,MAAgB;oCACxB,IAAI,EAAE,IAAc;oCACpB,MAAM,EAAE,IAAI;iCACb;6BACF,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,WAAW,CAAC,QAAoB;QAC9B,IAAI,OAAO,GAAG,KAAK,WAAW,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;YACrE,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;YAE/D,WAAW,CAAC,KAAK,IAAI,EAAE;gBACrB,MAAM,QAAQ,EAAE,CAAC;YACnB,CAAC,EAAE,IAAI,CAAC,CAAC;QACX,CAAC;IACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var{defineProperty:T,getOwnPropertyNames:s,getOwnPropertyDescriptor:q}=Object,r=Object.prototype.hasOwnProperty;var Z=new WeakMap,t=(i)=>{var f=Z.get(i),l;if(f)return f;if(f=T({},"__esModule",{value:!0}),i&&typeof i==="object"||typeof i==="function")s(i).map((a)=>!r.call(f,a)&&T(f,a,{get:()=>i[a],enumerable:!(l=q(i,a))||l.enumerable}));return Z.set(i,f),f};var o=(i,f)=>{for(var l in f)T(i,l,{get:f[l],enumerable:!0,configurable:!0,set:(a)=>f[l]=()=>a})};var Di={};o(Di,{route:()=>y,createResponse:()=>P,APIError:()=>C});module.exports=t(Di);var b=(i="text/plain; charset=utf-8",f)=>(l,a={})=>{if(l===void 0||l instanceof Response)return l;let E=new Response(f?.(l)??l,a.url?void 0:a);return E.headers.set("content-type",i),E},wi=b("application/json; charset=utf-8",JSON.stringify);var Li=b("text/plain; charset=utf-8",String),Ri=b("text/html"),Ci=b("image/jpeg"),Ui=b("image/png"),$i=b("image/webp"),c=async(i)=>{i.content=i.body?await i.clone().json().catch(()=>i.clone().formData()).catch(()=>i.text()):void 0},g=(i)=>{i.cookies=(i.headers.get("Cookie")||"").split(/;\s*/).map((f)=>f.split(/=(.+)/)).reduce((f,[l,a])=>a?(f[l]=a,f):f,{})},G=(i={})=>{let{origin:f="*",credentials:l=!1,allowMethods:a="*",allowHeaders:E,exposeHeaders:A,maxAge:d}=i,_=(O)=>{let N=O?.headers.get("origin");return f===!0?N:f instanceof RegExp?f.test(N)?N:void 0:Array.isArray(f)?f.includes(N)?N:void 0:f instanceof Function?f(N):f=="*"&&l?N:f},I=(O,N)=>{for(let[w,L]of Object.entries(N))L&&O.headers.append(w,L);return O};return{corsify:(O,N)=>O?.headers?.get("access-control-allow-origin")||O.status==101?O:I(O.clone(),{"access-control-allow-origin":_(N),"access-control-allow-credentials":l}),preflight:(O)=>{if(O.method=="OPTIONS"){let N=new Response(null,{status:204});return I(N,{"access-control-allow-origin":_(O),"access-control-allow-methods":a?.join?.(",")??a,"access-control-expose-headers":A?.join?.(",")??A,"access-control-allow-headers":E?.join?.(",")??E??O.headers.get("access-control-request-headers"),"access-control-max-age":d,"access-control-allow-credentials":l})}}}};var R={OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,IM_A_TEAPOT:418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511},B={PORT:3000,HOSTNAME:"localhost",ROUTES_DIR:"./routes",CACHE_TTL:0,CORS_MAX_AGE:86400},j={JSON:"application/json",TEXT:"text/plain",HTML:"text/html",FORM_URLENCODED:"application/x-www-form-urlencoded",MULTIPART:"multipart/form-data"};class Y{protectedHandler=null;setProtectedHandler(i){this.protectedHandler=i}async authenticate(i){if(!this.protectedHandler)throw new Error("Protected handler not configured. Use vector.protected() to set authentication handler.");try{let f=await this.protectedHandler(i);return i.authUser=f,f}catch(f){throw new Error(`Authentication failed: ${f instanceof Error?f.message:String(f)}`)}}isAuthenticated(i){return!!i.authUser}getUser(i){return i.authUser||null}}class Q{cacheHandler=null;memoryCache=new Map;cleanupInterval=null;setCacheHandler(i){this.cacheHandler=i}async get(i,f,l=B.CACHE_TTL){if(l<=0)return f();if(this.cacheHandler)return this.cacheHandler(i,f,l);return this.getFromMemoryCache(i,f,l)}async getFromMemoryCache(i,f,l){let a=Date.now(),E=this.memoryCache.get(i);if(this.isCacheValid(E,a))return E.value;let A=await f();return this.setInMemoryCache(i,A,l),A}isCacheValid(i,f){return i!==void 0&&i.expires>f}setInMemoryCache(i,f,l){let a=Date.now()+l*1000;this.memoryCache.set(i,{value:f,expires:a}),this.scheduleCleanup()}scheduleCleanup(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanupExpired()},60000)}cleanupExpired(){let i=Date.now();for(let[f,l]of this.memoryCache.entries())if(l.expires<=i)this.memoryCache.delete(f);if(this.memoryCache.size===0&&this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}clear(){if(this.memoryCache.clear(),this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}async set(i,f,l=B.CACHE_TTL){if(l<=0)return;if(this.cacheHandler){await this.cacheHandler(i,async()=>f,l);return}this.setInMemoryCache(i,f,l)}delete(i){return this.memoryCache.delete(i)}has(i){let f=this.memoryCache.get(i);if(!f)return!1;if(f.expires<=Date.now())return this.memoryCache.delete(i),!1;return!0}generateKey(i,f){let l=new URL(i.url);return[i.method,l.pathname,l.search,f?.authUser?.id||"anonymous"].join(":")}}var z=(()=>({}));function U(i){if(typeof i!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function k(i,f){var l="",a=0,E=-1,A=0,d;for(var _=0;_<=i.length;++_){if(_<i.length)d=i.charCodeAt(_);else if(d===47)break;else d=47;if(d===47){if(E===_-1||A===1);else if(E!==_-1&&A===2){if(l.length<2||a!==2||l.charCodeAt(l.length-1)!==46||l.charCodeAt(l.length-2)!==46){if(l.length>2){var I=l.lastIndexOf("/");if(I!==l.length-1){if(I===-1)l="",a=0;else l=l.slice(0,I),a=l.length-1-l.lastIndexOf("/");E=_,A=0;continue}}else if(l.length===2||l.length===1){l="",a=0,E=_,A=0;continue}}if(f){if(l.length>0)l+="/..";else l="..";a=2}}else{if(l.length>0)l+="/"+i.slice(E+1,_);else l=i.slice(E+1,_);a=_-E-1}E=_,A=0}else if(d===46&&A!==-1)++A;else A=-1}return l}function p(i,f){var l=f.dir||f.root,a=f.base||(f.name||"")+(f.ext||"");if(!l)return a;if(l===f.root)return l+a;return l+i+a}function S(){var i="",f=!1,l;for(var a=arguments.length-1;a>=-1&&!f;a--){var E;if(a>=0)E=arguments[a];else{if(l===void 0)l=process.cwd();E=l}if(U(E),E.length===0)continue;i=E+"/"+i,f=E.charCodeAt(0)===47}if(i=k(i,!f),f)if(i.length>0)return"/"+i;else return"/";else if(i.length>0)return i;else return"."}function m(i){if(U(i),i.length===0)return".";var f=i.charCodeAt(0)===47,l=i.charCodeAt(i.length-1)===47;if(i=k(i,!f),i.length===0&&!f)i=".";if(i.length>0&&l)i+="/";if(f)return"/"+i;return i}function e(i){return U(i),i.length>0&&i.charCodeAt(0)===47}function V(){if(arguments.length===0)return".";var i;for(var f=0;f<arguments.length;++f){var l=arguments[f];if(U(l),l.length>0)if(i===void 0)i=l;else i+="/"+l}if(i===void 0)return".";return m(i)}function h(i,f){if(U(i),U(f),i===f)return"";if(i=S(i),f=S(f),i===f)return"";var l=1;for(;l<i.length;++l)if(i.charCodeAt(l)!==47)break;var a=i.length,E=a-l,A=1;for(;A<f.length;++A)if(f.charCodeAt(A)!==47)break;var d=f.length,_=d-A,I=E<_?E:_,O=-1,N=0;for(;N<=I;++N){if(N===I){if(_>I){if(f.charCodeAt(A+N)===47)return f.slice(A+N+1);else if(N===0)return f.slice(A+N)}else if(E>I){if(i.charCodeAt(l+N)===47)O=N;else if(N===0)O=0}break}var w=i.charCodeAt(l+N),L=f.charCodeAt(A+N);if(w!==L)break;else if(w===47)O=N}var $="";for(N=l+O+1;N<=a;++N)if(N===a||i.charCodeAt(N)===47)if($.length===0)$+="..";else $+="/..";if($.length>0)return $+f.slice(A+O);else{if(A+=O,f.charCodeAt(A)===47)++A;return f.slice(A)}}function ii(i){return i}function F(i){if(U(i),i.length===0)return".";var f=i.charCodeAt(0),l=f===47,a=-1,E=!0;for(var A=i.length-1;A>=1;--A)if(f=i.charCodeAt(A),f===47){if(!E){a=A;break}}else E=!1;if(a===-1)return l?"/":".";if(l&&a===1)return"//";return i.slice(0,a)}function fi(i,f){if(f!==void 0&&typeof f!=="string")throw new TypeError('"ext" argument must be a string');U(i);var l=0,a=-1,E=!0,A;if(f!==void 0&&f.length>0&&f.length<=i.length){if(f.length===i.length&&f===i)return"";var d=f.length-1,_=-1;for(A=i.length-1;A>=0;--A){var I=i.charCodeAt(A);if(I===47){if(!E){l=A+1;break}}else{if(_===-1)E=!1,_=A+1;if(d>=0)if(I===f.charCodeAt(d)){if(--d===-1)a=A}else d=-1,a=_}}if(l===a)a=_;else if(a===-1)a=i.length;return i.slice(l,a)}else{for(A=i.length-1;A>=0;--A)if(i.charCodeAt(A)===47){if(!E){l=A+1;break}}else if(a===-1)E=!1,a=A+1;if(a===-1)return"";return i.slice(l,a)}}function li(i){U(i);var f=-1,l=0,a=-1,E=!0,A=0;for(var d=i.length-1;d>=0;--d){var _=i.charCodeAt(d);if(_===47){if(!E){l=d+1;break}continue}if(a===-1)E=!1,a=d+1;if(_===46){if(f===-1)f=d;else if(A!==1)A=1}else if(f!==-1)A=-1}if(f===-1||a===-1||A===0||A===1&&f===a-1&&f===l+1)return"";return i.slice(f,a)}function ai(i){if(i===null||typeof i!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof i);return p("/",i)}function Ai(i){U(i);var f={root:"",dir:"",base:"",ext:"",name:""};if(i.length===0)return f;var l=i.charCodeAt(0),a=l===47,E;if(a)f.root="/",E=1;else E=0;var A=-1,d=0,_=-1,I=!0,O=i.length-1,N=0;for(;O>=E;--O){if(l=i.charCodeAt(O),l===47){if(!I){d=O+1;break}continue}if(_===-1)I=!1,_=O+1;if(l===46){if(A===-1)A=O;else if(N!==1)N=1}else if(A!==-1)N=-1}if(A===-1||_===-1||N===0||N===1&&A===_-1&&A===d+1){if(_!==-1)if(d===0&&a)f.base=f.name=i.slice(1,_);else f.base=f.name=i.slice(d,_)}else{if(d===0&&a)f.name=i.slice(1,A),f.base=i.slice(1,_);else f.name=i.slice(d,A),f.base=i.slice(d,_);f.ext=i.slice(A,_)}if(d>0)f.dir=i.slice(0,d-1);else if(a)f.dir="/";return f}var X="/",Ei=":",xi=((i)=>(i.posix=i,i))({resolve:S,normalize:m,isAbsolute:e,join:V,relative:h,_makeLong:ii,dirname:F,basename:fi,extname:li,format:ai,parse:Ai,sep:X,delimiter:Ei,win32:null,posix:null});class J{outputPath;constructor(i="./.vector/routes.generated.ts"){this.outputPath=i}async generate(i){let f=F(this.outputPath);await z.promises.mkdir(f,{recursive:!0});let l=[],a=new Map;for(let _ of i){if(!a.has(_.path))a.set(_.path,[]);a.get(_.path).push(_)}let E=0,A=[];for(let[_,I]of a){let O=h(F(this.outputPath),_).replace(/\\/g,"/").replace(/\.(ts|js)$/,""),N=`route_${E++}`,w=I.filter((L)=>L.name!=="default").map((L)=>L.name);if(I.some((L)=>L.name==="default"))if(w.length>0)l.push(`import ${N}, { ${w.join(", ")} } from '${O}';`);else l.push(`import ${N} from '${O}';`);else if(w.length>0)l.push(`import { ${w.join(", ")} } from '${O}';`);for(let L of I){let $=L.name==="default"?N:L.name;A.push(` ${$},`)}}let d=`// This file is auto-generated. Do not edit manually.
|
|
1
|
+
var{defineProperty:h,getOwnPropertyNames:n,getOwnPropertyDescriptor:s}=Object,p=Object.prototype.hasOwnProperty;var T=new WeakMap,r=(i)=>{var f=T.get(i),l;if(f)return f;if(f=h({},"__esModule",{value:!0}),i&&typeof i==="object"||typeof i==="function")n(i).map((E)=>!p.call(f,E)&&h(f,E,{get:()=>i[E],enumerable:!(l=s(i,E))||l.enumerable}));return T.set(i,f),f};var o=(i,f)=>{for(var l in f)h(i,l,{get:f[l],enumerable:!0,configurable:!0,set:(E)=>f[l]=()=>E})};var Li={};o(Li,{route:()=>y,createResponse:()=>P,APIError:()=>S});module.exports=r(Li);var G=(i="text/plain; charset=utf-8",f)=>(l,E={})=>{if(l===void 0||l instanceof Response)return l;let _=new Response(f?.(l)??l,E.url?void 0:E);return _.headers.set("content-type",i),_},$i=G("application/json; charset=utf-8",JSON.stringify);var wi=G("text/plain; charset=utf-8",String),Ci=G("text/html"),Si=G("image/jpeg"),bi=G("image/png"),Ri=G("image/webp"),k=async(i)=>{i.content=i.body?await i.clone().json().catch(()=>i.clone().formData()).catch(()=>i.text()):void 0},g=(i)=>{i.cookies=(i.headers.get("Cookie")||"").split(/;\s*/).map((f)=>f.split(/=(.+)/)).reduce((f,[l,E])=>E?(f[l]=E,f):f,{})},H=(i={})=>{let{origin:f="*",credentials:l=!1,allowMethods:E="*",allowHeaders:_,exposeHeaders:A,maxAge:N}=i,O=(D)=>{let I=D?.headers.get("origin");return f===!0?I:f instanceof RegExp?f.test(I)?I:void 0:Array.isArray(f)?f.includes(I)?I:void 0:f instanceof Function?f(I):f=="*"&&l?I:f},U=(D,I)=>{for(let[$,w]of Object.entries(I))w&&D.headers.append($,w);return D};return{corsify:(D,I)=>D?.headers?.get("access-control-allow-origin")||D.status==101?D:U(D.clone(),{"access-control-allow-origin":O(I),"access-control-allow-credentials":l}),preflight:(D)=>{if(D.method=="OPTIONS"){let I=new Response(null,{status:204});return U(I,{"access-control-allow-origin":O(D),"access-control-allow-methods":E?.join?.(",")??E,"access-control-expose-headers":A?.join?.(",")??A,"access-control-allow-headers":_?.join?.(",")??_??D.headers.get("access-control-request-headers"),"access-control-max-age":N,"access-control-allow-credentials":l})}}}};var C={OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,IM_A_TEAPOT:418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511},z={PORT:3000,HOSTNAME:"localhost",ROUTES_DIR:"./routes",CACHE_TTL:0,CORS_MAX_AGE:86400},F={JSON:"application/json",TEXT:"text/plain",HTML:"text/html",FORM_URLENCODED:"application/x-www-form-urlencoded",MULTIPART:"multipart/form-data"};class J{protectedHandler=null;setProtectedHandler(i){this.protectedHandler=i}async authenticate(i){if(!this.protectedHandler)throw new Error("Protected handler not configured. Use vector.protected() to set authentication handler.");try{let f=await this.protectedHandler(i);return i.authUser=f,f}catch(f){throw new Error(`Authentication failed: ${f instanceof Error?f.message:String(f)}`)}}isAuthenticated(i){return!!i.authUser}getUser(i){return i.authUser||null}}class W{cacheHandler=null;memoryCache=new Map;cleanupInterval=null;setCacheHandler(i){this.cacheHandler=i}async get(i,f,l=z.CACHE_TTL){if(l<=0)return f();if(this.cacheHandler)return this.cacheHandler(i,f,l);return this.getFromMemoryCache(i,f,l)}async getFromMemoryCache(i,f,l){let E=Date.now(),_=this.memoryCache.get(i);if(this.isCacheValid(_,E))return _.value;let A=await f();return this.setInMemoryCache(i,A,l),A}isCacheValid(i,f){return i!==void 0&&i.expires>f}setInMemoryCache(i,f,l){let E=Date.now()+l*1000;this.memoryCache.set(i,{value:f,expires:E}),this.scheduleCleanup()}scheduleCleanup(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanupExpired()},60000)}cleanupExpired(){let i=Date.now();for(let[f,l]of this.memoryCache.entries())if(l.expires<=i)this.memoryCache.delete(f);if(this.memoryCache.size===0&&this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}clear(){if(this.memoryCache.clear(),this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}async set(i,f,l=z.CACHE_TTL){if(l<=0)return;if(this.cacheHandler){await this.cacheHandler(i,async()=>f,l);return}this.setInMemoryCache(i,f,l)}delete(i){return this.memoryCache.delete(i)}has(i){let f=this.memoryCache.get(i);if(!f)return!1;if(f.expires<=Date.now())return this.memoryCache.delete(i),!1;return!0}generateKey(i,f){let l=new URL(i.url);return[i.method,l.pathname,l.search,f?.authUser?.id||"anonymous"].join(":")}}var V=(()=>({}));function b(i){if(typeof i!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function c(i,f){var l="",E=0,_=-1,A=0,N;for(var O=0;O<=i.length;++O){if(O<i.length)N=i.charCodeAt(O);else if(N===47)break;else N=47;if(N===47){if(_===O-1||A===1);else if(_!==O-1&&A===2){if(l.length<2||E!==2||l.charCodeAt(l.length-1)!==46||l.charCodeAt(l.length-2)!==46){if(l.length>2){var U=l.lastIndexOf("/");if(U!==l.length-1){if(U===-1)l="",E=0;else l=l.slice(0,U),E=l.length-1-l.lastIndexOf("/");_=O,A=0;continue}}else if(l.length===2||l.length===1){l="",E=0,_=O,A=0;continue}}if(f){if(l.length>0)l+="/..";else l="..";E=2}}else{if(l.length>0)l+="/"+i.slice(_+1,O);else l=i.slice(_+1,O);E=O-_-1}_=O,A=0}else if(N===46&&A!==-1)++A;else A=-1}return l}function t(i,f){var l=f.dir||f.root,E=f.base||(f.name||"")+(f.ext||"");if(!l)return E;if(l===f.root)return l+E;return l+i+E}function j(){var i="",f=!1,l;for(var E=arguments.length-1;E>=-1&&!f;E--){var _;if(E>=0)_=arguments[E];else{if(l===void 0)l=process.cwd();_=l}if(b(_),_.length===0)continue;i=_+"/"+i,f=_.charCodeAt(0)===47}if(i=c(i,!f),f)if(i.length>0)return"/"+i;else return"/";else if(i.length>0)return i;else return"."}function m(i){if(b(i),i.length===0)return".";var f=i.charCodeAt(0)===47,l=i.charCodeAt(i.length-1)===47;if(i=c(i,!f),i.length===0&&!f)i=".";if(i.length>0&&l)i+="/";if(f)return"/"+i;return i}function e(i){return b(i),i.length>0&&i.charCodeAt(0)===47}function M(){if(arguments.length===0)return".";var i;for(var f=0;f<arguments.length;++f){var l=arguments[f];if(b(l),l.length>0)if(i===void 0)i=l;else i+="/"+l}if(i===void 0)return".";return m(i)}function a(i,f){if(b(i),b(f),i===f)return"";if(i=j(i),f=j(f),i===f)return"";var l=1;for(;l<i.length;++l)if(i.charCodeAt(l)!==47)break;var E=i.length,_=E-l,A=1;for(;A<f.length;++A)if(f.charCodeAt(A)!==47)break;var N=f.length,O=N-A,U=_<O?_:O,D=-1,I=0;for(;I<=U;++I){if(I===U){if(O>U){if(f.charCodeAt(A+I)===47)return f.slice(A+I+1);else if(I===0)return f.slice(A+I)}else if(_>U){if(i.charCodeAt(l+I)===47)D=I;else if(I===0)D=0}break}var $=i.charCodeAt(l+I),w=f.charCodeAt(A+I);if($!==w)break;else if($===47)D=I}var R="";for(I=l+D+1;I<=E;++I)if(I===E||i.charCodeAt(I)===47)if(R.length===0)R+="..";else R+="/..";if(R.length>0)return R+f.slice(A+D);else{if(A+=D,f.charCodeAt(A)===47)++A;return f.slice(A)}}function ii(i){return i}function Y(i){if(b(i),i.length===0)return".";var f=i.charCodeAt(0),l=f===47,E=-1,_=!0;for(var A=i.length-1;A>=1;--A)if(f=i.charCodeAt(A),f===47){if(!_){E=A;break}}else _=!1;if(E===-1)return l?"/":".";if(l&&E===1)return"//";return i.slice(0,E)}function fi(i,f){if(f!==void 0&&typeof f!=="string")throw new TypeError('"ext" argument must be a string');b(i);var l=0,E=-1,_=!0,A;if(f!==void 0&&f.length>0&&f.length<=i.length){if(f.length===i.length&&f===i)return"";var N=f.length-1,O=-1;for(A=i.length-1;A>=0;--A){var U=i.charCodeAt(A);if(U===47){if(!_){l=A+1;break}}else{if(O===-1)_=!1,O=A+1;if(N>=0)if(U===f.charCodeAt(N)){if(--N===-1)E=A}else N=-1,E=O}}if(l===E)E=O;else if(E===-1)E=i.length;return i.slice(l,E)}else{for(A=i.length-1;A>=0;--A)if(i.charCodeAt(A)===47){if(!_){l=A+1;break}}else if(E===-1)_=!1,E=A+1;if(E===-1)return"";return i.slice(l,E)}}function li(i){b(i);var f=-1,l=0,E=-1,_=!0,A=0;for(var N=i.length-1;N>=0;--N){var O=i.charCodeAt(N);if(O===47){if(!_){l=N+1;break}continue}if(E===-1)_=!1,E=N+1;if(O===46){if(f===-1)f=N;else if(A!==1)A=1}else if(f!==-1)A=-1}if(f===-1||E===-1||A===0||A===1&&f===E-1&&f===l+1)return"";return i.slice(f,E)}function Ei(i){if(i===null||typeof i!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof i);return t("/",i)}function Ai(i){b(i);var f={root:"",dir:"",base:"",ext:"",name:""};if(i.length===0)return f;var l=i.charCodeAt(0),E=l===47,_;if(E)f.root="/",_=1;else _=0;var A=-1,N=0,O=-1,U=!0,D=i.length-1,I=0;for(;D>=_;--D){if(l=i.charCodeAt(D),l===47){if(!U){N=D+1;break}continue}if(O===-1)U=!1,O=D+1;if(l===46){if(A===-1)A=D;else if(I!==1)I=1}else if(A!==-1)I=-1}if(A===-1||O===-1||I===0||I===1&&A===O-1&&A===N+1){if(O!==-1)if(N===0&&E)f.base=f.name=i.slice(1,O);else f.base=f.name=i.slice(N,O)}else{if(N===0&&E)f.name=i.slice(1,A),f.base=i.slice(1,O);else f.name=i.slice(N,A),f.base=i.slice(N,O);f.ext=i.slice(A,O)}if(N>0)f.dir=i.slice(0,N-1);else if(E)f.dir="/";return f}var Q="/",_i=":",xi=((i)=>(i.posix=i,i))({resolve:j,normalize:m,isAbsolute:e,join:M,relative:a,_makeLong:ii,dirname:Y,basename:fi,extname:li,format:Ei,parse:Ai,sep:Q,delimiter:_i,win32:null,posix:null});class K{outputPath;constructor(i="./.vector/routes.generated.ts"){this.outputPath=i}async generate(i){let f=Y(this.outputPath);await V.promises.mkdir(f,{recursive:!0});let l=[],E=new Map;for(let O of i){if(!E.has(O.path))E.set(O.path,[]);E.get(O.path).push(O)}let _=0,A=[];for(let[O,U]of E){let D=a(Y(this.outputPath),O).replace(/\\/g,"/").replace(/\.(ts|js)$/,""),I=`route_${_++}`,$=U.filter((w)=>w.name!=="default").map((w)=>w.name);if(U.some((w)=>w.name==="default"))if($.length>0)l.push(`import ${I}, { ${$.join(", ")} } from '${D}';`);else l.push(`import ${I} from '${D}';`);else if($.length>0)l.push(`import { ${$.join(", ")} } from '${D}';`);for(let w of U){let R=w.name==="default"?I:w.name;A.push(` ${R},`)}}let N=`// This file is auto-generated. Do not edit manually.
|
|
2
2
|
// Generated at: ${new Date().toISOString()}
|
|
3
3
|
|
|
4
4
|
${l.join(`
|
|
@@ -10,12 +10,12 @@ ${A.join(`
|
|
|
10
10
|
];
|
|
11
11
|
|
|
12
12
|
export default routes;
|
|
13
|
-
`;await
|
|
14
|
-
...${
|
|
13
|
+
`;await V.promises.writeFile(this.outputPath,N,"utf-8")}async generateDynamic(i){let f=[];for(let l of i){let E=JSON.stringify({method:l.method,path:l.options.path,options:l.options});f.push(` await import('${l.path}').then(m => ({
|
|
14
|
+
...${E},
|
|
15
15
|
handler: m.${l.name==="default"?"default":l.name}
|
|
16
16
|
}))`)}return`export const loadRoutes = async () => {
|
|
17
17
|
return Promise.all([
|
|
18
18
|
${f.join(`,
|
|
19
19
|
`)}
|
|
20
20
|
]);
|
|
21
|
-
};`}}var x=(()=>({}));class W{routesDir;constructor(i="./routes"){this.routesDir=S(process.cwd(),i)}async scan(){let i=[];if(!x.existsSync(this.routesDir))return[];try{await this.scanDirectory(this.routesDir,i)}catch(f){if(f.code==="ENOENT")return console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`),[];throw f}return i}async scanDirectory(i,f,l=""){let a=await x.promises.readdir(i);for(let E of a){let A=V(i,E);if((await x.promises.stat(A)).isDirectory()){let _=l?`${l}/${E}`:E;await this.scanDirectory(A,f,_)}else if(E.endsWith(".ts")||E.endsWith(".js")){let _=h(this.routesDir,A).replace(/\.(ts|js)$/,"").split(X).join("/");try{let O=await import(process.platform==="win32"?`file:///${A.replace(/\\/g,"/")}`:A);if(O.default&&typeof O.default==="function")f.push({name:"default",path:A,method:"GET",options:{method:"GET",path:`/${_}`,expose:!0}});for(let[N,w]of Object.entries(O)){if(N==="default")continue;if(w&&typeof w==="object"&&"entry"in w&&"options"in w&&"handler"in w){let L=w;f.push({name:N,path:A,method:L.options.method,options:L.options})}else if(Array.isArray(w)&&w.length>=4){let[L,,,$]=w;f.push({name:N,path:A,method:L,options:{method:L,path:$,expose:!0}})}}}catch(I){console.error(`Failed to load route from ${A}:`,I)}}}}enableWatch(i){if(typeof Bun!=="undefined"&&Bun.env.NODE_ENV==="development")console.log(`Watching for route changes in ${this.routesDir}`),setInterval(async()=>{await i()},1000)}}class M{beforeHandlers=[];finallyHandlers=[];addBefore(...i){this.beforeHandlers.push(...i)}addFinally(...i){this.finallyHandlers.push(...i)}async executeBefore(i){let f=i;for(let l of this.beforeHandlers){let a=await l(f);if(a instanceof Response)return a;f=a}return f}async executeFinally(i,f){let l=i;for(let a of this.finallyHandlers)l=await a(l,f);return l}clone(){let i=new M;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function u(i){return process.platform==="win32"?`file:///${i.replace(/\\/g,"/")}`:i}class v{middlewareManager;authManager;cacheManager;routes=[];constructor(i,f,l){this.middlewareManager=i,this.authManager=f,this.cacheManager=l}getRouteSpecificity(i){let A=0,d=i.split("/").filter(Boolean);for(let _ of d)if(this.isStaticSegment(_))A+=1000;else if(this.isParamSegment(_))A+=10;else if(this.isWildcardSegment(_))A+=1;if(A+=i.length,this.isExactPath(i))A+=1e4;return A}isStaticSegment(i){return!i.startsWith(":")&&!i.includes("*")}isParamSegment(i){return i.startsWith(":")}isWildcardSegment(i){return i.includes("*")}isExactPath(i){return!i.includes(":")&&!i.includes("*")}sortRoutes(){this.routes.sort((i,f)=>{let l=this.extractPath(i),a=this.extractPath(f),E=this.getRouteSpecificity(l);return this.getRouteSpecificity(a)-E})}extractPath(i){return i[3]||""}route(i,f){let l=this.wrapHandler(i,f),a=[i.method.toUpperCase(),this.createRouteRegex(i.path),[l],i.path];return this.routes.push(a),this.sortRoutes(),a}createRouteRegex(i){return RegExp(`^${i.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`)}prepareRequest(i,f){if(!i.context)i.context={};if(f?.params!==void 0)i.params=f.params;if(f?.route!==void 0)i.route=f.route;if(f?.metadata!==void 0)i.metadata=f.metadata;if(!i.query&&i.url){let l=new URL(i.url),a={};for(let[E,A]of l.searchParams)if(E in a)if(Array.isArray(a[E]))a[E].push(A);else a[E]=[a[E],A];else a[E]=A;i.query=a}if(!i.cookies)g(i)}wrapHandler(i,f){return async(l)=>{let a=l;this.prepareRequest(a,{metadata:i.metadata}),l=a;try{if(i.expose===!1)return C.forbidden("Forbidden");let E=await this.middlewareManager.executeBefore(l);if(E instanceof Response)return E;if(l=E,i.auth)try{await this.authManager.authenticate(l)}catch(O){return C.unauthorized(O instanceof Error?O.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let O=l.headers.get("content-type");if(O?.includes("application/json"))l.content=await l.json();else if(O?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(O?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let A,d=i.cache,_=async()=>{let O=await f(l);if(O instanceof Response)return{_isResponse:!0,body:await O.text(),status:O.status,headers:Object.fromEntries(O.headers.entries())};return O};if(d&&typeof d==="number"&&d>0){let O=this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(O,_,d)}else if(d&&typeof d==="object"&&d.ttl){let O=d.key||this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(O,_,d.ttl)}else A=await f(l);if(A&&typeof A==="object"&&A._isResponse===!0)A=new Response(A.body,{status:A.status,headers:A.headers});let I;if(i.rawResponse||A instanceof Response)I=A instanceof Response?A:new Response(A);else I=P(200,A,i.responseContentType);return I=await this.middlewareManager.executeFinally(I,l),I}catch(E){if(E instanceof Response)return E;return console.error("Route handler error:",E),C.internalServerError(E instanceof Error?E.message:String(E),i.responseContentType)}}}addRoute(i){this.routes.push(i),this.sortRoutes()}getRoutes(){return this.routes}async handle(i){let l=new URL(i.url).pathname;for(let[a,E,A,d]of this.routes)if(i.method==="OPTIONS"||i.method===a){let _=l.match(E);if(_){let I=i;this.prepareRequest(I,{params:_.groups||{},route:d||l});for(let O of A){let N=await O(I);if(N)return N}}}return C.notFound("Route not found")}clearRoutes(){this.routes=[]}}class K{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:a}=G(this.normalizeCorsOptions(f.cors));this.corsHandler={preflight:l,corsify:a}}}normalizeCorsOptions(i){return{origin:i.origin||"*",credentials:i.credentials!==!1,allowHeaders:Array.isArray(i.allowHeaders)?i.allowHeaders.join(", "):i.allowHeaders||"Content-Type, Authorization",allowMethods:Array.isArray(i.allowMethods)?i.allowMethods.join(", "):i.allowMethods||"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:Array.isArray(i.exposeHeaders)?i.exposeHeaders.join(", "):i.exposeHeaders||"Authorization",maxAge:i.maxAge||86400}}async start(){let i=this.config.port||3000,f=this.config.hostname||"localhost",l=async(a)=>{try{if(this.corsHandler&&a.method==="OPTIONS")return this.corsHandler.preflight(a);let E=await this.router.handle(a);if(this.corsHandler)E=this.corsHandler.corsify(E,a);return E}catch(E){return console.error("Server error:",E),new Response("Internal Server Error",{status:500})}};try{if(this.server=Bun.serve({port:i,hostname:f,reusePort:this.config.reusePort!==!1,fetch:l,idleTimeout:this.config.idleTimeout||60,error:(a)=>{return console.error("[ERROR] Server error:",a),new Response("Internal Server Error",{status:500})}}),!this.server||!this.server.port)throw new Error(`Failed to start server on ${f}:${i} - server object is invalid`);return console.log(`→ Vector server running at http://${f}:${i}`),this.server}catch(a){if(a.code==="EADDRINUSE"||a.message?.includes("address already in use"))a.message=`Port ${i} is already in use`,a.port=i;else if(a.code==="EACCES"||a.message?.includes("permission denied"))a.message=`Permission denied to bind to port ${i}`,a.port=i;else if(a.message?.includes("EADDRNOTAVAIL"))a.message=`Cannot bind to hostname ${f}`,a.hostname=f;throw a}}stop(){if(this.server)this.server.stop(),this.server=null,console.log("Server stopped")}getServer(){return this.server}getPort(){return this.server?.port||this.config.port||3000}getHostname(){return this.server?.hostname||this.config.hostname||"localhost"}getUrl(){let i=this.getPort();return`http://${this.getHostname()}:${i}`}}class H{static instance;router;server=null;middlewareManager;authManager;cacheManager;config={};routeScanner=null;routeGenerator=null;_protectedHandler=null;_cacheHandler=null;constructor(){this.middlewareManager=new M,this.authManager=new Y,this.cacheManager=new Q,this.router=new v(this.middlewareManager,this.authManager,this.cacheManager)}static getInstance(){if(!H.instance)H.instance=new H;return H.instance}setProtectedHandler(i){this._protectedHandler=i,this.authManager.setProtectedHandler(i)}getProtectedHandler(){return this._protectedHandler}setCacheHandler(i){this._cacheHandler=i,this.cacheManager.setCacheHandler(i)}getCacheHandler(){return this._cacheHandler}addRoute(i,f){return this.router.route(i,f)}async startServer(i){if(this.config={...this.config,...i},this.middlewareManager.clear(),i?.before)this.middlewareManager.addBefore(...i.before);if(i?.finally)this.middlewareManager.addFinally(...i.finally);if(this.config.autoDiscover!==!1)await this.discoverRoutes();return this.server=new K(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes";if(this.routeScanner=new W(i),!this.routeGenerator)this.routeGenerator=new J;try{let f=await this.routeScanner.scan();if(f.length>0){if(this.config.development)await this.routeGenerator.generate(f);for(let l of f)try{let E=await import(u(l.path)),A=l.name==="default"?E.default:E[l.name];if(A){if(this.isRouteDefinition(A)){let d=A;this.router.route(d.options,d.handler),this.logRouteLoaded(d.options)}else if(this.isRouteEntry(A))this.router.addRoute(A),this.logRouteLoaded(A);else if(typeof A==="function")this.router.route(l.options,A),this.logRouteLoaded(l.options)}}catch(a){console.error(`Failed to load route ${l.name} from ${l.path}:`,a)}this.router.sortRoutes()}}catch(f){if(f.code!=="ENOENT"&&f.code!=="ENOTDIR")console.error("Failed to discover routes:",f)}}async loadRoute(i){if(typeof i==="function"){let f=i();if(Array.isArray(f))this.router.addRoute(f)}else if(i&&typeof i==="object"){for(let[,f]of Object.entries(i))if(typeof f==="function"){let l=f();if(Array.isArray(l))this.router.addRoute(l)}}}isRouteEntry(i){return Array.isArray(i)&&i.length>=3}isRouteDefinition(i){return i&&typeof i==="object"&&"entry"in i&&"options"in i&&"handler"in i}logRouteLoaded(i){}stop(){if(this.server)this.server.stop(),this.server=null;this.router.clearRoutes()}getServer(){return this.server}getRouter(){return this.router}getCacheManager(){return this.cacheManager}getAuthManager(){return this.authManager}static resetInstance(){H.instance=null}}var n=H.getInstance;var{preflight:qi,corsify:ri}=G({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400});function y(i,f){let l=Ni(i,f);return{entry:[i.method.toUpperCase(),RegExp(`^${i.path.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),[l],i.path],options:i,handler:f}}function _i(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}var di={success:(i,f)=>P(R.OK,i,f),created:(i,f)=>P(R.CREATED,i,f)};function D(i,f,l){let a={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return P(i,a,l)}var C={badRequest:(i="Bad Request",f)=>D(R.BAD_REQUEST,i,f),unauthorized:(i="Unauthorized",f)=>D(R.UNAUTHORIZED,i,f),paymentRequired:(i="Payment Required",f)=>D(402,i,f),forbidden:(i="Forbidden",f)=>D(R.FORBIDDEN,i,f),notFound:(i="Not Found",f)=>D(R.NOT_FOUND,i,f),methodNotAllowed:(i="Method Not Allowed",f)=>D(405,i,f),notAcceptable:(i="Not Acceptable",f)=>D(406,i,f),requestTimeout:(i="Request Timeout",f)=>D(408,i,f),conflict:(i="Conflict",f)=>D(R.CONFLICT,i,f),gone:(i="Gone",f)=>D(410,i,f),lengthRequired:(i="Length Required",f)=>D(411,i,f),preconditionFailed:(i="Precondition Failed",f)=>D(412,i,f),payloadTooLarge:(i="Payload Too Large",f)=>D(413,i,f),uriTooLong:(i="URI Too Long",f)=>D(414,i,f),unsupportedMediaType:(i="Unsupported Media Type",f)=>D(415,i,f),rangeNotSatisfiable:(i="Range Not Satisfiable",f)=>D(416,i,f),expectationFailed:(i="Expectation Failed",f)=>D(417,i,f),imATeapot:(i="I'm a teapot",f)=>D(418,i,f),misdirectedRequest:(i="Misdirected Request",f)=>D(421,i,f),unprocessableEntity:(i="Unprocessable Entity",f)=>D(R.UNPROCESSABLE_ENTITY,i,f),locked:(i="Locked",f)=>D(423,i,f),failedDependency:(i="Failed Dependency",f)=>D(424,i,f),tooEarly:(i="Too Early",f)=>D(425,i,f),upgradeRequired:(i="Upgrade Required",f)=>D(426,i,f),preconditionRequired:(i="Precondition Required",f)=>D(428,i,f),tooManyRequests:(i="Too Many Requests",f)=>D(429,i,f),requestHeaderFieldsTooLarge:(i="Request Header Fields Too Large",f)=>D(431,i,f),unavailableForLegalReasons:(i="Unavailable For Legal Reasons",f)=>D(451,i,f),internalServerError:(i="Internal Server Error",f)=>D(R.INTERNAL_SERVER_ERROR,i,f),notImplemented:(i="Not Implemented",f)=>D(501,i,f),badGateway:(i="Bad Gateway",f)=>D(502,i,f),serviceUnavailable:(i="Service Unavailable",f)=>D(503,i,f),gatewayTimeout:(i="Gateway Timeout",f)=>D(504,i,f),httpVersionNotSupported:(i="HTTP Version Not Supported",f)=>D(505,i,f),variantAlsoNegotiates:(i="Variant Also Negotiates",f)=>D(506,i,f),insufficientStorage:(i="Insufficient Storage",f)=>D(507,i,f),loopDetected:(i="Loop Detected",f)=>D(508,i,f),notExtended:(i="Not Extended",f)=>D(510,i,f),networkAuthenticationRequired:(i="Network Authentication Required",f)=>D(511,i,f),invalidArgument:(i="Invalid Argument",f)=>D(R.UNPROCESSABLE_ENTITY,i,f),rateLimitExceeded:(i="Rate Limit Exceeded",f)=>D(429,i,f),maintenance:(i="Service Under Maintenance",f)=>D(503,i,f),custom:(i,f,l)=>D(i,f,l)};function P(i,f,l=j.JSON){let a=l===j.JSON?_i(f):f;return new Response(a,{status:i,headers:{"content-type":l}})}var Oi=async(i,f)=>{let a=n().getProtectedHandler();if(!a)throw C.unauthorized("Authentication not configured",f);try{let E=await a(i);i.authUser=E}catch(E){throw C.unauthorized(E instanceof Error?E.message:"Authentication failed",f)}};function Ni(i,f){let{auth:l=!1,expose:a=!1,rawRequest:E=!1,rawResponse:A=!1,responseContentType:d=j.JSON}=i;return async(_)=>{if(!a)return C.forbidden("Forbidden");try{if(l)await Oi(_,d);if(!E)await c(_);let I=await f(_);return A?I:di.success(I,d)}catch(I){if(I instanceof Response)return I;return C.internalServerError(String(I),d)}}}
|
|
21
|
+
};`}}var x=(()=>({}));class B{routesDir;excludePatterns;static DEFAULT_EXCLUDE_PATTERNS=["*.test.ts","*.test.js","*.test.tsx","*.test.jsx","*.spec.ts","*.spec.js","*.spec.tsx","*.spec.jsx","*.tests.ts","*.tests.js","**/__tests__/**","*.interface.ts","*.type.ts","*.d.ts"];constructor(i="./routes",f){this.routesDir=j(process.cwd(),i),this.excludePatterns=f||B.DEFAULT_EXCLUDE_PATTERNS}async scan(){let i=[];if(!x.existsSync(this.routesDir))return[];try{await this.scanDirectory(this.routesDir,i)}catch(f){if(f.code==="ENOENT")return console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`),[];throw f}return i}isExcluded(i){let f=a(this.routesDir,i);for(let l of this.excludePatterns){let E=l.replace(/\./g,"\\.").replace(/\*/g,"[^/]*").replace(/\*\*/g,".*").replace(/\?/g,"."),_=new RegExp(`^${E}$`),A=f.split(Q).pop()||"";if(_.test(f)||_.test(A))return!0}return!1}async scanDirectory(i,f,l=""){let E=await x.promises.readdir(i);for(let _ of E){let A=M(i,_);if((await x.promises.stat(A)).isDirectory()){let O=l?`${l}/${_}`:_;await this.scanDirectory(A,f,O)}else if(_.endsWith(".ts")||_.endsWith(".js")){if(this.isExcluded(A))continue;let O=a(this.routesDir,A).replace(/\.(ts|js)$/,"").split(Q).join("/");try{let D=await import(process.platform==="win32"?`file:///${A.replace(/\\/g,"/")}`:A);if(D.default&&typeof D.default==="function")f.push({name:"default",path:A,method:"GET",options:{method:"GET",path:`/${O}`,expose:!0}});for(let[I,$]of Object.entries(D)){if(I==="default")continue;if($&&typeof $==="object"&&"entry"in $&&"options"in $&&"handler"in $){let w=$;f.push({name:I,path:A,method:w.options.method,options:w.options})}else if(Array.isArray($)&&$.length>=4){let[w,,,R]=$;f.push({name:I,path:A,method:w,options:{method:w,path:R,expose:!0}})}}}catch(U){console.error(`Failed to load route from ${A}:`,U)}}}}enableWatch(i){if(typeof Bun!=="undefined"&&Bun.env.NODE_ENV==="development")console.log(`Watching for route changes in ${this.routesDir}`),setInterval(async()=>{await i()},1000)}}class X{beforeHandlers=[];finallyHandlers=[];addBefore(...i){this.beforeHandlers.push(...i)}addFinally(...i){this.finallyHandlers.push(...i)}async executeBefore(i){let f=i;for(let l of this.beforeHandlers){let E=await l(f);if(E instanceof Response)return E;f=E}return f}async executeFinally(i,f){let l=i;for(let E of this.finallyHandlers)try{l=await E(l,f)}catch(_){console.error("After middleware error:",_)}return l}clone(){let i=new X;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function u(i){return process.platform==="win32"?`file:///${i.replace(/\\/g,"/")}`:i}class Z{middlewareManager;authManager;cacheManager;routes=[];constructor(i,f,l){this.middlewareManager=i,this.authManager=f,this.cacheManager=l}getRouteSpecificity(i){let A=0,N=i.split("/").filter(Boolean);for(let O of N)if(this.isStaticSegment(O))A+=1000;else if(this.isParamSegment(O))A+=10;else if(this.isWildcardSegment(O))A+=1;if(A+=i.length,this.isExactPath(i))A+=1e4;return A}isStaticSegment(i){return!i.startsWith(":")&&!i.includes("*")}isParamSegment(i){return i.startsWith(":")}isWildcardSegment(i){return i.includes("*")}isExactPath(i){return!i.includes(":")&&!i.includes("*")}sortRoutes(){this.routes.sort((i,f)=>{let l=this.extractPath(i),E=this.extractPath(f),_=this.getRouteSpecificity(l);return this.getRouteSpecificity(E)-_})}extractPath(i){return i[3]||""}route(i,f){let l=this.wrapHandler(i,f),E=[i.method.toUpperCase(),this.createRouteRegex(i.path),[l],i.path];return this.routes.push(E),this.sortRoutes(),E}createRouteRegex(i){return RegExp(`^${i.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`)}prepareRequest(i,f){if(!i.context)i.context={};if(f?.params!==void 0)i.params=f.params;if(f?.route!==void 0)i.route=f.route;if(f?.metadata!==void 0)i.metadata=f.metadata;if(!i.query&&i.url){let l=new URL(i.url),E={};for(let[_,A]of l.searchParams)if(_ in E)if(Array.isArray(E[_]))E[_].push(A);else E[_]=[E[_],A];else E[_]=A;i.query=E}if(!i.cookies)g(i)}wrapHandler(i,f){return async(l)=>{let E=l;this.prepareRequest(E,{metadata:i.metadata}),l=E;try{if(i.expose===!1)return S.forbidden("Forbidden");let _=await this.middlewareManager.executeBefore(l);if(_ instanceof Response)return _;if(l=_,i.auth)try{await this.authManager.authenticate(l)}catch(D){return S.unauthorized(D instanceof Error?D.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let D=l.headers.get("content-type");if(D?.includes("application/json"))l.content=await l.json();else if(D?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(D?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let A,N=i.cache,O=async()=>{let D=await f(l);if(D instanceof Response)return{_isResponse:!0,body:await D.text(),status:D.status,headers:Object.fromEntries(D.headers.entries())};return D};if(N&&typeof N==="number"&&N>0){let D=this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(D,O,N)}else if(N&&typeof N==="object"&&N.ttl){let D=N.key||this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(D,O,N.ttl)}else A=await f(l);if(A&&typeof A==="object"&&A._isResponse===!0)A=new Response(A.body,{status:A.status,headers:A.headers});let U;if(i.rawResponse||A instanceof Response)U=A instanceof Response?A:new Response(A);else U=P(200,A,i.responseContentType);return U=await this.middlewareManager.executeFinally(U,l),U}catch(_){if(_ instanceof Response)return _;return console.error("Route handler error:",_),S.internalServerError(_ instanceof Error?_.message:String(_),i.responseContentType)}}}addRoute(i){this.routes.push(i),this.sortRoutes()}getRoutes(){return this.routes}async handle(i){let l=new URL(i.url).pathname;for(let[E,_,A,N]of this.routes)if(i.method==="OPTIONS"||i.method===E){let O=l.match(_);if(O){let U=i;this.prepareRequest(U,{params:O.groups||{},route:N||l});for(let D of A){let I=await D(U);if(I)return I}}}return S.notFound("Route not found")}clearRoutes(){this.routes=[]}}class v{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:E}=H(this.normalizeCorsOptions(f.cors));this.corsHandler={preflight:l,corsify:E}}}normalizeCorsOptions(i){return{origin:i.origin||"*",credentials:i.credentials!==!1,allowHeaders:Array.isArray(i.allowHeaders)?i.allowHeaders.join(", "):i.allowHeaders||"Content-Type, Authorization",allowMethods:Array.isArray(i.allowMethods)?i.allowMethods.join(", "):i.allowMethods||"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:Array.isArray(i.exposeHeaders)?i.exposeHeaders.join(", "):i.exposeHeaders||"Authorization",maxAge:i.maxAge||86400}}async start(){let i=this.config.port||3000,f=this.config.hostname||"localhost",l=async(E)=>{try{if(this.corsHandler&&E.method==="OPTIONS")return this.corsHandler.preflight(E);let _=await this.router.handle(E);if(this.corsHandler)_=this.corsHandler.corsify(_,E);return _}catch(_){return console.error("Server error:",_),new Response("Internal Server Error",{status:500})}};try{if(this.server=Bun.serve({port:i,hostname:f,reusePort:this.config.reusePort!==!1,fetch:l,idleTimeout:this.config.idleTimeout||60,error:(E)=>{return console.error("[ERROR] Server error:",E),new Response("Internal Server Error",{status:500})}}),!this.server||!this.server.port)throw new Error(`Failed to start server on ${f}:${i} - server object is invalid`);return this.server}catch(E){if(E.code==="EADDRINUSE"||E.message?.includes("address already in use"))E.message=`Port ${i} is already in use`,E.port=i;else if(E.code==="EACCES"||E.message?.includes("permission denied"))E.message=`Permission denied to bind to port ${i}`,E.port=i;else if(E.message?.includes("EADDRNOTAVAIL"))E.message=`Cannot bind to hostname ${f}`,E.hostname=f;throw E}}stop(){if(this.server)this.server.stop(),this.server=null,console.log("Server stopped")}getServer(){return this.server}getPort(){return this.server?.port||this.config.port||3000}getHostname(){return this.server?.hostname||this.config.hostname||"localhost"}getUrl(){let i=this.getPort();return`http://${this.getHostname()}:${i}`}}class d{static instance;router;server=null;middlewareManager;authManager;cacheManager;config={};routeScanner=null;routeGenerator=null;_protectedHandler=null;_cacheHandler=null;constructor(){this.middlewareManager=new X,this.authManager=new J,this.cacheManager=new W,this.router=new Z(this.middlewareManager,this.authManager,this.cacheManager)}static getInstance(){if(!d.instance)d.instance=new d;return d.instance}setProtectedHandler(i){this._protectedHandler=i,this.authManager.setProtectedHandler(i)}getProtectedHandler(){return this._protectedHandler}setCacheHandler(i){this._cacheHandler=i,this.cacheManager.setCacheHandler(i)}getCacheHandler(){return this._cacheHandler}addRoute(i,f){return this.router.route(i,f)}async startServer(i){if(this.config={...this.config,...i},this.middlewareManager.clear(),this.config.autoDiscover!==!1)this.router.clearRoutes();if(i?.before)this.middlewareManager.addBefore(...i.before);if(i?.finally)this.middlewareManager.addFinally(...i.finally);if(this.config.autoDiscover!==!1)await this.discoverRoutes();return this.server=new v(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes",f=this.config.routeExcludePatterns;if(this.routeScanner=new B(i,f),!this.routeGenerator)this.routeGenerator=new K;try{let l=await this.routeScanner.scan();if(l.length>0){if(this.config.development)await this.routeGenerator.generate(l);for(let E of l)try{let A=await import(u(E.path)),N=E.name==="default"?A.default:A[E.name];if(N){if(this.isRouteDefinition(N)){let O=N;this.router.route(O.options,O.handler),this.logRouteLoaded(O.options)}else if(this.isRouteEntry(N))this.router.addRoute(N),this.logRouteLoaded(N);else if(typeof N==="function")this.router.route(E.options,N),this.logRouteLoaded(E.options)}}catch(_){console.error(`Failed to load route ${E.name} from ${E.path}:`,_)}this.router.sortRoutes()}}catch(l){if(l.code!=="ENOENT"&&l.code!=="ENOTDIR")console.error("Failed to discover routes:",l)}}async loadRoute(i){if(typeof i==="function"){let f=i();if(Array.isArray(f))this.router.addRoute(f)}else if(i&&typeof i==="object"){for(let[,f]of Object.entries(i))if(typeof f==="function"){let l=f();if(Array.isArray(l))this.router.addRoute(l)}}}isRouteEntry(i){return Array.isArray(i)&&i.length>=3}isRouteDefinition(i){return i&&typeof i==="object"&&"entry"in i&&"options"in i&&"handler"in i}logRouteLoaded(i){}stop(){if(this.server)this.server.stop(),this.server=null}getServer(){return this.server}getRouter(){return this.router}getCacheManager(){return this.cacheManager}getAuthManager(){return this.authManager}static resetInstance(){d.instance=null}}var q=d.getInstance;var{preflight:si,corsify:pi}=H({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400});function y(i,f){let l=Ii(i,f);return{entry:[i.method.toUpperCase(),RegExp(`^${i.path.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),[l],i.path],options:i,handler:f}}function Oi(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}var Ni={success:(i,f)=>P(C.OK,i,f),created:(i,f)=>P(C.CREATED,i,f)};function L(i,f,l){let E={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return P(i,E,l)}var S={badRequest:(i="Bad Request",f)=>L(C.BAD_REQUEST,i,f),unauthorized:(i="Unauthorized",f)=>L(C.UNAUTHORIZED,i,f),paymentRequired:(i="Payment Required",f)=>L(402,i,f),forbidden:(i="Forbidden",f)=>L(C.FORBIDDEN,i,f),notFound:(i="Not Found",f)=>L(C.NOT_FOUND,i,f),methodNotAllowed:(i="Method Not Allowed",f)=>L(405,i,f),notAcceptable:(i="Not Acceptable",f)=>L(406,i,f),requestTimeout:(i="Request Timeout",f)=>L(408,i,f),conflict:(i="Conflict",f)=>L(C.CONFLICT,i,f),gone:(i="Gone",f)=>L(410,i,f),lengthRequired:(i="Length Required",f)=>L(411,i,f),preconditionFailed:(i="Precondition Failed",f)=>L(412,i,f),payloadTooLarge:(i="Payload Too Large",f)=>L(413,i,f),uriTooLong:(i="URI Too Long",f)=>L(414,i,f),unsupportedMediaType:(i="Unsupported Media Type",f)=>L(415,i,f),rangeNotSatisfiable:(i="Range Not Satisfiable",f)=>L(416,i,f),expectationFailed:(i="Expectation Failed",f)=>L(417,i,f),imATeapot:(i="I'm a teapot",f)=>L(418,i,f),misdirectedRequest:(i="Misdirected Request",f)=>L(421,i,f),unprocessableEntity:(i="Unprocessable Entity",f)=>L(C.UNPROCESSABLE_ENTITY,i,f),locked:(i="Locked",f)=>L(423,i,f),failedDependency:(i="Failed Dependency",f)=>L(424,i,f),tooEarly:(i="Too Early",f)=>L(425,i,f),upgradeRequired:(i="Upgrade Required",f)=>L(426,i,f),preconditionRequired:(i="Precondition Required",f)=>L(428,i,f),tooManyRequests:(i="Too Many Requests",f)=>L(429,i,f),requestHeaderFieldsTooLarge:(i="Request Header Fields Too Large",f)=>L(431,i,f),unavailableForLegalReasons:(i="Unavailable For Legal Reasons",f)=>L(451,i,f),internalServerError:(i="Internal Server Error",f)=>L(C.INTERNAL_SERVER_ERROR,i,f),notImplemented:(i="Not Implemented",f)=>L(501,i,f),badGateway:(i="Bad Gateway",f)=>L(502,i,f),serviceUnavailable:(i="Service Unavailable",f)=>L(503,i,f),gatewayTimeout:(i="Gateway Timeout",f)=>L(504,i,f),httpVersionNotSupported:(i="HTTP Version Not Supported",f)=>L(505,i,f),variantAlsoNegotiates:(i="Variant Also Negotiates",f)=>L(506,i,f),insufficientStorage:(i="Insufficient Storage",f)=>L(507,i,f),loopDetected:(i="Loop Detected",f)=>L(508,i,f),notExtended:(i="Not Extended",f)=>L(510,i,f),networkAuthenticationRequired:(i="Network Authentication Required",f)=>L(511,i,f),invalidArgument:(i="Invalid Argument",f)=>L(C.UNPROCESSABLE_ENTITY,i,f),rateLimitExceeded:(i="Rate Limit Exceeded",f)=>L(429,i,f),maintenance:(i="Service Under Maintenance",f)=>L(503,i,f),custom:(i,f,l)=>L(i,f,l)};function P(i,f,l=F.JSON){let E=l===F.JSON?Oi(f):f;return new Response(E,{status:i,headers:{"content-type":l}})}var Di=async(i,f)=>{let E=q().getProtectedHandler();if(!E)throw S.unauthorized("Authentication not configured",f);try{let _=await E(i);i.authUser=_}catch(_){throw S.unauthorized(_ instanceof Error?_.message:"Authentication failed",f)}};function Ii(i,f){let{auth:l=!1,expose:E=!1,rawRequest:_=!1,rawResponse:A=!1,responseContentType:N=F.JSON}=i;return async(O)=>{if(!E)return S.forbidden("Forbidden");try{if(l)await Di(O,N);if(!_)await k(O);let U=await f(O);return A?U:Ni.success(U,N)}catch(U){if(U instanceof Response)return U;return S.internalServerError(String(U),N)}}}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var H=(i="text/plain; charset=utf-8",f)=>(l,a={})=>{if(l===void 0||l instanceof Response)return l;let E=new Response(f?.(l)??l,a.url?void 0:a);return E.headers.set("content-type",i),E},Ai=H("application/json; charset=utf-8",JSON.stringify);var Ei=H("text/plain; charset=utf-8",String),_i=H("text/html"),di=H("image/jpeg"),Oi=H("image/png"),Ni=H("image/webp"),W=async(i)=>{i.content=i.body?await i.clone().json().catch(()=>i.clone().formData()).catch(()=>i.text()):void 0},v=(i)=>{i.cookies=(i.headers.get("Cookie")||"").split(/;\s*/).map((f)=>f.split(/=(.+)/)).reduce((f,[l,a])=>a?(f[l]=a,f):f,{})},x=(i={})=>{let{origin:f="*",credentials:l=!1,allowMethods:a="*",allowHeaders:E,exposeHeaders:A,maxAge:d}=i,_=(O)=>{let N=O?.headers.get("origin");return f===!0?N:f instanceof RegExp?f.test(N)?N:void 0:Array.isArray(f)?f.includes(N)?N:void 0:f instanceof Function?f(N):f=="*"&&l?N:f},I=(O,N)=>{for(let[w,L]of Object.entries(N))L&&O.headers.append(w,L);return O};return{corsify:(O,N)=>O?.headers?.get("access-control-allow-origin")||O.status==101?O:I(O.clone(),{"access-control-allow-origin":_(N),"access-control-allow-credentials":l}),preflight:(O)=>{if(O.method=="OPTIONS"){let N=new Response(null,{status:204});return I(N,{"access-control-allow-origin":_(O),"access-control-allow-methods":a?.join?.(",")??a,"access-control-expose-headers":A?.join?.(",")??A,"access-control-allow-headers":E?.join?.(",")??E??O.headers.get("access-control-request-headers"),"access-control-max-age":d,"access-control-allow-credentials":l})}}}};var R={OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,IM_A_TEAPOT:418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511},M={PORT:3000,HOSTNAME:"localhost",ROUTES_DIR:"./routes",CACHE_TTL:0,CORS_MAX_AGE:86400},G={JSON:"application/json",TEXT:"text/plain",HTML:"text/html",FORM_URLENCODED:"application/x-www-form-urlencoded",MULTIPART:"multipart/form-data"};class T{protectedHandler=null;setProtectedHandler(i){this.protectedHandler=i}async authenticate(i){if(!this.protectedHandler)throw new Error("Protected handler not configured. Use vector.protected() to set authentication handler.");try{let f=await this.protectedHandler(i);return i.authUser=f,f}catch(f){throw new Error(`Authentication failed: ${f instanceof Error?f.message:String(f)}`)}}isAuthenticated(i){return!!i.authUser}getUser(i){return i.authUser||null}}class B{cacheHandler=null;memoryCache=new Map;cleanupInterval=null;setCacheHandler(i){this.cacheHandler=i}async get(i,f,l=M.CACHE_TTL){if(l<=0)return f();if(this.cacheHandler)return this.cacheHandler(i,f,l);return this.getFromMemoryCache(i,f,l)}async getFromMemoryCache(i,f,l){let a=Date.now(),E=this.memoryCache.get(i);if(this.isCacheValid(E,a))return E.value;let A=await f();return this.setInMemoryCache(i,A,l),A}isCacheValid(i,f){return i!==void 0&&i.expires>f}setInMemoryCache(i,f,l){let a=Date.now()+l*1000;this.memoryCache.set(i,{value:f,expires:a}),this.scheduleCleanup()}scheduleCleanup(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanupExpired()},60000)}cleanupExpired(){let i=Date.now();for(let[f,l]of this.memoryCache.entries())if(l.expires<=i)this.memoryCache.delete(f);if(this.memoryCache.size===0&&this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}clear(){if(this.memoryCache.clear(),this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}async set(i,f,l=M.CACHE_TTL){if(l<=0)return;if(this.cacheHandler){await this.cacheHandler(i,async()=>f,l);return}this.setInMemoryCache(i,f,l)}delete(i){return this.memoryCache.delete(i)}has(i){let f=this.memoryCache.get(i);if(!f)return!1;if(f.expires<=Date.now())return this.memoryCache.delete(i),!1;return!0}generateKey(i,f){let l=new URL(i.url);return[i.method,l.pathname,l.search,f?.authUser?.id||"anonymous"].join(":")}}var{promises:c}=(()=>({}));function C(i){if(typeof i!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function K(i,f){var l="",a=0,E=-1,A=0,d;for(var _=0;_<=i.length;++_){if(_<i.length)d=i.charCodeAt(_);else if(d===47)break;else d=47;if(d===47){if(E===_-1||A===1);else if(E!==_-1&&A===2){if(l.length<2||a!==2||l.charCodeAt(l.length-1)!==46||l.charCodeAt(l.length-2)!==46){if(l.length>2){var I=l.lastIndexOf("/");if(I!==l.length-1){if(I===-1)l="",a=0;else l=l.slice(0,I),a=l.length-1-l.lastIndexOf("/");E=_,A=0;continue}}else if(l.length===2||l.length===1){l="",a=0,E=_,A=0;continue}}if(f){if(l.length>0)l+="/..";else l="..";a=2}}else{if(l.length>0)l+="/"+i.slice(E+1,_);else l=i.slice(E+1,_);a=_-E-1}E=_,A=0}else if(d===46&&A!==-1)++A;else A=-1}return l}function u(i,f){var l=f.dir||f.root,a=f.base||(f.name||"")+(f.ext||"");if(!l)return a;if(l===f.root)return l+a;return l+i+a}function S(){var i="",f=!1,l;for(var a=arguments.length-1;a>=-1&&!f;a--){var E;if(a>=0)E=arguments[a];else{if(l===void 0)l=process.cwd();E=l}if(C(E),E.length===0)continue;i=E+"/"+i,f=E.charCodeAt(0)===47}if(i=K(i,!f),f)if(i.length>0)return"/"+i;else return"/";else if(i.length>0)return i;else return"."}function Z(i){if(C(i),i.length===0)return".";var f=i.charCodeAt(0)===47,l=i.charCodeAt(i.length-1)===47;if(i=K(i,!f),i.length===0&&!f)i=".";if(i.length>0&&l)i+="/";if(f)return"/"+i;return i}function n(i){return C(i),i.length>0&&i.charCodeAt(0)===47}function Y(){if(arguments.length===0)return".";var i;for(var f=0;f<arguments.length;++f){var l=arguments[f];if(C(l),l.length>0)if(i===void 0)i=l;else i+="/"+l}if(i===void 0)return".";return Z(i)}function h(i,f){if(C(i),C(f),i===f)return"";if(i=S(i),f=S(f),i===f)return"";var l=1;for(;l<i.length;++l)if(i.charCodeAt(l)!==47)break;var a=i.length,E=a-l,A=1;for(;A<f.length;++A)if(f.charCodeAt(A)!==47)break;var d=f.length,_=d-A,I=E<_?E:_,O=-1,N=0;for(;N<=I;++N){if(N===I){if(_>I){if(f.charCodeAt(A+N)===47)return f.slice(A+N+1);else if(N===0)return f.slice(A+N)}else if(E>I){if(i.charCodeAt(l+N)===47)O=N;else if(N===0)O=0}break}var w=i.charCodeAt(l+N),L=f.charCodeAt(A+N);if(w!==L)break;else if(w===47)O=N}var $="";for(N=l+O+1;N<=a;++N)if(N===a||i.charCodeAt(N)===47)if($.length===0)$+="..";else $+="/..";if($.length>0)return $+f.slice(A+O);else{if(A+=O,f.charCodeAt(A)===47)++A;return f.slice(A)}}function y(i){return i}function j(i){if(C(i),i.length===0)return".";var f=i.charCodeAt(0),l=f===47,a=-1,E=!0;for(var A=i.length-1;A>=1;--A)if(f=i.charCodeAt(A),f===47){if(!E){a=A;break}}else E=!1;if(a===-1)return l?"/":".";if(l&&a===1)return"//";return i.slice(0,a)}function s(i,f){if(f!==void 0&&typeof f!=="string")throw new TypeError('"ext" argument must be a string');C(i);var l=0,a=-1,E=!0,A;if(f!==void 0&&f.length>0&&f.length<=i.length){if(f.length===i.length&&f===i)return"";var d=f.length-1,_=-1;for(A=i.length-1;A>=0;--A){var I=i.charCodeAt(A);if(I===47){if(!E){l=A+1;break}}else{if(_===-1)E=!1,_=A+1;if(d>=0)if(I===f.charCodeAt(d)){if(--d===-1)a=A}else d=-1,a=_}}if(l===a)a=_;else if(a===-1)a=i.length;return i.slice(l,a)}else{for(A=i.length-1;A>=0;--A)if(i.charCodeAt(A)===47){if(!E){l=A+1;break}}else if(a===-1)E=!1,a=A+1;if(a===-1)return"";return i.slice(l,a)}}function q(i){C(i);var f=-1,l=0,a=-1,E=!0,A=0;for(var d=i.length-1;d>=0;--d){var _=i.charCodeAt(d);if(_===47){if(!E){l=d+1;break}continue}if(a===-1)E=!1,a=d+1;if(_===46){if(f===-1)f=d;else if(A!==1)A=1}else if(f!==-1)A=-1}if(f===-1||a===-1||A===0||A===1&&f===a-1&&f===l+1)return"";return i.slice(f,a)}function r(i){if(i===null||typeof i!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof i);return u("/",i)}function t(i){C(i);var f={root:"",dir:"",base:"",ext:"",name:""};if(i.length===0)return f;var l=i.charCodeAt(0),a=l===47,E;if(a)f.root="/",E=1;else E=0;var A=-1,d=0,_=-1,I=!0,O=i.length-1,N=0;for(;O>=E;--O){if(l=i.charCodeAt(O),l===47){if(!I){d=O+1;break}continue}if(_===-1)I=!1,_=O+1;if(l===46){if(A===-1)A=O;else if(N!==1)N=1}else if(A!==-1)N=-1}if(A===-1||_===-1||N===0||N===1&&A===_-1&&A===d+1){if(_!==-1)if(d===0&&a)f.base=f.name=i.slice(1,_);else f.base=f.name=i.slice(d,_)}else{if(d===0&&a)f.name=i.slice(1,A),f.base=i.slice(1,_);else f.name=i.slice(d,A),f.base=i.slice(d,_);f.ext=i.slice(A,_)}if(d>0)f.dir=i.slice(0,d-1);else if(a)f.dir="/";return f}var Q="/",o=":",Ci=((i)=>(i.posix=i,i))({resolve:S,normalize:Z,isAbsolute:n,join:Y,relative:h,_makeLong:y,dirname:j,basename:s,extname:q,format:r,parse:t,sep:Q,delimiter:o,win32:null,posix:null});class V{outputPath;constructor(i="./.vector/routes.generated.ts"){this.outputPath=i}async generate(i){let f=j(this.outputPath);await c.mkdir(f,{recursive:!0});let l=[],a=new Map;for(let _ of i){if(!a.has(_.path))a.set(_.path,[]);a.get(_.path).push(_)}let E=0,A=[];for(let[_,I]of a){let O=h(j(this.outputPath),_).replace(/\\/g,"/").replace(/\.(ts|js)$/,""),N=`route_${E++}`,w=I.filter((L)=>L.name!=="default").map((L)=>L.name);if(I.some((L)=>L.name==="default"))if(w.length>0)l.push(`import ${N}, { ${w.join(", ")} } from '${O}';`);else l.push(`import ${N} from '${O}';`);else if(w.length>0)l.push(`import { ${w.join(", ")} } from '${O}';`);for(let L of I){let $=L.name==="default"?N:L.name;A.push(` ${$},`)}}let d=`// This file is auto-generated. Do not edit manually.
|
|
1
|
+
var d=(i="text/plain; charset=utf-8",f)=>(l,E={})=>{if(l===void 0||l instanceof Response)return l;let _=new Response(f?.(l)??l,E.url?void 0:E);return _.headers.set("content-type",i),_},Ai=d("application/json; charset=utf-8",JSON.stringify);var _i=d("text/plain; charset=utf-8",String),Oi=d("text/html"),Ni=d("image/jpeg"),Di=d("image/png"),Ii=d("image/webp"),K=async(i)=>{i.content=i.body?await i.clone().json().catch(()=>i.clone().formData()).catch(()=>i.text()):void 0},Z=(i)=>{i.cookies=(i.headers.get("Cookie")||"").split(/;\s*/).map((f)=>f.split(/=(.+)/)).reduce((f,[l,E])=>E?(f[l]=E,f):f,{})},x=(i={})=>{let{origin:f="*",credentials:l=!1,allowMethods:E="*",allowHeaders:_,exposeHeaders:A,maxAge:N}=i,O=(D)=>{let I=D?.headers.get("origin");return f===!0?I:f instanceof RegExp?f.test(I)?I:void 0:Array.isArray(f)?f.includes(I)?I:void 0:f instanceof Function?f(I):f=="*"&&l?I:f},U=(D,I)=>{for(let[$,w]of Object.entries(I))w&&D.headers.append($,w);return D};return{corsify:(D,I)=>D?.headers?.get("access-control-allow-origin")||D.status==101?D:U(D.clone(),{"access-control-allow-origin":O(I),"access-control-allow-credentials":l}),preflight:(D)=>{if(D.method=="OPTIONS"){let I=new Response(null,{status:204});return U(I,{"access-control-allow-origin":O(D),"access-control-allow-methods":E?.join?.(",")??E,"access-control-expose-headers":A?.join?.(",")??A,"access-control-allow-headers":_?.join?.(",")??_??D.headers.get("access-control-request-headers"),"access-control-max-age":N,"access-control-allow-credentials":l})}}}};var C={OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,IM_A_TEAPOT:418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511},X={PORT:3000,HOSTNAME:"localhost",ROUTES_DIR:"./routes",CACHE_TTL:0,CORS_MAX_AGE:86400},H={JSON:"application/json",TEXT:"text/plain",HTML:"text/html",FORM_URLENCODED:"application/x-www-form-urlencoded",MULTIPART:"multipart/form-data"};class h{protectedHandler=null;setProtectedHandler(i){this.protectedHandler=i}async authenticate(i){if(!this.protectedHandler)throw new Error("Protected handler not configured. Use vector.protected() to set authentication handler.");try{let f=await this.protectedHandler(i);return i.authUser=f,f}catch(f){throw new Error(`Authentication failed: ${f instanceof Error?f.message:String(f)}`)}}isAuthenticated(i){return!!i.authUser}getUser(i){return i.authUser||null}}class z{cacheHandler=null;memoryCache=new Map;cleanupInterval=null;setCacheHandler(i){this.cacheHandler=i}async get(i,f,l=X.CACHE_TTL){if(l<=0)return f();if(this.cacheHandler)return this.cacheHandler(i,f,l);return this.getFromMemoryCache(i,f,l)}async getFromMemoryCache(i,f,l){let E=Date.now(),_=this.memoryCache.get(i);if(this.isCacheValid(_,E))return _.value;let A=await f();return this.setInMemoryCache(i,A,l),A}isCacheValid(i,f){return i!==void 0&&i.expires>f}setInMemoryCache(i,f,l){let E=Date.now()+l*1000;this.memoryCache.set(i,{value:f,expires:E}),this.scheduleCleanup()}scheduleCleanup(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanupExpired()},60000)}cleanupExpired(){let i=Date.now();for(let[f,l]of this.memoryCache.entries())if(l.expires<=i)this.memoryCache.delete(f);if(this.memoryCache.size===0&&this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}clear(){if(this.memoryCache.clear(),this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}async set(i,f,l=X.CACHE_TTL){if(l<=0)return;if(this.cacheHandler){await this.cacheHandler(i,async()=>f,l);return}this.setInMemoryCache(i,f,l)}delete(i){return this.memoryCache.delete(i)}has(i){let f=this.memoryCache.get(i);if(!f)return!1;if(f.expires<=Date.now())return this.memoryCache.delete(i),!1;return!0}generateKey(i,f){let l=new URL(i.url);return[i.method,l.pathname,l.search,f?.authUser?.id||"anonymous"].join(":")}}var{promises:k}=(()=>({}));function S(i){if(typeof i!=="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function v(i,f){var l="",E=0,_=-1,A=0,N;for(var O=0;O<=i.length;++O){if(O<i.length)N=i.charCodeAt(O);else if(N===47)break;else N=47;if(N===47){if(_===O-1||A===1);else if(_!==O-1&&A===2){if(l.length<2||E!==2||l.charCodeAt(l.length-1)!==46||l.charCodeAt(l.length-2)!==46){if(l.length>2){var U=l.lastIndexOf("/");if(U!==l.length-1){if(U===-1)l="",E=0;else l=l.slice(0,U),E=l.length-1-l.lastIndexOf("/");_=O,A=0;continue}}else if(l.length===2||l.length===1){l="",E=0,_=O,A=0;continue}}if(f){if(l.length>0)l+="/..";else l="..";E=2}}else{if(l.length>0)l+="/"+i.slice(_+1,O);else l=i.slice(_+1,O);E=O-_-1}_=O,A=0}else if(N===46&&A!==-1)++A;else A=-1}return l}function u(i,f){var l=f.dir||f.root,E=f.base||(f.name||"")+(f.ext||"");if(!l)return E;if(l===f.root)return l+E;return l+i+E}function j(){var i="",f=!1,l;for(var E=arguments.length-1;E>=-1&&!f;E--){var _;if(E>=0)_=arguments[E];else{if(l===void 0)l=process.cwd();_=l}if(S(_),_.length===0)continue;i=_+"/"+i,f=_.charCodeAt(0)===47}if(i=v(i,!f),f)if(i.length>0)return"/"+i;else return"/";else if(i.length>0)return i;else return"."}function T(i){if(S(i),i.length===0)return".";var f=i.charCodeAt(0)===47,l=i.charCodeAt(i.length-1)===47;if(i=v(i,!f),i.length===0&&!f)i=".";if(i.length>0&&l)i+="/";if(f)return"/"+i;return i}function q(i){return S(i),i.length>0&&i.charCodeAt(0)===47}function J(){if(arguments.length===0)return".";var i;for(var f=0;f<arguments.length;++f){var l=arguments[f];if(S(l),l.length>0)if(i===void 0)i=l;else i+="/"+l}if(i===void 0)return".";return T(i)}function G(i,f){if(S(i),S(f),i===f)return"";if(i=j(i),f=j(f),i===f)return"";var l=1;for(;l<i.length;++l)if(i.charCodeAt(l)!==47)break;var E=i.length,_=E-l,A=1;for(;A<f.length;++A)if(f.charCodeAt(A)!==47)break;var N=f.length,O=N-A,U=_<O?_:O,D=-1,I=0;for(;I<=U;++I){if(I===U){if(O>U){if(f.charCodeAt(A+I)===47)return f.slice(A+I+1);else if(I===0)return f.slice(A+I)}else if(_>U){if(i.charCodeAt(l+I)===47)D=I;else if(I===0)D=0}break}var $=i.charCodeAt(l+I),w=f.charCodeAt(A+I);if($!==w)break;else if($===47)D=I}var R="";for(I=l+D+1;I<=E;++I)if(I===E||i.charCodeAt(I)===47)if(R.length===0)R+="..";else R+="/..";if(R.length>0)return R+f.slice(A+D);else{if(A+=D,f.charCodeAt(A)===47)++A;return f.slice(A)}}function y(i){return i}function F(i){if(S(i),i.length===0)return".";var f=i.charCodeAt(0),l=f===47,E=-1,_=!0;for(var A=i.length-1;A>=1;--A)if(f=i.charCodeAt(A),f===47){if(!_){E=A;break}}else _=!1;if(E===-1)return l?"/":".";if(l&&E===1)return"//";return i.slice(0,E)}function n(i,f){if(f!==void 0&&typeof f!=="string")throw new TypeError('"ext" argument must be a string');S(i);var l=0,E=-1,_=!0,A;if(f!==void 0&&f.length>0&&f.length<=i.length){if(f.length===i.length&&f===i)return"";var N=f.length-1,O=-1;for(A=i.length-1;A>=0;--A){var U=i.charCodeAt(A);if(U===47){if(!_){l=A+1;break}}else{if(O===-1)_=!1,O=A+1;if(N>=0)if(U===f.charCodeAt(N)){if(--N===-1)E=A}else N=-1,E=O}}if(l===E)E=O;else if(E===-1)E=i.length;return i.slice(l,E)}else{for(A=i.length-1;A>=0;--A)if(i.charCodeAt(A)===47){if(!_){l=A+1;break}}else if(E===-1)_=!1,E=A+1;if(E===-1)return"";return i.slice(l,E)}}function s(i){S(i);var f=-1,l=0,E=-1,_=!0,A=0;for(var N=i.length-1;N>=0;--N){var O=i.charCodeAt(N);if(O===47){if(!_){l=N+1;break}continue}if(E===-1)_=!1,E=N+1;if(O===46){if(f===-1)f=N;else if(A!==1)A=1}else if(f!==-1)A=-1}if(f===-1||E===-1||A===0||A===1&&f===E-1&&f===l+1)return"";return i.slice(f,E)}function p(i){if(i===null||typeof i!=="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof i);return u("/",i)}function r(i){S(i);var f={root:"",dir:"",base:"",ext:"",name:""};if(i.length===0)return f;var l=i.charCodeAt(0),E=l===47,_;if(E)f.root="/",_=1;else _=0;var A=-1,N=0,O=-1,U=!0,D=i.length-1,I=0;for(;D>=_;--D){if(l=i.charCodeAt(D),l===47){if(!U){N=D+1;break}continue}if(O===-1)U=!1,O=D+1;if(l===46){if(A===-1)A=D;else if(I!==1)I=1}else if(A!==-1)I=-1}if(A===-1||O===-1||I===0||I===1&&A===O-1&&A===N+1){if(O!==-1)if(N===0&&E)f.base=f.name=i.slice(1,O);else f.base=f.name=i.slice(N,O)}else{if(N===0&&E)f.name=i.slice(1,A),f.base=i.slice(1,O);else f.name=i.slice(N,A),f.base=i.slice(N,O);f.ext=i.slice(A,O)}if(N>0)f.dir=i.slice(0,N-1);else if(E)f.dir="/";return f}var Y="/",o=":",Si=((i)=>(i.posix=i,i))({resolve:j,normalize:T,isAbsolute:q,join:J,relative:G,_makeLong:y,dirname:F,basename:n,extname:s,format:p,parse:r,sep:Y,delimiter:o,win32:null,posix:null});class W{outputPath;constructor(i="./.vector/routes.generated.ts"){this.outputPath=i}async generate(i){let f=F(this.outputPath);await k.mkdir(f,{recursive:!0});let l=[],E=new Map;for(let O of i){if(!E.has(O.path))E.set(O.path,[]);E.get(O.path).push(O)}let _=0,A=[];for(let[O,U]of E){let D=G(F(this.outputPath),O).replace(/\\/g,"/").replace(/\.(ts|js)$/,""),I=`route_${_++}`,$=U.filter((w)=>w.name!=="default").map((w)=>w.name);if(U.some((w)=>w.name==="default"))if($.length>0)l.push(`import ${I}, { ${$.join(", ")} } from '${D}';`);else l.push(`import ${I} from '${D}';`);else if($.length>0)l.push(`import { ${$.join(", ")} } from '${D}';`);for(let w of U){let R=w.name==="default"?I:w.name;A.push(` ${R},`)}}let N=`// This file is auto-generated. Do not edit manually.
|
|
2
2
|
// Generated at: ${new Date().toISOString()}
|
|
3
3
|
|
|
4
4
|
${l.join(`
|
|
@@ -10,12 +10,12 @@ ${A.join(`
|
|
|
10
10
|
];
|
|
11
11
|
|
|
12
12
|
export default routes;
|
|
13
|
-
`;await
|
|
14
|
-
...${
|
|
13
|
+
`;await k.writeFile(this.outputPath,N,"utf-8")}async generateDynamic(i){let f=[];for(let l of i){let E=JSON.stringify({method:l.method,path:l.options.path,options:l.options});f.push(` await import('${l.path}').then(m => ({
|
|
14
|
+
...${E},
|
|
15
15
|
handler: m.${l.name==="default"?"default":l.name}
|
|
16
16
|
}))`)}return`export const loadRoutes = async () => {
|
|
17
17
|
return Promise.all([
|
|
18
18
|
${f.join(`,
|
|
19
19
|
`)}
|
|
20
20
|
]);
|
|
21
|
-
};`}}var{existsSync:p,promises:g}=(()=>({}));class X{routesDir;constructor(i="./routes"){this.routesDir=S(process.cwd(),i)}async scan(){let i=[];if(!p(this.routesDir))return[];try{await this.scanDirectory(this.routesDir,i)}catch(f){if(f.code==="ENOENT")return console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`),[];throw f}return i}async scanDirectory(i,f,l=""){let a=await g.readdir(i);for(let E of a){let A=Y(i,E);if((await g.stat(A)).isDirectory()){let _=l?`${l}/${E}`:E;await this.scanDirectory(A,f,_)}else if(E.endsWith(".ts")||E.endsWith(".js")){let _=h(this.routesDir,A).replace(/\.(ts|js)$/,"").split(Q).join("/");try{let O=await import(process.platform==="win32"?`file:///${A.replace(/\\/g,"/")}`:A);if(O.default&&typeof O.default==="function")f.push({name:"default",path:A,method:"GET",options:{method:"GET",path:`/${_}`,expose:!0}});for(let[N,w]of Object.entries(O)){if(N==="default")continue;if(w&&typeof w==="object"&&"entry"in w&&"options"in w&&"handler"in w){let L=w;f.push({name:N,path:A,method:L.options.method,options:L.options})}else if(Array.isArray(w)&&w.length>=4){let[L,,,$]=w;f.push({name:N,path:A,method:L,options:{method:L,path:$,expose:!0}})}}}catch(I){console.error(`Failed to load route from ${A}:`,I)}}}}enableWatch(i){if(typeof Bun!=="undefined"&&Bun.env.NODE_ENV==="development")console.log(`Watching for route changes in ${this.routesDir}`),setInterval(async()=>{await i()},1000)}}class F{beforeHandlers=[];finallyHandlers=[];addBefore(...i){this.beforeHandlers.push(...i)}addFinally(...i){this.finallyHandlers.push(...i)}async executeBefore(i){let f=i;for(let l of this.beforeHandlers){let a=await l(f);if(a instanceof Response)return a;f=a}return f}async executeFinally(i,f){let l=i;for(let a of this.finallyHandlers)l=await a(l,f);return l}clone(){let i=new F;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function k(i){return process.platform==="win32"?`file:///${i.replace(/\\/g,"/")}`:i}class z{middlewareManager;authManager;cacheManager;routes=[];constructor(i,f,l){this.middlewareManager=i,this.authManager=f,this.cacheManager=l}getRouteSpecificity(i){let A=0,d=i.split("/").filter(Boolean);for(let _ of d)if(this.isStaticSegment(_))A+=1000;else if(this.isParamSegment(_))A+=10;else if(this.isWildcardSegment(_))A+=1;if(A+=i.length,this.isExactPath(i))A+=1e4;return A}isStaticSegment(i){return!i.startsWith(":")&&!i.includes("*")}isParamSegment(i){return i.startsWith(":")}isWildcardSegment(i){return i.includes("*")}isExactPath(i){return!i.includes(":")&&!i.includes("*")}sortRoutes(){this.routes.sort((i,f)=>{let l=this.extractPath(i),a=this.extractPath(f),E=this.getRouteSpecificity(l);return this.getRouteSpecificity(a)-E})}extractPath(i){return i[3]||""}route(i,f){let l=this.wrapHandler(i,f),a=[i.method.toUpperCase(),this.createRouteRegex(i.path),[l],i.path];return this.routes.push(a),this.sortRoutes(),a}createRouteRegex(i){return RegExp(`^${i.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`)}prepareRequest(i,f){if(!i.context)i.context={};if(f?.params!==void 0)i.params=f.params;if(f?.route!==void 0)i.route=f.route;if(f?.metadata!==void 0)i.metadata=f.metadata;if(!i.query&&i.url){let l=new URL(i.url),a={};for(let[E,A]of l.searchParams)if(E in a)if(Array.isArray(a[E]))a[E].push(A);else a[E]=[a[E],A];else a[E]=A;i.query=a}if(!i.cookies)v(i)}wrapHandler(i,f){return async(l)=>{let a=l;this.prepareRequest(a,{metadata:i.metadata}),l=a;try{if(i.expose===!1)return U.forbidden("Forbidden");let E=await this.middlewareManager.executeBefore(l);if(E instanceof Response)return E;if(l=E,i.auth)try{await this.authManager.authenticate(l)}catch(O){return U.unauthorized(O instanceof Error?O.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let O=l.headers.get("content-type");if(O?.includes("application/json"))l.content=await l.json();else if(O?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(O?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let A,d=i.cache,_=async()=>{let O=await f(l);if(O instanceof Response)return{_isResponse:!0,body:await O.text(),status:O.status,headers:Object.fromEntries(O.headers.entries())};return O};if(d&&typeof d==="number"&&d>0){let O=this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(O,_,d)}else if(d&&typeof d==="object"&&d.ttl){let O=d.key||this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(O,_,d.ttl)}else A=await f(l);if(A&&typeof A==="object"&&A._isResponse===!0)A=new Response(A.body,{status:A.status,headers:A.headers});let I;if(i.rawResponse||A instanceof Response)I=A instanceof Response?A:new Response(A);else I=b(200,A,i.responseContentType);return I=await this.middlewareManager.executeFinally(I,l),I}catch(E){if(E instanceof Response)return E;return console.error("Route handler error:",E),U.internalServerError(E instanceof Error?E.message:String(E),i.responseContentType)}}}addRoute(i){this.routes.push(i),this.sortRoutes()}getRoutes(){return this.routes}async handle(i){let l=new URL(i.url).pathname;for(let[a,E,A,d]of this.routes)if(i.method==="OPTIONS"||i.method===a){let _=l.match(E);if(_){let I=i;this.prepareRequest(I,{params:_.groups||{},route:d||l});for(let O of A){let N=await O(I);if(N)return N}}}return U.notFound("Route not found")}clearRoutes(){this.routes=[]}}class J{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:a}=x(this.normalizeCorsOptions(f.cors));this.corsHandler={preflight:l,corsify:a}}}normalizeCorsOptions(i){return{origin:i.origin||"*",credentials:i.credentials!==!1,allowHeaders:Array.isArray(i.allowHeaders)?i.allowHeaders.join(", "):i.allowHeaders||"Content-Type, Authorization",allowMethods:Array.isArray(i.allowMethods)?i.allowMethods.join(", "):i.allowMethods||"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:Array.isArray(i.exposeHeaders)?i.exposeHeaders.join(", "):i.exposeHeaders||"Authorization",maxAge:i.maxAge||86400}}async start(){let i=this.config.port||3000,f=this.config.hostname||"localhost",l=async(a)=>{try{if(this.corsHandler&&a.method==="OPTIONS")return this.corsHandler.preflight(a);let E=await this.router.handle(a);if(this.corsHandler)E=this.corsHandler.corsify(E,a);return E}catch(E){return console.error("Server error:",E),new Response("Internal Server Error",{status:500})}};try{if(this.server=Bun.serve({port:i,hostname:f,reusePort:this.config.reusePort!==!1,fetch:l,idleTimeout:this.config.idleTimeout||60,error:(a)=>{return console.error("[ERROR] Server error:",a),new Response("Internal Server Error",{status:500})}}),!this.server||!this.server.port)throw new Error(`Failed to start server on ${f}:${i} - server object is invalid`);return console.log(`→ Vector server running at http://${f}:${i}`),this.server}catch(a){if(a.code==="EADDRINUSE"||a.message?.includes("address already in use"))a.message=`Port ${i} is already in use`,a.port=i;else if(a.code==="EACCES"||a.message?.includes("permission denied"))a.message=`Permission denied to bind to port ${i}`,a.port=i;else if(a.message?.includes("EADDRNOTAVAIL"))a.message=`Cannot bind to hostname ${f}`,a.hostname=f;throw a}}stop(){if(this.server)this.server.stop(),this.server=null,console.log("Server stopped")}getServer(){return this.server}getPort(){return this.server?.port||this.config.port||3000}getHostname(){return this.server?.hostname||this.config.hostname||"localhost"}getUrl(){let i=this.getPort();return`http://${this.getHostname()}:${i}`}}class P{static instance;router;server=null;middlewareManager;authManager;cacheManager;config={};routeScanner=null;routeGenerator=null;_protectedHandler=null;_cacheHandler=null;constructor(){this.middlewareManager=new F,this.authManager=new T,this.cacheManager=new B,this.router=new z(this.middlewareManager,this.authManager,this.cacheManager)}static getInstance(){if(!P.instance)P.instance=new P;return P.instance}setProtectedHandler(i){this._protectedHandler=i,this.authManager.setProtectedHandler(i)}getProtectedHandler(){return this._protectedHandler}setCacheHandler(i){this._cacheHandler=i,this.cacheManager.setCacheHandler(i)}getCacheHandler(){return this._cacheHandler}addRoute(i,f){return this.router.route(i,f)}async startServer(i){if(this.config={...this.config,...i},this.middlewareManager.clear(),i?.before)this.middlewareManager.addBefore(...i.before);if(i?.finally)this.middlewareManager.addFinally(...i.finally);if(this.config.autoDiscover!==!1)await this.discoverRoutes();return this.server=new J(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes";if(this.routeScanner=new X(i),!this.routeGenerator)this.routeGenerator=new V;try{let f=await this.routeScanner.scan();if(f.length>0){if(this.config.development)await this.routeGenerator.generate(f);for(let l of f)try{let E=await import(k(l.path)),A=l.name==="default"?E.default:E[l.name];if(A){if(this.isRouteDefinition(A)){let d=A;this.router.route(d.options,d.handler),this.logRouteLoaded(d.options)}else if(this.isRouteEntry(A))this.router.addRoute(A),this.logRouteLoaded(A);else if(typeof A==="function")this.router.route(l.options,A),this.logRouteLoaded(l.options)}}catch(a){console.error(`Failed to load route ${l.name} from ${l.path}:`,a)}this.router.sortRoutes()}}catch(f){if(f.code!=="ENOENT"&&f.code!=="ENOTDIR")console.error("Failed to discover routes:",f)}}async loadRoute(i){if(typeof i==="function"){let f=i();if(Array.isArray(f))this.router.addRoute(f)}else if(i&&typeof i==="object"){for(let[,f]of Object.entries(i))if(typeof f==="function"){let l=f();if(Array.isArray(l))this.router.addRoute(l)}}}isRouteEntry(i){return Array.isArray(i)&&i.length>=3}isRouteDefinition(i){return i&&typeof i==="object"&&"entry"in i&&"options"in i&&"handler"in i}logRouteLoaded(i){}stop(){if(this.server)this.server.stop(),this.server=null;this.router.clearRoutes()}getServer(){return this.server}getRouter(){return this.router}getCacheManager(){return this.cacheManager}getAuthManager(){return this.authManager}static resetInstance(){P.instance=null}}var m=P.getInstance;var{preflight:ki,corsify:mi}=x({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400});function e(i,f){let l=ai(i,f);return{entry:[i.method.toUpperCase(),RegExp(`^${i.path.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),[l],i.path],options:i,handler:f}}function ii(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}var fi={success:(i,f)=>b(R.OK,i,f),created:(i,f)=>b(R.CREATED,i,f)};function D(i,f,l){let a={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return b(i,a,l)}var U={badRequest:(i="Bad Request",f)=>D(R.BAD_REQUEST,i,f),unauthorized:(i="Unauthorized",f)=>D(R.UNAUTHORIZED,i,f),paymentRequired:(i="Payment Required",f)=>D(402,i,f),forbidden:(i="Forbidden",f)=>D(R.FORBIDDEN,i,f),notFound:(i="Not Found",f)=>D(R.NOT_FOUND,i,f),methodNotAllowed:(i="Method Not Allowed",f)=>D(405,i,f),notAcceptable:(i="Not Acceptable",f)=>D(406,i,f),requestTimeout:(i="Request Timeout",f)=>D(408,i,f),conflict:(i="Conflict",f)=>D(R.CONFLICT,i,f),gone:(i="Gone",f)=>D(410,i,f),lengthRequired:(i="Length Required",f)=>D(411,i,f),preconditionFailed:(i="Precondition Failed",f)=>D(412,i,f),payloadTooLarge:(i="Payload Too Large",f)=>D(413,i,f),uriTooLong:(i="URI Too Long",f)=>D(414,i,f),unsupportedMediaType:(i="Unsupported Media Type",f)=>D(415,i,f),rangeNotSatisfiable:(i="Range Not Satisfiable",f)=>D(416,i,f),expectationFailed:(i="Expectation Failed",f)=>D(417,i,f),imATeapot:(i="I'm a teapot",f)=>D(418,i,f),misdirectedRequest:(i="Misdirected Request",f)=>D(421,i,f),unprocessableEntity:(i="Unprocessable Entity",f)=>D(R.UNPROCESSABLE_ENTITY,i,f),locked:(i="Locked",f)=>D(423,i,f),failedDependency:(i="Failed Dependency",f)=>D(424,i,f),tooEarly:(i="Too Early",f)=>D(425,i,f),upgradeRequired:(i="Upgrade Required",f)=>D(426,i,f),preconditionRequired:(i="Precondition Required",f)=>D(428,i,f),tooManyRequests:(i="Too Many Requests",f)=>D(429,i,f),requestHeaderFieldsTooLarge:(i="Request Header Fields Too Large",f)=>D(431,i,f),unavailableForLegalReasons:(i="Unavailable For Legal Reasons",f)=>D(451,i,f),internalServerError:(i="Internal Server Error",f)=>D(R.INTERNAL_SERVER_ERROR,i,f),notImplemented:(i="Not Implemented",f)=>D(501,i,f),badGateway:(i="Bad Gateway",f)=>D(502,i,f),serviceUnavailable:(i="Service Unavailable",f)=>D(503,i,f),gatewayTimeout:(i="Gateway Timeout",f)=>D(504,i,f),httpVersionNotSupported:(i="HTTP Version Not Supported",f)=>D(505,i,f),variantAlsoNegotiates:(i="Variant Also Negotiates",f)=>D(506,i,f),insufficientStorage:(i="Insufficient Storage",f)=>D(507,i,f),loopDetected:(i="Loop Detected",f)=>D(508,i,f),notExtended:(i="Not Extended",f)=>D(510,i,f),networkAuthenticationRequired:(i="Network Authentication Required",f)=>D(511,i,f),invalidArgument:(i="Invalid Argument",f)=>D(R.UNPROCESSABLE_ENTITY,i,f),rateLimitExceeded:(i="Rate Limit Exceeded",f)=>D(429,i,f),maintenance:(i="Service Under Maintenance",f)=>D(503,i,f),custom:(i,f,l)=>D(i,f,l)};function b(i,f,l=G.JSON){let a=l===G.JSON?ii(f):f;return new Response(a,{status:i,headers:{"content-type":l}})}var li=async(i,f)=>{let a=m().getProtectedHandler();if(!a)throw U.unauthorized("Authentication not configured",f);try{let E=await a(i);i.authUser=E}catch(E){throw U.unauthorized(E instanceof Error?E.message:"Authentication failed",f)}};function ai(i,f){let{auth:l=!1,expose:a=!1,rawRequest:E=!1,rawResponse:A=!1,responseContentType:d=G.JSON}=i;return async(_)=>{if(!a)return U.forbidden("Forbidden");try{if(l)await li(_,d);if(!E)await W(_);let I=await f(_);return A?I:fi.success(I,d)}catch(I){if(I instanceof Response)return I;return U.internalServerError(String(I),d)}}}export{e as route,b as createResponse,U as APIError};
|
|
21
|
+
};`}}var{existsSync:t,promises:g}=(()=>({}));class Q{routesDir;excludePatterns;static DEFAULT_EXCLUDE_PATTERNS=["*.test.ts","*.test.js","*.test.tsx","*.test.jsx","*.spec.ts","*.spec.js","*.spec.tsx","*.spec.jsx","*.tests.ts","*.tests.js","**/__tests__/**","*.interface.ts","*.type.ts","*.d.ts"];constructor(i="./routes",f){this.routesDir=j(process.cwd(),i),this.excludePatterns=f||Q.DEFAULT_EXCLUDE_PATTERNS}async scan(){let i=[];if(!t(this.routesDir))return[];try{await this.scanDirectory(this.routesDir,i)}catch(f){if(f.code==="ENOENT")return console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`),[];throw f}return i}isExcluded(i){let f=G(this.routesDir,i);for(let l of this.excludePatterns){let E=l.replace(/\./g,"\\.").replace(/\*/g,"[^/]*").replace(/\*\*/g,".*").replace(/\?/g,"."),_=new RegExp(`^${E}$`),A=f.split(Y).pop()||"";if(_.test(f)||_.test(A))return!0}return!1}async scanDirectory(i,f,l=""){let E=await g.readdir(i);for(let _ of E){let A=J(i,_);if((await g.stat(A)).isDirectory()){let O=l?`${l}/${_}`:_;await this.scanDirectory(A,f,O)}else if(_.endsWith(".ts")||_.endsWith(".js")){if(this.isExcluded(A))continue;let O=G(this.routesDir,A).replace(/\.(ts|js)$/,"").split(Y).join("/");try{let D=await import(process.platform==="win32"?`file:///${A.replace(/\\/g,"/")}`:A);if(D.default&&typeof D.default==="function")f.push({name:"default",path:A,method:"GET",options:{method:"GET",path:`/${O}`,expose:!0}});for(let[I,$]of Object.entries(D)){if(I==="default")continue;if($&&typeof $==="object"&&"entry"in $&&"options"in $&&"handler"in $){let w=$;f.push({name:I,path:A,method:w.options.method,options:w.options})}else if(Array.isArray($)&&$.length>=4){let[w,,,R]=$;f.push({name:I,path:A,method:w,options:{method:w,path:R,expose:!0}})}}}catch(U){console.error(`Failed to load route from ${A}:`,U)}}}}enableWatch(i){if(typeof Bun!=="undefined"&&Bun.env.NODE_ENV==="development")console.log(`Watching for route changes in ${this.routesDir}`),setInterval(async()=>{await i()},1000)}}class B{beforeHandlers=[];finallyHandlers=[];addBefore(...i){this.beforeHandlers.push(...i)}addFinally(...i){this.finallyHandlers.push(...i)}async executeBefore(i){let f=i;for(let l of this.beforeHandlers){let E=await l(f);if(E instanceof Response)return E;f=E}return f}async executeFinally(i,f){let l=i;for(let E of this.finallyHandlers)try{l=await E(l,f)}catch(_){console.error("After middleware error:",_)}return l}clone(){let i=new B;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function c(i){return process.platform==="win32"?`file:///${i.replace(/\\/g,"/")}`:i}class M{middlewareManager;authManager;cacheManager;routes=[];constructor(i,f,l){this.middlewareManager=i,this.authManager=f,this.cacheManager=l}getRouteSpecificity(i){let A=0,N=i.split("/").filter(Boolean);for(let O of N)if(this.isStaticSegment(O))A+=1000;else if(this.isParamSegment(O))A+=10;else if(this.isWildcardSegment(O))A+=1;if(A+=i.length,this.isExactPath(i))A+=1e4;return A}isStaticSegment(i){return!i.startsWith(":")&&!i.includes("*")}isParamSegment(i){return i.startsWith(":")}isWildcardSegment(i){return i.includes("*")}isExactPath(i){return!i.includes(":")&&!i.includes("*")}sortRoutes(){this.routes.sort((i,f)=>{let l=this.extractPath(i),E=this.extractPath(f),_=this.getRouteSpecificity(l);return this.getRouteSpecificity(E)-_})}extractPath(i){return i[3]||""}route(i,f){let l=this.wrapHandler(i,f),E=[i.method.toUpperCase(),this.createRouteRegex(i.path),[l],i.path];return this.routes.push(E),this.sortRoutes(),E}createRouteRegex(i){return RegExp(`^${i.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`)}prepareRequest(i,f){if(!i.context)i.context={};if(f?.params!==void 0)i.params=f.params;if(f?.route!==void 0)i.route=f.route;if(f?.metadata!==void 0)i.metadata=f.metadata;if(!i.query&&i.url){let l=new URL(i.url),E={};for(let[_,A]of l.searchParams)if(_ in E)if(Array.isArray(E[_]))E[_].push(A);else E[_]=[E[_],A];else E[_]=A;i.query=E}if(!i.cookies)Z(i)}wrapHandler(i,f){return async(l)=>{let E=l;this.prepareRequest(E,{metadata:i.metadata}),l=E;try{if(i.expose===!1)return b.forbidden("Forbidden");let _=await this.middlewareManager.executeBefore(l);if(_ instanceof Response)return _;if(l=_,i.auth)try{await this.authManager.authenticate(l)}catch(D){return b.unauthorized(D instanceof Error?D.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let D=l.headers.get("content-type");if(D?.includes("application/json"))l.content=await l.json();else if(D?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(D?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let A,N=i.cache,O=async()=>{let D=await f(l);if(D instanceof Response)return{_isResponse:!0,body:await D.text(),status:D.status,headers:Object.fromEntries(D.headers.entries())};return D};if(N&&typeof N==="number"&&N>0){let D=this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(D,O,N)}else if(N&&typeof N==="object"&&N.ttl){let D=N.key||this.cacheManager.generateKey(l,{authUser:l.authUser});A=await this.cacheManager.get(D,O,N.ttl)}else A=await f(l);if(A&&typeof A==="object"&&A._isResponse===!0)A=new Response(A.body,{status:A.status,headers:A.headers});let U;if(i.rawResponse||A instanceof Response)U=A instanceof Response?A:new Response(A);else U=a(200,A,i.responseContentType);return U=await this.middlewareManager.executeFinally(U,l),U}catch(_){if(_ instanceof Response)return _;return console.error("Route handler error:",_),b.internalServerError(_ instanceof Error?_.message:String(_),i.responseContentType)}}}addRoute(i){this.routes.push(i),this.sortRoutes()}getRoutes(){return this.routes}async handle(i){let l=new URL(i.url).pathname;for(let[E,_,A,N]of this.routes)if(i.method==="OPTIONS"||i.method===E){let O=l.match(_);if(O){let U=i;this.prepareRequest(U,{params:O.groups||{},route:N||l});for(let D of A){let I=await D(U);if(I)return I}}}return b.notFound("Route not found")}clearRoutes(){this.routes=[]}}class V{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:E}=x(this.normalizeCorsOptions(f.cors));this.corsHandler={preflight:l,corsify:E}}}normalizeCorsOptions(i){return{origin:i.origin||"*",credentials:i.credentials!==!1,allowHeaders:Array.isArray(i.allowHeaders)?i.allowHeaders.join(", "):i.allowHeaders||"Content-Type, Authorization",allowMethods:Array.isArray(i.allowMethods)?i.allowMethods.join(", "):i.allowMethods||"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:Array.isArray(i.exposeHeaders)?i.exposeHeaders.join(", "):i.exposeHeaders||"Authorization",maxAge:i.maxAge||86400}}async start(){let i=this.config.port||3000,f=this.config.hostname||"localhost",l=async(E)=>{try{if(this.corsHandler&&E.method==="OPTIONS")return this.corsHandler.preflight(E);let _=await this.router.handle(E);if(this.corsHandler)_=this.corsHandler.corsify(_,E);return _}catch(_){return console.error("Server error:",_),new Response("Internal Server Error",{status:500})}};try{if(this.server=Bun.serve({port:i,hostname:f,reusePort:this.config.reusePort!==!1,fetch:l,idleTimeout:this.config.idleTimeout||60,error:(E)=>{return console.error("[ERROR] Server error:",E),new Response("Internal Server Error",{status:500})}}),!this.server||!this.server.port)throw new Error(`Failed to start server on ${f}:${i} - server object is invalid`);return this.server}catch(E){if(E.code==="EADDRINUSE"||E.message?.includes("address already in use"))E.message=`Port ${i} is already in use`,E.port=i;else if(E.code==="EACCES"||E.message?.includes("permission denied"))E.message=`Permission denied to bind to port ${i}`,E.port=i;else if(E.message?.includes("EADDRNOTAVAIL"))E.message=`Cannot bind to hostname ${f}`,E.hostname=f;throw E}}stop(){if(this.server)this.server.stop(),this.server=null,console.log("Server stopped")}getServer(){return this.server}getPort(){return this.server?.port||this.config.port||3000}getHostname(){return this.server?.hostname||this.config.hostname||"localhost"}getUrl(){let i=this.getPort();return`http://${this.getHostname()}:${i}`}}class P{static instance;router;server=null;middlewareManager;authManager;cacheManager;config={};routeScanner=null;routeGenerator=null;_protectedHandler=null;_cacheHandler=null;constructor(){this.middlewareManager=new B,this.authManager=new h,this.cacheManager=new z,this.router=new M(this.middlewareManager,this.authManager,this.cacheManager)}static getInstance(){if(!P.instance)P.instance=new P;return P.instance}setProtectedHandler(i){this._protectedHandler=i,this.authManager.setProtectedHandler(i)}getProtectedHandler(){return this._protectedHandler}setCacheHandler(i){this._cacheHandler=i,this.cacheManager.setCacheHandler(i)}getCacheHandler(){return this._cacheHandler}addRoute(i,f){return this.router.route(i,f)}async startServer(i){if(this.config={...this.config,...i},this.middlewareManager.clear(),this.config.autoDiscover!==!1)this.router.clearRoutes();if(i?.before)this.middlewareManager.addBefore(...i.before);if(i?.finally)this.middlewareManager.addFinally(...i.finally);if(this.config.autoDiscover!==!1)await this.discoverRoutes();return this.server=new V(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes",f=this.config.routeExcludePatterns;if(this.routeScanner=new Q(i,f),!this.routeGenerator)this.routeGenerator=new W;try{let l=await this.routeScanner.scan();if(l.length>0){if(this.config.development)await this.routeGenerator.generate(l);for(let E of l)try{let A=await import(c(E.path)),N=E.name==="default"?A.default:A[E.name];if(N){if(this.isRouteDefinition(N)){let O=N;this.router.route(O.options,O.handler),this.logRouteLoaded(O.options)}else if(this.isRouteEntry(N))this.router.addRoute(N),this.logRouteLoaded(N);else if(typeof N==="function")this.router.route(E.options,N),this.logRouteLoaded(E.options)}}catch(_){console.error(`Failed to load route ${E.name} from ${E.path}:`,_)}this.router.sortRoutes()}}catch(l){if(l.code!=="ENOENT"&&l.code!=="ENOTDIR")console.error("Failed to discover routes:",l)}}async loadRoute(i){if(typeof i==="function"){let f=i();if(Array.isArray(f))this.router.addRoute(f)}else if(i&&typeof i==="object"){for(let[,f]of Object.entries(i))if(typeof f==="function"){let l=f();if(Array.isArray(l))this.router.addRoute(l)}}}isRouteEntry(i){return Array.isArray(i)&&i.length>=3}isRouteDefinition(i){return i&&typeof i==="object"&&"entry"in i&&"options"in i&&"handler"in i}logRouteLoaded(i){}stop(){if(this.server)this.server.stop(),this.server=null}getServer(){return this.server}getRouter(){return this.router}getCacheManager(){return this.cacheManager}getAuthManager(){return this.authManager}static resetInstance(){P.instance=null}}var m=P.getInstance;var{preflight:ci,corsify:mi}=x({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400});function e(i,f){let l=Ei(i,f);return{entry:[i.method.toUpperCase(),RegExp(`^${i.path.replace(/\/+(\/|$)/g,"$1").replace(/(\/?\.?):(\w+)\+/g,"($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g,"($1(?<$2>[^$1/]+?))").replace(/\./g,"\\.").replace(/(\/?)\*/g,"($1.*)?")}/*$`),[l],i.path],options:i,handler:f}}function ii(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}var fi={success:(i,f)=>a(C.OK,i,f),created:(i,f)=>a(C.CREATED,i,f)};function L(i,f,l){let E={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return a(i,E,l)}var b={badRequest:(i="Bad Request",f)=>L(C.BAD_REQUEST,i,f),unauthorized:(i="Unauthorized",f)=>L(C.UNAUTHORIZED,i,f),paymentRequired:(i="Payment Required",f)=>L(402,i,f),forbidden:(i="Forbidden",f)=>L(C.FORBIDDEN,i,f),notFound:(i="Not Found",f)=>L(C.NOT_FOUND,i,f),methodNotAllowed:(i="Method Not Allowed",f)=>L(405,i,f),notAcceptable:(i="Not Acceptable",f)=>L(406,i,f),requestTimeout:(i="Request Timeout",f)=>L(408,i,f),conflict:(i="Conflict",f)=>L(C.CONFLICT,i,f),gone:(i="Gone",f)=>L(410,i,f),lengthRequired:(i="Length Required",f)=>L(411,i,f),preconditionFailed:(i="Precondition Failed",f)=>L(412,i,f),payloadTooLarge:(i="Payload Too Large",f)=>L(413,i,f),uriTooLong:(i="URI Too Long",f)=>L(414,i,f),unsupportedMediaType:(i="Unsupported Media Type",f)=>L(415,i,f),rangeNotSatisfiable:(i="Range Not Satisfiable",f)=>L(416,i,f),expectationFailed:(i="Expectation Failed",f)=>L(417,i,f),imATeapot:(i="I'm a teapot",f)=>L(418,i,f),misdirectedRequest:(i="Misdirected Request",f)=>L(421,i,f),unprocessableEntity:(i="Unprocessable Entity",f)=>L(C.UNPROCESSABLE_ENTITY,i,f),locked:(i="Locked",f)=>L(423,i,f),failedDependency:(i="Failed Dependency",f)=>L(424,i,f),tooEarly:(i="Too Early",f)=>L(425,i,f),upgradeRequired:(i="Upgrade Required",f)=>L(426,i,f),preconditionRequired:(i="Precondition Required",f)=>L(428,i,f),tooManyRequests:(i="Too Many Requests",f)=>L(429,i,f),requestHeaderFieldsTooLarge:(i="Request Header Fields Too Large",f)=>L(431,i,f),unavailableForLegalReasons:(i="Unavailable For Legal Reasons",f)=>L(451,i,f),internalServerError:(i="Internal Server Error",f)=>L(C.INTERNAL_SERVER_ERROR,i,f),notImplemented:(i="Not Implemented",f)=>L(501,i,f),badGateway:(i="Bad Gateway",f)=>L(502,i,f),serviceUnavailable:(i="Service Unavailable",f)=>L(503,i,f),gatewayTimeout:(i="Gateway Timeout",f)=>L(504,i,f),httpVersionNotSupported:(i="HTTP Version Not Supported",f)=>L(505,i,f),variantAlsoNegotiates:(i="Variant Also Negotiates",f)=>L(506,i,f),insufficientStorage:(i="Insufficient Storage",f)=>L(507,i,f),loopDetected:(i="Loop Detected",f)=>L(508,i,f),notExtended:(i="Not Extended",f)=>L(510,i,f),networkAuthenticationRequired:(i="Network Authentication Required",f)=>L(511,i,f),invalidArgument:(i="Invalid Argument",f)=>L(C.UNPROCESSABLE_ENTITY,i,f),rateLimitExceeded:(i="Rate Limit Exceeded",f)=>L(429,i,f),maintenance:(i="Service Under Maintenance",f)=>L(503,i,f),custom:(i,f,l)=>L(i,f,l)};function a(i,f,l=H.JSON){let E=l===H.JSON?ii(f):f;return new Response(E,{status:i,headers:{"content-type":l}})}var li=async(i,f)=>{let E=m().getProtectedHandler();if(!E)throw b.unauthorized("Authentication not configured",f);try{let _=await E(i);i.authUser=_}catch(_){throw b.unauthorized(_ instanceof Error?_.message:"Authentication failed",f)}};function Ei(i,f){let{auth:l=!1,expose:E=!1,rawRequest:_=!1,rawResponse:A=!1,responseContentType:N=H.JSON}=i;return async(O)=>{if(!E)return b.forbidden("Forbidden");try{if(l)await li(O,N);if(!_)await K(O);let U=await f(O);return A?U:fi.success(U,N)}catch(U){if(U instanceof Response)return U;return b.internalServerError(String(U),N)}}}export{e as route,a as createResponse,b as APIError};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/middleware/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,qBAAa,iBAAiB,CAC5B,MAAM,SAAS,WAAW,GAAG,kBAAkB;IAE/C,OAAO,CAAC,cAAc,CAAyC;IAC/D,OAAO,CAAC,eAAe,CAAwC;IAE/D,SAAS,CAAC,GAAG,QAAQ,EAAE,uBAAuB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI;IAI/D,UAAU,CAAC,GAAG,QAAQ,EAAE,sBAAsB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI;IAIzD,aAAa,CACjB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAC7B,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC;IAgBtC,cAAc,CAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAC7B,OAAO,CAAC,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/middleware/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,qBAAa,iBAAiB,CAC5B,MAAM,SAAS,WAAW,GAAG,kBAAkB;IAE/C,OAAO,CAAC,cAAc,CAAyC;IAC/D,OAAO,CAAC,eAAe,CAAwC;IAE/D,SAAS,CAAC,GAAG,QAAQ,EAAE,uBAAuB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI;IAI/D,UAAU,CAAC,GAAG,QAAQ,EAAE,sBAAsB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI;IAIzD,aAAa,CACjB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAC7B,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC;IAgBtC,cAAc,CAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAC7B,OAAO,CAAC,QAAQ,CAAC;IAgBpB,KAAK,IAAI,iBAAiB,CAAC,MAAM,CAAC;IAOlC,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -21,7 +21,14 @@ export class MiddlewareManager {
|
|
|
21
21
|
async executeFinally(response, request) {
|
|
22
22
|
let currentResponse = response;
|
|
23
23
|
for (const handler of this.finallyHandlers) {
|
|
24
|
-
|
|
24
|
+
try {
|
|
25
|
+
currentResponse = await handler(currentResponse, request);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
// Log but don't throw - we don't want to break the response chain
|
|
29
|
+
console.error('After middleware error:', error);
|
|
30
|
+
// Continue with the current response
|
|
31
|
+
}
|
|
25
32
|
}
|
|
26
33
|
return currentResponse;
|
|
27
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/middleware/manager.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,iBAAiB;IAGpB,cAAc,GAAsC,EAAE,CAAC;IACvD,eAAe,GAAqC,EAAE,CAAC;IAE/D,SAAS,CAAC,GAAG,QAA2C;QACtD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,UAAU,CAAC,GAAG,QAA0C;QACtD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,OAA8B;QAE9B,IAAI,cAAc,GAAG,OAAO,CAAC;QAE7B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,cAAc,EAAE,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OAA8B;QAE9B,IAAI,eAAe,GAAG,QAAQ,CAAC;QAE/B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACH,eAAe,GAAG,MAAM,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,kEAAkE;gBAClE,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;gBAChD,qCAAqC;YACvC,CAAC;QACH,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,KAAK;QACH,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAU,CAAC;QAChD,OAAO,CAAC,cAAc,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;QAClD,OAAO,CAAC,eAAe,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export interface VectorConfig<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
61
61
|
before?: BeforeMiddlewareHandler<TTypes>[];
|
|
62
62
|
finally?: AfterMiddlewareHandler<TTypes>[];
|
|
63
63
|
routesDir?: string;
|
|
64
|
+
routeExcludePatterns?: string[];
|
|
64
65
|
autoDiscover?: boolean;
|
|
65
66
|
idleTimeout?: number;
|
|
66
67
|
}
|
|
@@ -70,6 +71,7 @@ export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTy
|
|
|
70
71
|
reusePort?: boolean;
|
|
71
72
|
development?: boolean;
|
|
72
73
|
routesDir?: string;
|
|
74
|
+
routeExcludePatterns?: string[];
|
|
73
75
|
idleTimeout?: number;
|
|
74
76
|
before?: BeforeMiddlewareHandler<TTypes>[];
|
|
75
77
|
after?: AfterMiddlewareHandler<TTypes>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAID,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAGD,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAGD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,SAAS,GACxE,eAAe,GACf,CAAC,CAAC,MAAM,CAAC,CAAC;AAEd,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,SAAS,GAC9E,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACnB,CAAC,CAAC,SAAS,CAAC,CAAC;AAEjB,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,C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 -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vector-framework",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"author": "",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "webhie-com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/webhie-com/vector.git"
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"dev": "bun run src/cli/index.ts dev",
|
|
77
77
|
"start": "bun run src/cli/index.ts start",
|
|
78
78
|
"build": "bun run src/cli/index.ts build",
|
|
79
|
+
"build:app": "bun run src/cli/index.ts build",
|
|
79
80
|
"build:lib": "bun run build:clean && bun run build:ts && bun run build:bundle && bun run build:cli",
|
|
80
81
|
"build:clean": "rm -rf dist",
|
|
81
82
|
"build:ts": "tsc",
|