vector-framework 0.9.5 → 0.9.6
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 +2 -0
- package/dist/cli/index.js +6 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli.js +12 -4
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +9 -4
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/server.d.ts +3 -3
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +17 -16
- package/dist/core/server.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/index.ts +6 -1
- package/src/core/config-loader.ts +10 -4
- package/src/core/server.ts +28 -20
- package/src/types/index.ts +6 -4
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ const config: VectorConfigSchema = {
|
|
|
27
27
|
routesDir: "./routes", // Routes directory (default: ./routes)
|
|
28
28
|
development: process.env.NODE_ENV !== "production", // Development mode
|
|
29
29
|
reusePort: true, // Reuse port (default: true)
|
|
30
|
+
idleTimeout: 60, // Idle timeout in seconds (default: 60)
|
|
30
31
|
|
|
31
32
|
// CORS configuration
|
|
32
33
|
cors: {
|
|
@@ -338,6 +339,7 @@ interface VectorConfig {
|
|
|
338
339
|
development?: boolean; // Development mode
|
|
339
340
|
routesDir?: string; // Routes directory (default: ./routes)
|
|
340
341
|
autoDiscover?: boolean; // Auto-discover routes (default: true)
|
|
342
|
+
idleTimeout?: number; // Idle timeout in seconds (default: 60)
|
|
341
343
|
cors?: CorsOptions; // CORS configuration
|
|
342
344
|
before?: BeforeMiddlewareHandler[]; // Pre-request middleware
|
|
343
345
|
finally?: AfterMiddlewareHandler[]; // Post-response middleware
|
package/dist/cli/index.js
CHANGED
|
@@ -32,6 +32,10 @@ const { values, positionals } = parseArgs({
|
|
|
32
32
|
type: "boolean",
|
|
33
33
|
default: true,
|
|
34
34
|
},
|
|
35
|
+
config: {
|
|
36
|
+
type: "string",
|
|
37
|
+
short: "c",
|
|
38
|
+
},
|
|
35
39
|
},
|
|
36
40
|
strict: true,
|
|
37
41
|
allowPositionals: true,
|
|
@@ -45,7 +49,7 @@ async function runDev() {
|
|
|
45
49
|
async function startServer() {
|
|
46
50
|
try {
|
|
47
51
|
// Load configuration using ConfigLoader
|
|
48
|
-
const configLoader = new ConfigLoader();
|
|
52
|
+
const configLoader = new ConfigLoader(values.config);
|
|
49
53
|
const config = await configLoader.load();
|
|
50
54
|
const configSource = configLoader.getConfigSource();
|
|
51
55
|
// Merge CLI options with loaded config
|
|
@@ -244,6 +248,7 @@ Options:
|
|
|
244
248
|
-h, --host <host> Hostname to bind to (default: localhost)
|
|
245
249
|
-r, --routes <dir> Routes directory (default: ./routes)
|
|
246
250
|
-w, --watch Watch for file changes (default: true)
|
|
251
|
+
-c, --config <path> Path to config file (default: vector.config.ts)
|
|
247
252
|
--cors Enable CORS (default: true)
|
|
248
253
|
`);
|
|
249
254
|
process.exit(1);
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,4CAA4C;AAC5C,MAAM,IAAI,GACR,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzE,MAAM,EAAE,MAAM,EAAE,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AAG,CAAC,KAAK,CAAC;gBAC7B,KAAK;gBACL,OAAO;gBACP,cAAc;gBACd,UAAU;gBACV,MAAM;gBACN,UAAU;aACX,CAAC,CAAC;YACH,MAAM,YAAY,CAAC,MAAM,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,iCAAiC;YACjC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;YACpD,SAAS,CACP,KAAK,EACL,CAAC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EACzD;gBACE,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,IAAI;aACZ,CACF,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,QAAQ,OAAO,EAAE,CAAC;IAChB,KAAK,KAAK;QACR,MAAM,MAAM,EAAE,CAAC;QACf,MAAM;IACR,KAAK,OAAO;QACV,MAAM,QAAQ,EAAE,CAAC;QACjB,MAAM;IACR,KAAK,OAAO;QACV,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC;QACpC,MAAM,MAAM,EAAE,CAAC;QACf,MAAM;IACR;QACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;CAef,CAAC,CAAC;QACC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -804,6 +804,7 @@ class VectorServer {
|
|
|
804
804
|
hostname,
|
|
805
805
|
reusePort: this.config.reusePort !== false,
|
|
806
806
|
fetch,
|
|
807
|
+
idleTimeout: this.config.idleTimeout || 60,
|
|
807
808
|
error: (error) => {
|
|
808
809
|
console.error("[ERROR] Server error:", error);
|
|
809
810
|
return new Response("Internal Server Error", { status: 500 });
|
|
@@ -1002,14 +1003,15 @@ import { parseArgs } from "util";
|
|
|
1002
1003
|
|
|
1003
1004
|
// src/core/config-loader.ts
|
|
1004
1005
|
import { existsSync as existsSync2 } from "fs";
|
|
1005
|
-
import { resolve as resolve2 } from "path";
|
|
1006
|
+
import { resolve as resolve2, isAbsolute } from "path";
|
|
1006
1007
|
|
|
1007
1008
|
class ConfigLoader {
|
|
1008
1009
|
configPath;
|
|
1009
1010
|
config = null;
|
|
1010
1011
|
configSource = "default";
|
|
1011
|
-
constructor(configPath
|
|
1012
|
-
|
|
1012
|
+
constructor(configPath) {
|
|
1013
|
+
const path = configPath || "vector.config.ts";
|
|
1014
|
+
this.configPath = isAbsolute(path) ? path : resolve2(process.cwd(), path);
|
|
1013
1015
|
}
|
|
1014
1016
|
async load() {
|
|
1015
1017
|
if (existsSync2(this.configPath)) {
|
|
@@ -1043,6 +1045,7 @@ class ConfigLoader {
|
|
|
1043
1045
|
config.reusePort = this.config.reusePort;
|
|
1044
1046
|
config.development = this.config.development;
|
|
1045
1047
|
config.routesDir = this.config.routesDir || "./routes";
|
|
1048
|
+
config.idleTimeout = this.config.idleTimeout;
|
|
1046
1049
|
}
|
|
1047
1050
|
config.autoDiscover = true;
|
|
1048
1051
|
if (this.config?.cors) {
|
|
@@ -1106,6 +1109,10 @@ var { values, positionals } = parseArgs({
|
|
|
1106
1109
|
cors: {
|
|
1107
1110
|
type: "boolean",
|
|
1108
1111
|
default: true
|
|
1112
|
+
},
|
|
1113
|
+
config: {
|
|
1114
|
+
type: "string",
|
|
1115
|
+
short: "c"
|
|
1109
1116
|
}
|
|
1110
1117
|
},
|
|
1111
1118
|
strict: true,
|
|
@@ -1121,7 +1128,7 @@ async function runDev() {
|
|
|
1121
1128
|
let vector = null;
|
|
1122
1129
|
async function startServer() {
|
|
1123
1130
|
try {
|
|
1124
|
-
const configLoader = new ConfigLoader;
|
|
1131
|
+
const configLoader = new ConfigLoader(values.config);
|
|
1125
1132
|
const config = await configLoader.load();
|
|
1126
1133
|
const configSource = configLoader.getConfigSource();
|
|
1127
1134
|
config.port = config.port ?? Number.parseInt(values.port);
|
|
@@ -1288,6 +1295,7 @@ Options:
|
|
|
1288
1295
|
-h, --host <host> Hostname to bind to (default: localhost)
|
|
1289
1296
|
-r, --routes <dir> Routes directory (default: ./routes)
|
|
1290
1297
|
-w, --watch Watch for file changes (default: true)
|
|
1298
|
+
-c, --config <path> Path to config file (default: vector.config.ts)
|
|
1291
1299
|
--cors Enable CORS (default: true)
|
|
1292
1300
|
`);
|
|
1293
1301
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/core/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EAEZ,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,qBAAa,YAAY,CAAC,MAAM,SAAS,WAAW,GAAG,kBAAkB;IACvE,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAA2C;IACzD,OAAO,CAAC,YAAY,CAAiC;gBAEzC,UAAU,
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/core/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EAEZ,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,qBAAa,YAAY,CAAC,MAAM,SAAS,WAAW,GAAG,kBAAkB;IACvE,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAA2C;IACzD,OAAO,CAAC,YAAY,CAAiC;gBAEzC,UAAU,CAAC,EAAE,MAAM;IAUzB,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAgC3C,eAAe,IAAI,MAAM,GAAG,SAAS;YAIvB,iBAAiB;IA8CzB,eAAe,IAAI,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAI3D,gBAAgB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAItD,SAAS,IAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG,IAAI;CAG/C"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
2
|
+
import { resolve, isAbsolute } from "node:path";
|
|
3
3
|
import { toFileUrl } from "../utils/path";
|
|
4
4
|
export class ConfigLoader {
|
|
5
5
|
configPath;
|
|
6
6
|
config = null;
|
|
7
7
|
configSource = "default";
|
|
8
|
-
constructor(configPath
|
|
9
|
-
//
|
|
10
|
-
|
|
8
|
+
constructor(configPath) {
|
|
9
|
+
// Use provided config path or default to vector.config.ts
|
|
10
|
+
const path = configPath || "vector.config.ts";
|
|
11
|
+
// Handle absolute vs relative paths
|
|
12
|
+
this.configPath = isAbsolute(path)
|
|
13
|
+
? path
|
|
14
|
+
: resolve(process.cwd(), path);
|
|
11
15
|
}
|
|
12
16
|
async load() {
|
|
13
17
|
// Check if config file exists before attempting to load
|
|
@@ -48,6 +52,7 @@ export class ConfigLoader {
|
|
|
48
52
|
config.reusePort = this.config.reusePort;
|
|
49
53
|
config.development = this.config.development;
|
|
50
54
|
config.routesDir = this.config.routesDir || "./routes";
|
|
55
|
+
config.idleTimeout = this.config.idleTimeout;
|
|
51
56
|
}
|
|
52
57
|
// Always auto-discover routes
|
|
53
58
|
config.autoDiscover = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/core/config-loader.ts"],"names":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AI,EAAE,CAAC;YACtB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC1C,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI;oBAC5B,CAAC,CAAC;wBACE,MAAM,EAAE,GAAG;wBACX,WAAW,EAAE,IAAI;wBACjB,YAAY,EAAE,6BAA6B;wBAC3C,YAAY,EAAE,wCAAwC;wBACtD,aAAa,EAAE,eAAe;wBAC9B,MAAM,EAAE,KAAK;qBACd;oBACH,CAAC,CAAC,SAAS,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAmB,CAAC;YAChD,CAAC;QACH,CAAC;QAED,sEAAsE;QACtE,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;YACxB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACrC,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;YACvB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACrC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC;IACpC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|
package/dist/core/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Server } from
|
|
2
|
-
import type { DefaultVectorTypes, VectorConfig, VectorTypes } from
|
|
3
|
-
import type { VectorRouter } from
|
|
1
|
+
import type { Server } from "bun";
|
|
2
|
+
import type { DefaultVectorTypes, VectorConfig, VectorTypes } from "../types";
|
|
3
|
+
import type { VectorRouter } from "./router";
|
|
4
4
|
export declare class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
5
5
|
private server;
|
|
6
6
|
private router;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,KAAK,EAEV,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,qBAAa,YAAY,CAAC,MAAM,SAAS,WAAW,GAAG,kBAAkB;IACvE,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,WAAW,CAAM;gBAEb,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC;IAYtE,OAAO,CAAC,oBAAoB;IAiBtB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IA4C9B,IAAI;IAQJ,SAAS,IAAI,MAAM,GAAG,IAAI;IAI1B,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,MAAM;IAIrB,MAAM,IAAI,MAAM;CAKjB"}
|
package/dist/core/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cors } from
|
|
1
|
+
import { cors } from "itty-router";
|
|
2
2
|
export class VectorServer {
|
|
3
3
|
server = null;
|
|
4
4
|
router;
|
|
@@ -14,27 +14,27 @@ export class VectorServer {
|
|
|
14
14
|
}
|
|
15
15
|
normalizeCorsOptions(options) {
|
|
16
16
|
return {
|
|
17
|
-
origin: options.origin ||
|
|
17
|
+
origin: options.origin || "*",
|
|
18
18
|
credentials: options.credentials !== false,
|
|
19
19
|
allowHeaders: Array.isArray(options.allowHeaders)
|
|
20
|
-
? options.allowHeaders.join(
|
|
21
|
-
: options.allowHeaders ||
|
|
20
|
+
? options.allowHeaders.join(", ")
|
|
21
|
+
: options.allowHeaders || "Content-Type, Authorization",
|
|
22
22
|
allowMethods: Array.isArray(options.allowMethods)
|
|
23
|
-
? options.allowMethods.join(
|
|
24
|
-
: options.allowMethods ||
|
|
23
|
+
? options.allowMethods.join(", ")
|
|
24
|
+
: options.allowMethods || "GET, POST, PUT, PATCH, DELETE, OPTIONS",
|
|
25
25
|
exposeHeaders: Array.isArray(options.exposeHeaders)
|
|
26
|
-
? options.exposeHeaders.join(
|
|
27
|
-
: options.exposeHeaders ||
|
|
26
|
+
? options.exposeHeaders.join(", ")
|
|
27
|
+
: options.exposeHeaders || "Authorization",
|
|
28
28
|
maxAge: options.maxAge || 86400,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
async start() {
|
|
32
32
|
const port = this.config.port || 3000;
|
|
33
|
-
const hostname = this.config.hostname ||
|
|
33
|
+
const hostname = this.config.hostname || "localhost";
|
|
34
34
|
const fetch = async (request) => {
|
|
35
35
|
try {
|
|
36
36
|
// Handle CORS preflight
|
|
37
|
-
if (this.corsHandler && request.method ===
|
|
37
|
+
if (this.corsHandler && request.method === "OPTIONS") {
|
|
38
38
|
return this.corsHandler.preflight(request);
|
|
39
39
|
}
|
|
40
40
|
// Try to handle the request with our router
|
|
@@ -46,8 +46,8 @@ export class VectorServer {
|
|
|
46
46
|
return response;
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
|
-
console.error(
|
|
50
|
-
return new Response(
|
|
49
|
+
console.error("Server error:", error);
|
|
50
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
this.server = Bun.serve({
|
|
@@ -55,9 +55,10 @@ export class VectorServer {
|
|
|
55
55
|
hostname,
|
|
56
56
|
reusePort: this.config.reusePort !== false,
|
|
57
57
|
fetch,
|
|
58
|
+
idleTimeout: this.config.idleTimeout || 60,
|
|
58
59
|
error: (error) => {
|
|
59
|
-
console.error(
|
|
60
|
-
return new Response(
|
|
60
|
+
console.error("[ERROR] Server error:", error);
|
|
61
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
61
62
|
},
|
|
62
63
|
});
|
|
63
64
|
// Server logs are handled by CLI, keep this minimal
|
|
@@ -68,7 +69,7 @@ export class VectorServer {
|
|
|
68
69
|
if (this.server) {
|
|
69
70
|
this.server.stop();
|
|
70
71
|
this.server = null;
|
|
71
|
-
console.log(
|
|
72
|
+
console.log("Server stopped");
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
getServer() {
|
|
@@ -78,7 +79,7 @@ export class VectorServer {
|
|
|
78
79
|
return this.server?.port || this.config.port || 3000;
|
|
79
80
|
}
|
|
80
81
|
getHostname() {
|
|
81
|
-
return this.server?.hostname || this.config.hostname ||
|
|
82
|
+
return this.server?.hostname || this.config.hostname || "localhost";
|
|
82
83
|
}
|
|
83
84
|
getUrl() {
|
|
84
85
|
const port = this.getPort();
|
package/dist/core/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AASnC,MAAM,OAAO,YAAY;IACf,MAAM,GAAkB,IAAI,CAAC;IAC7B,MAAM,CAAuB;IAC7B,MAAM,CAA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AM,EAAE,GAAG,EAAE,CAAC,CAAC;YAChE,CAAC;SACF,CAAC,CAAC;QAEH,oDAAoD;QACpD,OAAO,CAAC,GAAG,CAAC,qCAAqC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,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;YACnB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC;IACvD,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,WAAW,CAAC;IACtE,CAAC;IAED,MAAM;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,UAAU,QAAQ,IAAI,IAAI,EAAE,CAAC;IACtC,CAAC;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -18,4 +18,4 @@ export default routes;
|
|
|
18
18
|
${f.join(`,
|
|
19
19
|
`)}
|
|
20
20
|
]);
|
|
21
|
-
};`}}var v;var p=$(()=>{v=(()=>({}));Z()});class k{routesDir;constructor(i="./routes"){this.routesDir=x(process.cwd(),i)}async scan(){let i=[];if(!F.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 F.promises.readdir(i);for(let A of a){let E=c(i,A);if((await F.promises.stat(E)).isDirectory()){let _=l?`${l}/${A}`:A;await this.scanDirectory(E,f,_)}else if(A.endsWith(".ts")||A.endsWith(".js")){let _=G(this.routesDir,E).replace(/\.(ts|js)$/,"").split(K).join("/");try{let w=await import(process.platform==="win32"?`file:///${E.replace(/\\/g,"/")}`:E);if(w.default&&typeof w.default==="function")f.push({name:"default",path:E,method:"GET",options:{method:"GET",path:`/${_}`,expose:!0}});for(let[d,I]of Object.entries(w)){if(d==="default")continue;if(I&&typeof I==="object"&&"entry"in I&&"options"in I&&"handler"in I){let L=I;f.push({name:d,path:E,method:L.options.method,options:L.options})}else if(Array.isArray(I)&&I.length>=4){let[L,,,P]=I;f.push({name:d,path:E,method:L,options:{method:L,path:P,expose:!0}})}}}catch(N){console.error(`Failed to load route from ${E}:`,N)}}}}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)}}var F;var e=$(()=>{F=(()=>({}));Z()});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 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 B;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function ii(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 E=0,O=i.split("/").filter(Boolean);for(let _ of O)if(this.isStaticSegment(_))E+=1000;else if(this.isParamSegment(_))E+=10;else if(this.isWildcardSegment(_))E+=1;if(E+=i.length,this.isExactPath(i))E+=1e4;return E}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),A=this.getRouteSpecificity(l);return this.getRouteSpecificity(a)-A})}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.*)?")}/*$`)}wrapHandler(i,f){return async(l)=>{let a=l;if(!a.context)a.context={};if(!a.query&&a.url){let A=new URL(a.url),E={};for(let[O,_]of A.searchParams)E[O]=E[O]?[].concat(E[O],_):_;a.query=E}if(i.metadata)a.metadata=i.metadata;l=a;try{if(i.expose===!1)return U.forbidden("Forbidden");let A=await this.middlewareManager.executeBefore(l);if(A instanceof Response)return A;if(l=A,i.auth)try{await this.authManager.authenticate(l)}catch(N){return U.unauthorized(N instanceof Error?N.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let N=l.headers.get("content-type");if(N?.includes("application/json"))l.content=await l.json();else if(N?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(N?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let E,O=i.cache;if(O&&typeof O==="number"&&O>0){let N=this.cacheManager.generateKey(l,{authUser:l.authUser});E=await this.cacheManager.get(N,()=>f(l),O)}else if(O&&typeof O==="object"&&O.ttl){let N=O.key||this.cacheManager.generateKey(l,{authUser:l.authUser});E=await this.cacheManager.get(N,()=>f(l),O.ttl)}else E=await f(l);let _;if(i.rawResponse||E instanceof Response)_=E instanceof Response?E:new Response(E);else _=H(200,E,i.responseContentType);return _=await this.middlewareManager.executeFinally(_,l),_}catch(A){if(A instanceof Response)return A;return console.error("Route handler error:",A),U.internalServerError(A instanceof Error?A.message:String(A),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,A,E]of this.routes)if(i.method==="OPTIONS"||i.method===a){let O=l.match(A);if(O){let _=i;if(!_.context)_.context={};_.params=O.groups||{};for(let N of E){let w=await N(_);if(w)return w}}}return U.notFound("Route not found")}clearRoutes(){this.routes=[]}}var fi=$(()=>{Y()});class u{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:a}=j(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 A=await this.router.handle(a);if(this.corsHandler)A=this.corsHandler.corsify(A,a);return A}catch(A){return console.error("Server error:",A),new Response("Internal Server Error",{status:500})}};return this.server=Bun.serve({port:i,hostname:f,reusePort:this.config.reusePort!==!1,fetch:l,error:(a)=>{return console.error("[ERROR] Server error:",a),new Response("Internal Server Error",{status:500})}}),console.log(`→ Vector server running at http://${f}:${i}`),this.server}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}`}}var li=$(()=>{V()});var ai={};n(ai,{getVectorInstance:()=>Pi,Vector:()=>h});class h{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 W,this.cacheManager=new z,this.router=new m(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 u(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes";if(this.routeScanner=new k(i),!this.routeGenerator)this.routeGenerator=new g;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 A=await import(ii(l.path)),E=l.name==="default"?A.default:A[l.name];if(E){if(this.isRouteDefinition(E)){let O=E;this.router.route(O.options,O.handler),this.logRouteLoaded(O.options)}else if(this.isRouteEntry(E))this.router.addRoute(E),this.logRouteLoaded(E);else if(typeof E==="function")this.router.route(l.options,E),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 Pi;var Ei=$(()=>{q();p();e();fi();li();Pi=h.getInstance});function Ai(i,f){let l=Si(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 hi(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}function D(i,f,l){let a={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return H(i,a,l)}function H(i,f,l=M.JSON){let a=l===M.JSON?hi(f):f;return new Response(a,{status:i,headers:{"content-type":l}})}function Si(i,f){let{auth:l=!1,expose:a=!1,rawRequest:A=!1,rawResponse:E=!1,responseContentType:O=M.JSON}=i;return async(_)=>{if(!a)return U.forbidden("Forbidden");try{if(l)await bi(_,O);if(!A)await s(_);y(_);let N=await f(_);return E?N:Hi.success(N,O)}catch(N){if(N instanceof Response)return N;return U.internalServerError(String(N),O)}}}var Af,_f,Hi,U,bi=async(i,f)=>{let{getVectorInstance:l}=await Promise.resolve().then(() => (Ei(),ai)),A=l().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)}};var Y=$(()=>{V();J();({preflight:Af,corsify:_f}=j({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400}));Hi={success:(i,f)=>H(R.OK,i,f),created:(i,f)=>H(R.CREATED,i,f)};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)}});var xi={};n(xi,{route:()=>Ai,createResponse:()=>H,APIError:()=>U});module.exports=Ni(xi);Y();Y();
|
|
21
|
+
};`}}var v;var p=$(()=>{v=(()=>({}));Z()});class k{routesDir;constructor(i="./routes"){this.routesDir=x(process.cwd(),i)}async scan(){let i=[];if(!F.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 F.promises.readdir(i);for(let A of a){let E=c(i,A);if((await F.promises.stat(E)).isDirectory()){let _=l?`${l}/${A}`:A;await this.scanDirectory(E,f,_)}else if(A.endsWith(".ts")||A.endsWith(".js")){let _=G(this.routesDir,E).replace(/\.(ts|js)$/,"").split(K).join("/");try{let w=await import(process.platform==="win32"?`file:///${E.replace(/\\/g,"/")}`:E);if(w.default&&typeof w.default==="function")f.push({name:"default",path:E,method:"GET",options:{method:"GET",path:`/${_}`,expose:!0}});for(let[d,I]of Object.entries(w)){if(d==="default")continue;if(I&&typeof I==="object"&&"entry"in I&&"options"in I&&"handler"in I){let L=I;f.push({name:d,path:E,method:L.options.method,options:L.options})}else if(Array.isArray(I)&&I.length>=4){let[L,,,P]=I;f.push({name:d,path:E,method:L,options:{method:L,path:P,expose:!0}})}}}catch(N){console.error(`Failed to load route from ${E}:`,N)}}}}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)}}var F;var e=$(()=>{F=(()=>({}));Z()});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 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 B;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function ii(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 E=0,O=i.split("/").filter(Boolean);for(let _ of O)if(this.isStaticSegment(_))E+=1000;else if(this.isParamSegment(_))E+=10;else if(this.isWildcardSegment(_))E+=1;if(E+=i.length,this.isExactPath(i))E+=1e4;return E}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),A=this.getRouteSpecificity(l);return this.getRouteSpecificity(a)-A})}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.*)?")}/*$`)}wrapHandler(i,f){return async(l)=>{let a=l;if(!a.context)a.context={};if(!a.query&&a.url){let A=new URL(a.url),E={};for(let[O,_]of A.searchParams)E[O]=E[O]?[].concat(E[O],_):_;a.query=E}if(i.metadata)a.metadata=i.metadata;l=a;try{if(i.expose===!1)return U.forbidden("Forbidden");let A=await this.middlewareManager.executeBefore(l);if(A instanceof Response)return A;if(l=A,i.auth)try{await this.authManager.authenticate(l)}catch(N){return U.unauthorized(N instanceof Error?N.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let N=l.headers.get("content-type");if(N?.includes("application/json"))l.content=await l.json();else if(N?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(N?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let E,O=i.cache;if(O&&typeof O==="number"&&O>0){let N=this.cacheManager.generateKey(l,{authUser:l.authUser});E=await this.cacheManager.get(N,()=>f(l),O)}else if(O&&typeof O==="object"&&O.ttl){let N=O.key||this.cacheManager.generateKey(l,{authUser:l.authUser});E=await this.cacheManager.get(N,()=>f(l),O.ttl)}else E=await f(l);let _;if(i.rawResponse||E instanceof Response)_=E instanceof Response?E:new Response(E);else _=H(200,E,i.responseContentType);return _=await this.middlewareManager.executeFinally(_,l),_}catch(A){if(A instanceof Response)return A;return console.error("Route handler error:",A),U.internalServerError(A instanceof Error?A.message:String(A),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,A,E]of this.routes)if(i.method==="OPTIONS"||i.method===a){let O=l.match(A);if(O){let _=i;if(!_.context)_.context={};_.params=O.groups||{};for(let N of E){let w=await N(_);if(w)return w}}}return U.notFound("Route not found")}clearRoutes(){this.routes=[]}}var fi=$(()=>{Y()});class u{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:a}=j(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 A=await this.router.handle(a);if(this.corsHandler)A=this.corsHandler.corsify(A,a);return A}catch(A){return console.error("Server error:",A),new Response("Internal Server Error",{status:500})}};return 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})}}),console.log(`→ Vector server running at http://${f}:${i}`),this.server}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}`}}var li=$(()=>{V()});var ai={};n(ai,{getVectorInstance:()=>Pi,Vector:()=>h});class h{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 W,this.cacheManager=new z,this.router=new m(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 u(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes";if(this.routeScanner=new k(i),!this.routeGenerator)this.routeGenerator=new g;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 A=await import(ii(l.path)),E=l.name==="default"?A.default:A[l.name];if(E){if(this.isRouteDefinition(E)){let O=E;this.router.route(O.options,O.handler),this.logRouteLoaded(O.options)}else if(this.isRouteEntry(E))this.router.addRoute(E),this.logRouteLoaded(E);else if(typeof E==="function")this.router.route(l.options,E),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 Pi;var Ei=$(()=>{q();p();e();fi();li();Pi=h.getInstance});function Ai(i,f){let l=Si(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 hi(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}function D(i,f,l){let a={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return H(i,a,l)}function H(i,f,l=M.JSON){let a=l===M.JSON?hi(f):f;return new Response(a,{status:i,headers:{"content-type":l}})}function Si(i,f){let{auth:l=!1,expose:a=!1,rawRequest:A=!1,rawResponse:E=!1,responseContentType:O=M.JSON}=i;return async(_)=>{if(!a)return U.forbidden("Forbidden");try{if(l)await bi(_,O);if(!A)await s(_);y(_);let N=await f(_);return E?N:Hi.success(N,O)}catch(N){if(N instanceof Response)return N;return U.internalServerError(String(N),O)}}}var Af,_f,Hi,U,bi=async(i,f)=>{let{getVectorInstance:l}=await Promise.resolve().then(() => (Ei(),ai)),A=l().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)}};var Y=$(()=>{V();J();({preflight:Af,corsify:_f}=j({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400}));Hi={success:(i,f)=>H(R.OK,i,f),created:(i,f)=>H(R.CREATED,i,f)};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)}});var xi={};n(xi,{route:()=>Ai,createResponse:()=>H,APIError:()=>U});module.exports=Ni(xi);Y();Y();
|
package/dist/index.mjs
CHANGED
|
@@ -18,4 +18,4 @@ export default routes;
|
|
|
18
18
|
${f.join(`,
|
|
19
19
|
`)}
|
|
20
20
|
]);
|
|
21
|
-
};`}}var y=U(()=>{c()});var{existsSync:Ii,promises:q}=(()=>({}));class Z{routesDir;constructor(i="./routes"){this.routesDir=x(process.cwd(),i)}async scan(){let i=[];if(!Ii(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 E=await q.readdir(i);for(let A of E){let a=W(i,A);if((await q.stat(a)).isDirectory()){let _=l?`${l}/${A}`:A;await this.scanDirectory(a,f,_)}else if(A.endsWith(".ts")||A.endsWith(".js")){let _=G(this.routesDir,a).replace(/\.(ts|js)$/,"").split(z).join("/");try{let w=await import(process.platform==="win32"?`file:///${a.replace(/\\/g,"/")}`:a);if(w.default&&typeof w.default==="function")f.push({name:"default",path:a,method:"GET",options:{method:"GET",path:`/${_}`,expose:!0}});for(let[d,I]of Object.entries(w)){if(d==="default")continue;if(I&&typeof I==="object"&&"entry"in I&&"options"in I&&"handler"in I){let L=I;f.push({name:d,path:a,method:L.options.method,options:L.options})}else if(Array.isArray(I)&&I.length>=4){let[L,,,P]=I;f.push({name:d,path:a,method:L,options:{method:L,path:P,expose:!0}})}}}catch(N){console.error(`Failed to load route from ${a}:`,N)}}}}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)}}var t=U(()=>{c()});class T{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)l=await E(l,f);return l}clone(){let i=new T;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function o(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,O=i.split("/").filter(Boolean);for(let _ of O)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),E=this.extractPath(f),A=this.getRouteSpecificity(l);return this.getRouteSpecificity(E)-A})}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.*)?")}/*$`)}wrapHandler(i,f){return async(l)=>{let E=l;if(!E.context)E.context={};if(!E.query&&E.url){let A=new URL(E.url),a={};for(let[O,_]of A.searchParams)a[O]=a[O]?[].concat(a[O],_):_;E.query=a}if(i.metadata)E.metadata=i.metadata;l=E;try{if(i.expose===!1)return C.forbidden("Forbidden");let A=await this.middlewareManager.executeBefore(l);if(A instanceof Response)return A;if(l=A,i.auth)try{await this.authManager.authenticate(l)}catch(N){return C.unauthorized(N instanceof Error?N.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let N=l.headers.get("content-type");if(N?.includes("application/json"))l.content=await l.json();else if(N?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(N?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let a,O=i.cache;if(O&&typeof O==="number"&&O>0){let N=this.cacheManager.generateKey(l,{authUser:l.authUser});a=await this.cacheManager.get(N,()=>f(l),O)}else if(O&&typeof O==="object"&&O.ttl){let N=O.key||this.cacheManager.generateKey(l,{authUser:l.authUser});a=await this.cacheManager.get(N,()=>f(l),O.ttl)}else a=await f(l);let _;if(i.rawResponse||a instanceof Response)_=a instanceof Response?a:new Response(a);else _=b(200,a,i.responseContentType);return _=await this.middlewareManager.executeFinally(_,l),_}catch(A){if(A instanceof Response)return A;return console.error("Route handler error:",A),C.internalServerError(A instanceof Error?A.message:String(A),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,a]of this.routes)if(i.method==="OPTIONS"||i.method===E){let O=l.match(A);if(O){let _=i;if(!_.context)_.context={};_.params=O.groups||{};for(let N of a){let w=await N(_);if(w)return w}}}return C.notFound("Route not found")}clearRoutes(){this.routes=[]}}var p=U(()=>{B()});class g{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:E}=F(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 A=await this.router.handle(E);if(this.corsHandler)A=this.corsHandler.corsify(A,E);return A}catch(A){return console.error("Server error:",A),new Response("Internal Server Error",{status:500})}};return this.server=Bun.serve({port:i,hostname:f,reusePort:this.config.reusePort!==!1,fetch:l,error:(E)=>{return console.error("[ERROR] Server error:",E),new Response("Internal Server Error",{status:500})}}),console.log(`→ Vector server running at http://${f}:${i}`),this.server}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}`}}var e=U(()=>{Y()});var ii={};ai(ii,{getVectorInstance:()=>Li,Vector:()=>h});class h{static instance;router;server=null;middlewareManager;authManager;cacheManager;config={};routeScanner=null;routeGenerator=null;_protectedHandler=null;_cacheHandler=null;constructor(){this.middlewareManager=new T,this.authManager=new X,this.cacheManager=new J,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 g(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes";if(this.routeScanner=new Z(i),!this.routeGenerator)this.routeGenerator=new K;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 A=await import(o(l.path)),a=l.name==="default"?A.default:A[l.name];if(a){if(this.isRouteDefinition(a)){let O=a;this.router.route(O.options,O.handler),this.logRouteLoaded(O.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(E){console.error(`Failed to load route ${l.name} from ${l.path}:`,E)}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 Li;var fi=U(()=>{u();y();t();p();e();Li=h.getInstance});function Ri(i,f){let l=Pi(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 Ui(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}function D(i,f,l){let E={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return b(i,E,l)}function b(i,f,l=j.JSON){let E=l===j.JSON?Ui(f):f;return new Response(E,{status:i,headers:{"content-type":l}})}function Pi(i,f){let{auth:l=!1,expose:E=!1,rawRequest:A=!1,rawResponse:a=!1,responseContentType:O=j.JSON}=i;return async(_)=>{if(!E)return C.forbidden("Forbidden");try{if(l)await Ci(_,O);if(!A)await k(_);m(_);let N=await f(_);return a?N:$i.success(N,O)}catch(N){if(N instanceof Response)return N;return C.internalServerError(String(N),O)}}}var lf,af,$i,C,Ci=async(i,f)=>{let{getVectorInstance:l}=await Promise.resolve().then(() => (fi(),ii)),A=l().getProtectedHandler();if(!A)throw C.unauthorized("Authentication not configured",f);try{let a=await A(i);i.authUser=a}catch(a){throw C.unauthorized(a instanceof Error?a.message:"Authentication failed",f)}};var B=U(()=>{Y();V();({preflight:lf,corsify:af}=F({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400}));$i={success:(i,f)=>b(R.OK,i,f),created:(i,f)=>b(R.CREATED,i,f)};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)}});B();B();export{Ri as route,b as createResponse,C as APIError};
|
|
21
|
+
};`}}var y=U(()=>{c()});var{existsSync:Ii,promises:q}=(()=>({}));class Z{routesDir;constructor(i="./routes"){this.routesDir=x(process.cwd(),i)}async scan(){let i=[];if(!Ii(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 E=await q.readdir(i);for(let A of E){let a=W(i,A);if((await q.stat(a)).isDirectory()){let _=l?`${l}/${A}`:A;await this.scanDirectory(a,f,_)}else if(A.endsWith(".ts")||A.endsWith(".js")){let _=G(this.routesDir,a).replace(/\.(ts|js)$/,"").split(z).join("/");try{let w=await import(process.platform==="win32"?`file:///${a.replace(/\\/g,"/")}`:a);if(w.default&&typeof w.default==="function")f.push({name:"default",path:a,method:"GET",options:{method:"GET",path:`/${_}`,expose:!0}});for(let[d,I]of Object.entries(w)){if(d==="default")continue;if(I&&typeof I==="object"&&"entry"in I&&"options"in I&&"handler"in I){let L=I;f.push({name:d,path:a,method:L.options.method,options:L.options})}else if(Array.isArray(I)&&I.length>=4){let[L,,,P]=I;f.push({name:d,path:a,method:L,options:{method:L,path:P,expose:!0}})}}}catch(N){console.error(`Failed to load route from ${a}:`,N)}}}}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)}}var t=U(()=>{c()});class T{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)l=await E(l,f);return l}clone(){let i=new T;return i.beforeHandlers=[...this.beforeHandlers],i.finallyHandlers=[...this.finallyHandlers],i}clear(){this.beforeHandlers=[],this.finallyHandlers=[]}}function o(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,O=i.split("/").filter(Boolean);for(let _ of O)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),E=this.extractPath(f),A=this.getRouteSpecificity(l);return this.getRouteSpecificity(E)-A})}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.*)?")}/*$`)}wrapHandler(i,f){return async(l)=>{let E=l;if(!E.context)E.context={};if(!E.query&&E.url){let A=new URL(E.url),a={};for(let[O,_]of A.searchParams)a[O]=a[O]?[].concat(a[O],_):_;E.query=a}if(i.metadata)E.metadata=i.metadata;l=E;try{if(i.expose===!1)return C.forbidden("Forbidden");let A=await this.middlewareManager.executeBefore(l);if(A instanceof Response)return A;if(l=A,i.auth)try{await this.authManager.authenticate(l)}catch(N){return C.unauthorized(N instanceof Error?N.message:"Authentication failed",i.responseContentType)}if(!i.rawRequest&&l.method!=="GET"&&l.method!=="HEAD")try{let N=l.headers.get("content-type");if(N?.includes("application/json"))l.content=await l.json();else if(N?.includes("application/x-www-form-urlencoded"))l.content=Object.fromEntries(await l.formData());else if(N?.includes("multipart/form-data"))l.content=await l.formData();else l.content=await l.text()}catch{l.content=null}let a,O=i.cache;if(O&&typeof O==="number"&&O>0){let N=this.cacheManager.generateKey(l,{authUser:l.authUser});a=await this.cacheManager.get(N,()=>f(l),O)}else if(O&&typeof O==="object"&&O.ttl){let N=O.key||this.cacheManager.generateKey(l,{authUser:l.authUser});a=await this.cacheManager.get(N,()=>f(l),O.ttl)}else a=await f(l);let _;if(i.rawResponse||a instanceof Response)_=a instanceof Response?a:new Response(a);else _=b(200,a,i.responseContentType);return _=await this.middlewareManager.executeFinally(_,l),_}catch(A){if(A instanceof Response)return A;return console.error("Route handler error:",A),C.internalServerError(A instanceof Error?A.message:String(A),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,a]of this.routes)if(i.method==="OPTIONS"||i.method===E){let O=l.match(A);if(O){let _=i;if(!_.context)_.context={};_.params=O.groups||{};for(let N of a){let w=await N(_);if(w)return w}}}return C.notFound("Route not found")}clearRoutes(){this.routes=[]}}var p=U(()=>{B()});class g{server=null;router;config;corsHandler;constructor(i,f){if(this.router=i,this.config=f,f.cors){let{preflight:l,corsify:E}=F(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 A=await this.router.handle(E);if(this.corsHandler)A=this.corsHandler.corsify(A,E);return A}catch(A){return console.error("Server error:",A),new Response("Internal Server Error",{status:500})}};return 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})}}),console.log(`→ Vector server running at http://${f}:${i}`),this.server}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}`}}var e=U(()=>{Y()});var ii={};ai(ii,{getVectorInstance:()=>Li,Vector:()=>h});class h{static instance;router;server=null;middlewareManager;authManager;cacheManager;config={};routeScanner=null;routeGenerator=null;_protectedHandler=null;_cacheHandler=null;constructor(){this.middlewareManager=new T,this.authManager=new X,this.cacheManager=new J,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 g(this.router,this.config),await this.server.start()}async discoverRoutes(){let i=this.config.routesDir||"./routes";if(this.routeScanner=new Z(i),!this.routeGenerator)this.routeGenerator=new K;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 A=await import(o(l.path)),a=l.name==="default"?A.default:A[l.name];if(a){if(this.isRouteDefinition(a)){let O=a;this.router.route(O.options,O.handler),this.logRouteLoaded(O.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(E){console.error(`Failed to load route ${l.name} from ${l.path}:`,E)}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 Li;var fi=U(()=>{u();y();t();p();e();Li=h.getInstance});function Ri(i,f){let l=Pi(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 Ui(i){return JSON.stringify(i??null,(f,l)=>typeof l==="bigint"?l.toString():l)}function D(i,f,l){let E={error:!0,message:f,statusCode:i,timestamp:new Date().toISOString()};return b(i,E,l)}function b(i,f,l=j.JSON){let E=l===j.JSON?Ui(f):f;return new Response(E,{status:i,headers:{"content-type":l}})}function Pi(i,f){let{auth:l=!1,expose:E=!1,rawRequest:A=!1,rawResponse:a=!1,responseContentType:O=j.JSON}=i;return async(_)=>{if(!E)return C.forbidden("Forbidden");try{if(l)await Ci(_,O);if(!A)await k(_);m(_);let N=await f(_);return a?N:$i.success(N,O)}catch(N){if(N instanceof Response)return N;return C.internalServerError(String(N),O)}}}var lf,af,$i,C,Ci=async(i,f)=>{let{getVectorInstance:l}=await Promise.resolve().then(() => (fi(),ii)),A=l().getProtectedHandler();if(!A)throw C.unauthorized("Authentication not configured",f);try{let a=await A(i);i.authUser=a}catch(a){throw C.unauthorized(a instanceof Error?a.message:"Authentication failed",f)}};var B=U(()=>{Y();V();({preflight:lf,corsify:af}=F({origin:"*",credentials:!0,allowHeaders:"Content-Type, Authorization",allowMethods:"GET, POST, PUT, PATCH, DELETE, OPTIONS",exposeHeaders:"Authorization",maxAge:86400}));$i={success:(i,f)=>b(R.OK,i,f),created:(i,f)=>b(R.CREATED,i,f)};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)}});B();B();export{Ri as route,b as createResponse,C as APIError};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export interface VectorConfig<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
57
57
|
finally?: AfterMiddlewareHandler<TTypes>[];
|
|
58
58
|
routesDir?: string;
|
|
59
59
|
autoDiscover?: boolean;
|
|
60
|
+
idleTimeout?: number;
|
|
60
61
|
}
|
|
61
62
|
export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
62
63
|
port?: number;
|
|
@@ -64,6 +65,7 @@ export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTy
|
|
|
64
65
|
reusePort?: boolean;
|
|
65
66
|
development?: boolean;
|
|
66
67
|
routesDir?: string;
|
|
68
|
+
idleTimeout?: number;
|
|
67
69
|
before?: BeforeMiddlewareHandler<TTypes>[];
|
|
68
70
|
after?: AfterMiddlewareHandler<TTypes>[];
|
|
69
71
|
auth?: ProtectedHandler<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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AAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;CAC/B"}
|
package/package.json
CHANGED
package/src/cli/index.ts
CHANGED
|
@@ -36,6 +36,10 @@ const { values, positionals } = parseArgs({
|
|
|
36
36
|
type: "boolean",
|
|
37
37
|
default: true,
|
|
38
38
|
},
|
|
39
|
+
config: {
|
|
40
|
+
type: "string",
|
|
41
|
+
short: "c",
|
|
42
|
+
},
|
|
39
43
|
},
|
|
40
44
|
strict: true,
|
|
41
45
|
allowPositionals: true,
|
|
@@ -55,7 +59,7 @@ async function runDev() {
|
|
|
55
59
|
async function startServer() {
|
|
56
60
|
try {
|
|
57
61
|
// Load configuration using ConfigLoader
|
|
58
|
-
const configLoader = new ConfigLoader();
|
|
62
|
+
const configLoader = new ConfigLoader(values.config as string | undefined);
|
|
59
63
|
const config = await configLoader.load();
|
|
60
64
|
const configSource = configLoader.getConfigSource();
|
|
61
65
|
|
|
@@ -289,6 +293,7 @@ Options:
|
|
|
289
293
|
-h, --host <host> Hostname to bind to (default: localhost)
|
|
290
294
|
-r, --routes <dir> Routes directory (default: ./routes)
|
|
291
295
|
-w, --watch Watch for file changes (default: true)
|
|
296
|
+
-c, --config <path> Path to config file (default: vector.config.ts)
|
|
292
297
|
--cors Enable CORS (default: true)
|
|
293
298
|
`);
|
|
294
299
|
process.exit(1);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
2
|
+
import { resolve, isAbsolute } from "node:path";
|
|
3
3
|
import { toFileUrl } from "../utils/path";
|
|
4
4
|
import type {
|
|
5
5
|
CacheHandler,
|
|
@@ -16,9 +16,14 @@ export class ConfigLoader<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
16
16
|
private config: VectorConfigSchema<TTypes> | null = null;
|
|
17
17
|
private configSource: "user" | "default" = "default";
|
|
18
18
|
|
|
19
|
-
constructor(configPath
|
|
20
|
-
//
|
|
21
|
-
|
|
19
|
+
constructor(configPath?: string) {
|
|
20
|
+
// Use provided config path or default to vector.config.ts
|
|
21
|
+
const path = configPath || "vector.config.ts";
|
|
22
|
+
|
|
23
|
+
// Handle absolute vs relative paths
|
|
24
|
+
this.configPath = isAbsolute(path)
|
|
25
|
+
? path
|
|
26
|
+
: resolve(process.cwd(), path);
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
async load(): Promise<VectorConfig<TTypes>> {
|
|
@@ -67,6 +72,7 @@ export class ConfigLoader<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
67
72
|
config.reusePort = this.config.reusePort;
|
|
68
73
|
config.development = this.config.development;
|
|
69
74
|
config.routesDir = this.config.routesDir || "./routes";
|
|
75
|
+
config.idleTimeout = this.config.idleTimeout;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
// Always auto-discover routes
|
package/src/core/server.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { Server } from
|
|
2
|
-
import { cors } from
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import type { Server } from "bun";
|
|
2
|
+
import { cors } from "itty-router";
|
|
3
|
+
import type {
|
|
4
|
+
CorsOptions,
|
|
5
|
+
DefaultVectorTypes,
|
|
6
|
+
VectorConfig,
|
|
7
|
+
VectorTypes,
|
|
8
|
+
} from "../types";
|
|
9
|
+
import type { VectorRouter } from "./router";
|
|
5
10
|
|
|
6
11
|
export class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
7
12
|
private server: Server | null = null;
|
|
@@ -14,36 +19,38 @@ export class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
14
19
|
this.config = config;
|
|
15
20
|
|
|
16
21
|
if (config.cors) {
|
|
17
|
-
const { preflight, corsify } = cors(
|
|
22
|
+
const { preflight, corsify } = cors(
|
|
23
|
+
this.normalizeCorsOptions(config.cors)
|
|
24
|
+
);
|
|
18
25
|
this.corsHandler = { preflight, corsify };
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
private normalizeCorsOptions(options: CorsOptions): any {
|
|
23
30
|
return {
|
|
24
|
-
origin: options.origin ||
|
|
31
|
+
origin: options.origin || "*",
|
|
25
32
|
credentials: options.credentials !== false,
|
|
26
33
|
allowHeaders: Array.isArray(options.allowHeaders)
|
|
27
|
-
? options.allowHeaders.join(
|
|
28
|
-
: options.allowHeaders ||
|
|
34
|
+
? options.allowHeaders.join(", ")
|
|
35
|
+
: options.allowHeaders || "Content-Type, Authorization",
|
|
29
36
|
allowMethods: Array.isArray(options.allowMethods)
|
|
30
|
-
? options.allowMethods.join(
|
|
31
|
-
: options.allowMethods ||
|
|
37
|
+
? options.allowMethods.join(", ")
|
|
38
|
+
: options.allowMethods || "GET, POST, PUT, PATCH, DELETE, OPTIONS",
|
|
32
39
|
exposeHeaders: Array.isArray(options.exposeHeaders)
|
|
33
|
-
? options.exposeHeaders.join(
|
|
34
|
-
: options.exposeHeaders ||
|
|
40
|
+
? options.exposeHeaders.join(", ")
|
|
41
|
+
: options.exposeHeaders || "Authorization",
|
|
35
42
|
maxAge: options.maxAge || 86400,
|
|
36
43
|
};
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
async start(): Promise<Server> {
|
|
40
47
|
const port = this.config.port || 3000;
|
|
41
|
-
const hostname = this.config.hostname ||
|
|
48
|
+
const hostname = this.config.hostname || "localhost";
|
|
42
49
|
|
|
43
50
|
const fetch = async (request: Request): Promise<Response> => {
|
|
44
51
|
try {
|
|
45
52
|
// Handle CORS preflight
|
|
46
|
-
if (this.corsHandler && request.method ===
|
|
53
|
+
if (this.corsHandler && request.method === "OPTIONS") {
|
|
47
54
|
return this.corsHandler.preflight(request);
|
|
48
55
|
}
|
|
49
56
|
|
|
@@ -57,8 +64,8 @@ export class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
57
64
|
|
|
58
65
|
return response;
|
|
59
66
|
} catch (error) {
|
|
60
|
-
console.error(
|
|
61
|
-
return new Response(
|
|
67
|
+
console.error("Server error:", error);
|
|
68
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
62
69
|
}
|
|
63
70
|
};
|
|
64
71
|
|
|
@@ -67,9 +74,10 @@ export class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
67
74
|
hostname,
|
|
68
75
|
reusePort: this.config.reusePort !== false,
|
|
69
76
|
fetch,
|
|
77
|
+
idleTimeout: this.config.idleTimeout || 60,
|
|
70
78
|
error: (error) => {
|
|
71
|
-
console.error(
|
|
72
|
-
return new Response(
|
|
79
|
+
console.error("[ERROR] Server error:", error);
|
|
80
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
73
81
|
},
|
|
74
82
|
});
|
|
75
83
|
|
|
@@ -83,7 +91,7 @@ export class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
83
91
|
if (this.server) {
|
|
84
92
|
this.server.stop();
|
|
85
93
|
this.server = null;
|
|
86
|
-
console.log(
|
|
94
|
+
console.log("Server stopped");
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
|
|
@@ -96,7 +104,7 @@ export class VectorServer<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
getHostname(): string {
|
|
99
|
-
return this.server?.hostname || this.config.hostname ||
|
|
107
|
+
return this.server?.hostname || this.config.hostname || "localhost";
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
getUrl(): string {
|
package/src/types/index.ts
CHANGED
|
@@ -83,6 +83,7 @@ export interface VectorConfig<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
83
83
|
finally?: AfterMiddlewareHandler<TTypes>[];
|
|
84
84
|
routesDir?: string;
|
|
85
85
|
autoDiscover?: boolean;
|
|
86
|
+
idleTimeout?: number;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
// New config-driven schema - flat structure
|
|
@@ -93,18 +94,19 @@ export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTy
|
|
|
93
94
|
reusePort?: boolean;
|
|
94
95
|
development?: boolean;
|
|
95
96
|
routesDir?: string;
|
|
96
|
-
|
|
97
|
+
idleTimeout?: number;
|
|
98
|
+
|
|
97
99
|
// Middleware functions
|
|
98
100
|
before?: BeforeMiddlewareHandler<TTypes>[];
|
|
99
101
|
after?: AfterMiddlewareHandler<TTypes>[];
|
|
100
|
-
|
|
102
|
+
|
|
101
103
|
// Handler functions
|
|
102
104
|
auth?: ProtectedHandler<TTypes>;
|
|
103
105
|
cache?: CacheHandler;
|
|
104
|
-
|
|
106
|
+
|
|
105
107
|
// CORS configuration
|
|
106
108
|
cors?: CorsOptions | boolean;
|
|
107
|
-
|
|
109
|
+
|
|
108
110
|
// Custom types for TypeScript
|
|
109
111
|
types?: VectorTypes;
|
|
110
112
|
}
|