vector-framework 1.0.0 → 1.1.1
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 +6 -5
- package/dist/cache/manager.d.ts +5 -2
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js +21 -7
- package/dist/cache/manager.js.map +1 -1
- package/dist/cli/index.js +62 -83
- package/dist/cli/index.js.map +1 -1
- package/dist/cli.js +108 -37
- package/dist/core/config-loader.d.ts +2 -2
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +16 -18
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/router.d.ts +2 -0
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +52 -16
- package/dist/core/router.js.map +1 -1
- package/dist/core/server.d.ts +4 -3
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +39 -18
- package/dist/core/server.js.map +1 -1
- package/dist/core/vector.d.ts +7 -7
- package/dist/core/vector.d.ts.map +1 -1
- package/dist/core/vector.js +20 -21
- package/dist/core/vector.js.map +1 -1
- package/dist/dev/route-scanner.d.ts +1 -1
- package/dist/dev/route-scanner.d.ts.map +1 -1
- package/dist/dev/route-scanner.js +40 -42
- package/dist/dev/route-scanner.js.map +1 -1
- package/dist/http.d.ts +2 -2
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +70 -63
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/middleware/manager.d.ts +1 -1
- package/dist/middleware/manager.d.ts.map +1 -1
- package/dist/middleware/manager.js.map +1 -1
- package/dist/utils/path.d.ts +1 -0
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +9 -3
- package/dist/utils/path.js.map +1 -1
- package/package.json +12 -8
- package/src/cache/manager.ts +23 -14
- package/src/cli/index.ts +66 -89
- package/src/core/config-loader.ts +18 -20
- package/src/core/router.ts +52 -18
- package/src/core/server.ts +42 -28
- package/src/core/vector.ts +25 -35
- package/src/dev/route-scanner.ts +41 -47
- package/src/http.ts +82 -112
- package/src/index.ts +3 -3
- package/src/middleware/manager.ts +4 -11
- package/src/utils/path.ts +13 -4
package/dist/cli.js
CHANGED
|
@@ -161,7 +161,7 @@ var init_route_scanner = __esm(() => {
|
|
|
161
161
|
isExcluded(filePath) {
|
|
162
162
|
const relativePath = relative2(this.routesDir, filePath);
|
|
163
163
|
for (const pattern of this.excludePatterns) {
|
|
164
|
-
const regexPattern = pattern.replace(/\./g, "\\.").replace(/\*/g, "[^/]*").replace(
|
|
164
|
+
const regexPattern = pattern.replace(/\./g, "\\.").replace(/\*\*/g, "__GLOBSTAR__").replace(/\*/g, "[^/]*").replace(/__GLOBSTAR__/g, ".*").replace(/\?/g, ".");
|
|
165
165
|
const regex = new RegExp(`^${regexPattern}$`);
|
|
166
166
|
const filename = relativePath.split(sep).pop() || "";
|
|
167
167
|
if (regex.test(relativePath) || regex.test(filename)) {
|
|
@@ -351,6 +351,7 @@ class CacheManager {
|
|
|
351
351
|
cacheHandler = null;
|
|
352
352
|
memoryCache = new Map;
|
|
353
353
|
cleanupInterval = null;
|
|
354
|
+
inflight = new Map;
|
|
354
355
|
setCacheHandler(handler) {
|
|
355
356
|
this.cacheHandler = handler;
|
|
356
357
|
}
|
|
@@ -369,9 +370,20 @@ class CacheManager {
|
|
|
369
370
|
if (this.isCacheValid(cached, now)) {
|
|
370
371
|
return cached.value;
|
|
371
372
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
373
|
+
if (this.inflight.has(key)) {
|
|
374
|
+
return await this.inflight.get(key);
|
|
375
|
+
}
|
|
376
|
+
const promise = (async () => {
|
|
377
|
+
const value = await factory();
|
|
378
|
+
this.setInMemoryCache(key, value, ttl);
|
|
379
|
+
return value;
|
|
380
|
+
})();
|
|
381
|
+
this.inflight.set(key, promise);
|
|
382
|
+
try {
|
|
383
|
+
return await promise;
|
|
384
|
+
} finally {
|
|
385
|
+
this.inflight.delete(key);
|
|
386
|
+
}
|
|
375
387
|
}
|
|
376
388
|
isCacheValid(entry, now) {
|
|
377
389
|
return entry !== undefined && entry.expires > now;
|
|
@@ -431,12 +443,12 @@ class CacheManager {
|
|
|
431
443
|
return true;
|
|
432
444
|
}
|
|
433
445
|
generateKey(request, options) {
|
|
434
|
-
const url = new URL(request.url);
|
|
446
|
+
const url = request._parsedUrl ?? new URL(request.url);
|
|
435
447
|
const parts = [
|
|
436
448
|
request.method,
|
|
437
449
|
url.pathname,
|
|
438
450
|
url.search,
|
|
439
|
-
options?.authUser?.id
|
|
451
|
+
options?.authUser?.id != null ? String(options.authUser.id) : "anonymous"
|
|
440
452
|
];
|
|
441
453
|
return parts.join(":");
|
|
442
454
|
}
|
|
@@ -494,6 +506,9 @@ class MiddlewareManager {
|
|
|
494
506
|
function toFileUrl(path) {
|
|
495
507
|
return process.platform === "win32" ? `file:///${path.replace(/\\/g, "/")}` : path;
|
|
496
508
|
}
|
|
509
|
+
function buildRouteRegex(path) {
|
|
510
|
+
return RegExp(`^${path.replace(/\/+(\/|$)/g, "$1").replace(/(\/?\.?):(\w+)\+/g, "($1(?<$2>[\\s\\S]+))").replace(/(\/?\.?):(\w+)/g, "($1(?<$2>[^$1/]+?))").replace(/\./g, "\\.").replace(/(\/?)\*/g, "($1.*)?")}/*$`);
|
|
511
|
+
}
|
|
497
512
|
|
|
498
513
|
// node_modules/itty-router/index.mjs
|
|
499
514
|
var r = (e = "text/plain; charset=utf-8", t) => (r2, o = {}) => {
|
|
@@ -508,9 +523,6 @@ var f = r("text/html");
|
|
|
508
523
|
var u = r("image/jpeg");
|
|
509
524
|
var h = r("image/png");
|
|
510
525
|
var g = r("image/webp");
|
|
511
|
-
var w = (e) => {
|
|
512
|
-
e.cookies = (e.headers.get("Cookie") || "").split(/;\s*/).map((e2) => e2.split(/=(.+)/)).reduce((e2, [t, r2]) => r2 ? (e2[t] = r2, e2) : e2, {});
|
|
513
|
-
};
|
|
514
526
|
var y = (e = {}) => {
|
|
515
527
|
const { origin: t = "*", credentials: r2 = false, allowMethods: o2 = "*", allowHeaders: a, exposeHeaders: s, maxAge: c } = e, n = (e2) => {
|
|
516
528
|
const o3 = e2?.headers.get("origin");
|
|
@@ -537,8 +549,22 @@ var { preflight, corsify } = y({
|
|
|
537
549
|
exposeHeaders: "Authorization",
|
|
538
550
|
maxAge: 86400
|
|
539
551
|
});
|
|
552
|
+
function hasBigInt(value, depth = 0) {
|
|
553
|
+
if (typeof value === "bigint")
|
|
554
|
+
return true;
|
|
555
|
+
if (depth > 4 || value === null || typeof value !== "object")
|
|
556
|
+
return false;
|
|
557
|
+
for (const v of Object.values(value)) {
|
|
558
|
+
if (hasBigInt(v, depth + 1))
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
540
563
|
function stringifyData(data) {
|
|
541
|
-
|
|
564
|
+
const val = data ?? null;
|
|
565
|
+
if (!hasBigInt(val))
|
|
566
|
+
return JSON.stringify(val);
|
|
567
|
+
return JSON.stringify(val, (_key, value) => typeof value === "bigint" ? value.toString() : value);
|
|
542
568
|
}
|
|
543
569
|
function createErrorResponse(code, message, contentType) {
|
|
544
570
|
const errorBody = {
|
|
@@ -608,12 +634,16 @@ class VectorRouter {
|
|
|
608
634
|
authManager;
|
|
609
635
|
cacheManager;
|
|
610
636
|
routes = [];
|
|
637
|
+
specificityCache = new Map;
|
|
611
638
|
constructor(middlewareManager, authManager, cacheManager) {
|
|
612
639
|
this.middlewareManager = middlewareManager;
|
|
613
640
|
this.authManager = authManager;
|
|
614
641
|
this.cacheManager = cacheManager;
|
|
615
642
|
}
|
|
616
643
|
getRouteSpecificity(path) {
|
|
644
|
+
const cached = this.specificityCache.get(path);
|
|
645
|
+
if (cached !== undefined)
|
|
646
|
+
return cached;
|
|
617
647
|
const STATIC_SEGMENT_WEIGHT = 1000;
|
|
618
648
|
const PARAM_SEGMENT_WEIGHT = 10;
|
|
619
649
|
const WILDCARD_WEIGHT = 1;
|
|
@@ -633,6 +663,7 @@ class VectorRouter {
|
|
|
633
663
|
if (this.isExactPath(path)) {
|
|
634
664
|
score += EXACT_MATCH_BONUS;
|
|
635
665
|
}
|
|
666
|
+
this.specificityCache.set(path, score);
|
|
636
667
|
return score;
|
|
637
668
|
}
|
|
638
669
|
isStaticSegment(segment) {
|
|
@@ -673,7 +704,7 @@ class VectorRouter {
|
|
|
673
704
|
return routeEntry;
|
|
674
705
|
}
|
|
675
706
|
createRouteRegex(path) {
|
|
676
|
-
return
|
|
707
|
+
return buildRouteRegex(path);
|
|
677
708
|
}
|
|
678
709
|
prepareRequest(request, options) {
|
|
679
710
|
if (!request.context) {
|
|
@@ -689,7 +720,7 @@ class VectorRouter {
|
|
|
689
720
|
request.metadata = options.metadata;
|
|
690
721
|
}
|
|
691
722
|
if (!request.query && request.url) {
|
|
692
|
-
const url = new URL(request.url);
|
|
723
|
+
const url = request._parsedUrl ?? new URL(request.url);
|
|
693
724
|
const query = {};
|
|
694
725
|
for (const [key, value] of url.searchParams) {
|
|
695
726
|
if (key in query) {
|
|
@@ -704,8 +735,30 @@ class VectorRouter {
|
|
|
704
735
|
}
|
|
705
736
|
request.query = query;
|
|
706
737
|
}
|
|
707
|
-
if (!request
|
|
708
|
-
|
|
738
|
+
if (!Object.getOwnPropertyDescriptor(request, "cookies")) {
|
|
739
|
+
Object.defineProperty(request, "cookies", {
|
|
740
|
+
get() {
|
|
741
|
+
const cookieHeader = this.headers.get("cookie") ?? "";
|
|
742
|
+
const cookies = {};
|
|
743
|
+
if (cookieHeader) {
|
|
744
|
+
for (const pair of cookieHeader.split(";")) {
|
|
745
|
+
const idx = pair.indexOf("=");
|
|
746
|
+
if (idx > 0) {
|
|
747
|
+
cookies[pair.slice(0, idx).trim()] = pair.slice(idx + 1).trim();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
Object.defineProperty(this, "cookies", {
|
|
752
|
+
value: cookies,
|
|
753
|
+
writable: true,
|
|
754
|
+
configurable: true,
|
|
755
|
+
enumerable: true
|
|
756
|
+
});
|
|
757
|
+
return cookies;
|
|
758
|
+
},
|
|
759
|
+
configurable: true,
|
|
760
|
+
enumerable: true
|
|
761
|
+
});
|
|
709
762
|
}
|
|
710
763
|
}
|
|
711
764
|
wrapHandler(options, handler) {
|
|
@@ -801,11 +854,23 @@ class VectorRouter {
|
|
|
801
854
|
this.routes.push(routeEntry);
|
|
802
855
|
this.sortRoutes();
|
|
803
856
|
}
|
|
857
|
+
bulkAddRoutes(entries) {
|
|
858
|
+
for (const entry of entries) {
|
|
859
|
+
this.routes.push(entry);
|
|
860
|
+
}
|
|
861
|
+
this.sortRoutes();
|
|
862
|
+
}
|
|
804
863
|
getRoutes() {
|
|
805
864
|
return this.routes;
|
|
806
865
|
}
|
|
807
866
|
async handle(request) {
|
|
808
|
-
|
|
867
|
+
let url;
|
|
868
|
+
try {
|
|
869
|
+
url = new URL(request.url);
|
|
870
|
+
} catch {
|
|
871
|
+
return APIError.badRequest("Malformed request URL");
|
|
872
|
+
}
|
|
873
|
+
request._parsedUrl = url;
|
|
809
874
|
const pathname = url.pathname;
|
|
810
875
|
for (const [method, regex, handlers, path] of this.routes) {
|
|
811
876
|
if (request.method === "OPTIONS" || request.method === method) {
|
|
@@ -828,6 +893,7 @@ class VectorRouter {
|
|
|
828
893
|
}
|
|
829
894
|
clearRoutes() {
|
|
830
895
|
this.routes = [];
|
|
896
|
+
this.specificityCache.clear();
|
|
831
897
|
}
|
|
832
898
|
}
|
|
833
899
|
|
|
@@ -837,12 +903,26 @@ class VectorServer {
|
|
|
837
903
|
router;
|
|
838
904
|
config;
|
|
839
905
|
corsHandler;
|
|
906
|
+
corsHeaders = null;
|
|
840
907
|
constructor(router, config) {
|
|
841
908
|
this.router = router;
|
|
842
909
|
this.config = config;
|
|
843
910
|
if (config.cors) {
|
|
844
|
-
const
|
|
911
|
+
const opts = this.normalizeCorsOptions(config.cors);
|
|
912
|
+
const { preflight: preflight2, corsify: corsify2 } = y(opts);
|
|
845
913
|
this.corsHandler = { preflight: preflight2, corsify: corsify2 };
|
|
914
|
+
if (typeof opts.origin === "string") {
|
|
915
|
+
this.corsHeaders = {
|
|
916
|
+
"access-control-allow-origin": opts.origin,
|
|
917
|
+
"access-control-allow-methods": opts.allowMethods,
|
|
918
|
+
"access-control-allow-headers": opts.allowHeaders,
|
|
919
|
+
"access-control-expose-headers": opts.exposeHeaders,
|
|
920
|
+
"access-control-max-age": String(opts.maxAge)
|
|
921
|
+
};
|
|
922
|
+
if (opts.credentials) {
|
|
923
|
+
this.corsHeaders["access-control-allow-credentials"] = "true";
|
|
924
|
+
}
|
|
925
|
+
}
|
|
846
926
|
}
|
|
847
927
|
}
|
|
848
928
|
normalizeCorsOptions(options) {
|
|
@@ -864,7 +944,11 @@ class VectorServer {
|
|
|
864
944
|
return this.corsHandler.preflight(request);
|
|
865
945
|
}
|
|
866
946
|
let response = await this.router.handle(request);
|
|
867
|
-
if (this.
|
|
947
|
+
if (this.corsHeaders) {
|
|
948
|
+
for (const [k, v] of Object.entries(this.corsHeaders)) {
|
|
949
|
+
response.headers.set(k, v);
|
|
950
|
+
}
|
|
951
|
+
} else if (this.corsHandler) {
|
|
868
952
|
response = this.corsHandler.corsify(response, request);
|
|
869
953
|
}
|
|
870
954
|
return response;
|
|
@@ -1097,9 +1181,9 @@ class ConfigLoader {
|
|
|
1097
1181
|
this.config = userConfig.default || userConfig;
|
|
1098
1182
|
this.configSource = "user";
|
|
1099
1183
|
} catch (error) {
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
console.error(
|
|
1184
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1185
|
+
console.error(`[Vector] Failed to load config from ${this.configPath}: ${msg}`);
|
|
1186
|
+
console.error("[Vector] Server is using default configuration. Fix your config file and restart.");
|
|
1103
1187
|
this.config = {};
|
|
1104
1188
|
}
|
|
1105
1189
|
} else {
|
|
@@ -1255,7 +1339,9 @@ Listening on ${cyan}http://${config.hostname}:${config.port}${reset}
|
|
|
1255
1339
|
const now = Date.now();
|
|
1256
1340
|
if (isReloading || now - lastReloadTime < 1000)
|
|
1257
1341
|
return;
|
|
1258
|
-
|
|
1342
|
+
const segments = filename ? filename.split(/[/\\]/) : [];
|
|
1343
|
+
const excluded = segments.some((s) => ["node_modules", ".git", ".vector", "dist"].includes(s));
|
|
1344
|
+
if (filename && (filename.endsWith(".ts") || filename.endsWith(".js") || filename.endsWith(".json")) && !excluded && !filename.includes("bun.lockb") && !filename.endsWith(".generated.ts")) {
|
|
1259
1345
|
changedFiles.add(filename);
|
|
1260
1346
|
if (reloadTimeout) {
|
|
1261
1347
|
clearTimeout(reloadTimeout);
|
|
@@ -1270,13 +1356,6 @@ Listening on ${cyan}http://${config.hostname}:${config.port}${reset}
|
|
|
1270
1356
|
vector.stop();
|
|
1271
1357
|
}
|
|
1272
1358
|
await new Promise((resolve3) => setTimeout(resolve3, 100));
|
|
1273
|
-
if (__require.cache) {
|
|
1274
|
-
for (const key in __require.cache) {
|
|
1275
|
-
if (!key.includes("node_modules")) {
|
|
1276
|
-
delete __require.cache[key];
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
1359
|
try {
|
|
1281
1360
|
const result2 = await startServer();
|
|
1282
1361
|
server = result2.server;
|
|
@@ -1333,15 +1412,7 @@ async function runBuild() {
|
|
|
1333
1412
|
}
|
|
1334
1413
|
} else {
|
|
1335
1414
|
const { spawnSync } = await import("child_process");
|
|
1336
|
-
const result = spawnSync("bun", [
|
|
1337
|
-
"build",
|
|
1338
|
-
"src/cli/index.ts",
|
|
1339
|
-
"--target",
|
|
1340
|
-
"bun",
|
|
1341
|
-
"--outfile",
|
|
1342
|
-
"dist/server.js",
|
|
1343
|
-
"--minify"
|
|
1344
|
-
], {
|
|
1415
|
+
const result = spawnSync("bun", ["build", "src/cli/index.ts", "--target", "bun", "--outfile", "dist/server.js", "--minify"], {
|
|
1345
1416
|
stdio: "inherit",
|
|
1346
1417
|
shell: true
|
|
1347
1418
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { CacheHandler, DefaultVectorTypes, ProtectedHandler, VectorConfig, VectorConfigSchema, VectorTypes } from
|
|
1
|
+
import type { CacheHandler, DefaultVectorTypes, ProtectedHandler, VectorConfig, VectorConfigSchema, VectorTypes } from '../types';
|
|
2
2
|
export declare class ConfigLoader<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
3
3
|
private configPath;
|
|
4
4
|
private config;
|
|
5
5
|
private configSource;
|
|
6
6
|
constructor(configPath?: string);
|
|
7
7
|
load(): Promise<VectorConfig<TTypes>>;
|
|
8
|
-
getConfigSource():
|
|
8
|
+
getConfigSource(): 'user' | 'default';
|
|
9
9
|
private buildLegacyConfig;
|
|
10
10
|
loadAuthHandler(): Promise<ProtectedHandler<TTypes> | null>;
|
|
11
11
|
loadCacheHandler(): Promise<CacheHandler | null>;
|
|
@@ -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,CAAC,EAAE,MAAM;
|
|
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;IAQzB,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IA0B3C,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,17 +1,15 @@
|
|
|
1
|
-
import { existsSync } from
|
|
2
|
-
import { resolve, isAbsolute } from
|
|
3
|
-
import { toFileUrl } from
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolve, isAbsolute } from 'node:path';
|
|
3
|
+
import { toFileUrl } from '../utils/path';
|
|
4
4
|
export class ConfigLoader {
|
|
5
5
|
configPath;
|
|
6
6
|
config = null;
|
|
7
|
-
configSource =
|
|
7
|
+
configSource = 'default';
|
|
8
8
|
constructor(configPath) {
|
|
9
9
|
// Use provided config path or default to vector.config.ts
|
|
10
|
-
const path = configPath ||
|
|
10
|
+
const path = configPath || 'vector.config.ts';
|
|
11
11
|
// Handle absolute vs relative paths
|
|
12
|
-
this.configPath = isAbsolute(path)
|
|
13
|
-
? path
|
|
14
|
-
: resolve(process.cwd(), path);
|
|
12
|
+
this.configPath = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
15
13
|
}
|
|
16
14
|
async load() {
|
|
17
15
|
// Check if config file exists before attempting to load
|
|
@@ -21,12 +19,12 @@ export class ConfigLoader {
|
|
|
21
19
|
const userConfigPath = toFileUrl(this.configPath);
|
|
22
20
|
const userConfig = await import(userConfigPath);
|
|
23
21
|
this.config = userConfig.default || userConfig;
|
|
24
|
-
this.configSource =
|
|
22
|
+
this.configSource = 'user';
|
|
25
23
|
}
|
|
26
24
|
catch (error) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
console.error(
|
|
25
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
26
|
+
console.error(`[Vector] Failed to load config from ${this.configPath}: ${msg}`);
|
|
27
|
+
console.error('[Vector] Server is using default configuration. Fix your config file and restart.');
|
|
30
28
|
this.config = {};
|
|
31
29
|
}
|
|
32
30
|
}
|
|
@@ -48,21 +46,21 @@ export class ConfigLoader {
|
|
|
48
46
|
config.hostname = this.config.hostname;
|
|
49
47
|
config.reusePort = this.config.reusePort;
|
|
50
48
|
config.development = this.config.development;
|
|
51
|
-
config.routesDir = this.config.routesDir ||
|
|
49
|
+
config.routesDir = this.config.routesDir || './routes';
|
|
52
50
|
config.idleTimeout = this.config.idleTimeout;
|
|
53
51
|
}
|
|
54
52
|
// Always auto-discover routes
|
|
55
53
|
config.autoDiscover = true;
|
|
56
54
|
// CORS configuration
|
|
57
55
|
if (this.config?.cors) {
|
|
58
|
-
if (typeof this.config.cors ===
|
|
56
|
+
if (typeof this.config.cors === 'boolean') {
|
|
59
57
|
config.cors = this.config.cors
|
|
60
58
|
? {
|
|
61
|
-
origin:
|
|
59
|
+
origin: '*',
|
|
62
60
|
credentials: true,
|
|
63
|
-
allowHeaders:
|
|
64
|
-
allowMethods:
|
|
65
|
-
exposeHeaders:
|
|
61
|
+
allowHeaders: 'Content-Type, Authorization',
|
|
62
|
+
allowMethods: 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
|
|
63
|
+
exposeHeaders: 'Authorization',
|
|
66
64
|
maxAge: 86400,
|
|
67
65
|
}
|
|
68
66
|
: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/core/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,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router.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare class VectorRouter<TTypes extends VectorTypes = DefaultVectorType
|
|
|
8
8
|
private authManager;
|
|
9
9
|
private cacheManager;
|
|
10
10
|
private routes;
|
|
11
|
+
private specificityCache;
|
|
11
12
|
constructor(middlewareManager: MiddlewareManager<TTypes>, authManager: AuthManager<TTypes>, cacheManager: CacheManager<TTypes>);
|
|
12
13
|
private getRouteSpecificity;
|
|
13
14
|
private isStaticSegment;
|
|
@@ -21,6 +22,7 @@ export declare class VectorRouter<TTypes extends VectorTypes = DefaultVectorType
|
|
|
21
22
|
private prepareRequest;
|
|
22
23
|
private wrapHandler;
|
|
23
24
|
addRoute(routeEntry: RouteEntry): void;
|
|
25
|
+
bulkAddRoutes(entries: RouteEntry[]): void;
|
|
24
26
|
getRoutes(): RouteEntry[];
|
|
25
27
|
handle(request: Request): Promise<Response>;
|
|
26
28
|
clearRoutes(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,YAAY,EAEZ,WAAW,EACZ,MAAM,UAAU,CAAC;AAGlB,qBAAa,YAAY,CAAC,MAAM,SAAS,WAAW,GAAG,kBAAkB;IACvE,OAAO,CAAC,iBAAiB,CAA4B;IACrD,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,gBAAgB,CAAkC;gBAGxD,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAC5C,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC;IAOpC,OAAO,CAAC,mBAAmB;IAgC3B,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,WAAW;IAInB,UAAU,IAAI,IAAI;IAYlB,OAAO,CAAC,WAAW;IAKnB,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,UAAU;IAc/E,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,cAAc;IAsEtB,OAAO,CAAC,WAAW;IAqHnB,QAAQ,CAAC,UAAU,EAAE,UAAU;IAK/B,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI;IAO1C,SAAS,IAAI,UAAU,EAAE;IAInB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiCjD,WAAW,IAAI,IAAI;CAIpB"}
|
package/dist/core/router.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { withCookies } from 'itty-router';
|
|
2
1
|
import { APIError, createResponse } from '../http';
|
|
2
|
+
import { buildRouteRegex } from '../utils/path';
|
|
3
3
|
export class VectorRouter {
|
|
4
4
|
middlewareManager;
|
|
5
5
|
authManager;
|
|
6
6
|
cacheManager;
|
|
7
7
|
routes = [];
|
|
8
|
+
specificityCache = new Map();
|
|
8
9
|
constructor(middlewareManager, authManager, cacheManager) {
|
|
9
10
|
this.middlewareManager = middlewareManager;
|
|
10
11
|
this.authManager = authManager;
|
|
11
12
|
this.cacheManager = cacheManager;
|
|
12
13
|
}
|
|
13
14
|
getRouteSpecificity(path) {
|
|
15
|
+
const cached = this.specificityCache.get(path);
|
|
16
|
+
if (cached !== undefined)
|
|
17
|
+
return cached;
|
|
14
18
|
const STATIC_SEGMENT_WEIGHT = 1000;
|
|
15
19
|
const PARAM_SEGMENT_WEIGHT = 10;
|
|
16
20
|
const WILDCARD_WEIGHT = 1;
|
|
@@ -32,6 +36,7 @@ export class VectorRouter {
|
|
|
32
36
|
if (this.isExactPath(path)) {
|
|
33
37
|
score += EXACT_MATCH_BONUS;
|
|
34
38
|
}
|
|
39
|
+
this.specificityCache.set(path, score);
|
|
35
40
|
return score;
|
|
36
41
|
}
|
|
37
42
|
isStaticSegment(segment) {
|
|
@@ -72,12 +77,7 @@ export class VectorRouter {
|
|
|
72
77
|
return routeEntry;
|
|
73
78
|
}
|
|
74
79
|
createRouteRegex(path) {
|
|
75
|
-
return
|
|
76
|
-
.replace(/\/+(\/|$)/g, '$1')
|
|
77
|
-
.replace(/(\/?\.?):(\w+)\+/g, '($1(?<$2>*))')
|
|
78
|
-
.replace(/(\/?\.?):(\w+)/g, '($1(?<$2>[^$1/]+?))')
|
|
79
|
-
.replace(/\./g, '\\.')
|
|
80
|
-
.replace(/(\/?)\*/g, '($1.*)?')}/*$`);
|
|
80
|
+
return buildRouteRegex(path);
|
|
81
81
|
}
|
|
82
82
|
prepareRequest(request, options) {
|
|
83
83
|
// Initialize context if not present
|
|
@@ -96,7 +96,7 @@ export class VectorRouter {
|
|
|
96
96
|
}
|
|
97
97
|
// Parse query parameters from URL if not already parsed
|
|
98
98
|
if (!request.query && request.url) {
|
|
99
|
-
const url = new URL(request.url);
|
|
99
|
+
const url = request._parsedUrl ?? new URL(request.url);
|
|
100
100
|
const query = {};
|
|
101
101
|
for (const [key, value] of url.searchParams) {
|
|
102
102
|
if (key in query) {
|
|
@@ -113,9 +113,31 @@ export class VectorRouter {
|
|
|
113
113
|
}
|
|
114
114
|
request.query = query;
|
|
115
115
|
}
|
|
116
|
-
//
|
|
117
|
-
if (!request
|
|
118
|
-
|
|
116
|
+
// Lazy cookie parsing — only parse the Cookie header when first accessed
|
|
117
|
+
if (!Object.getOwnPropertyDescriptor(request, 'cookies')) {
|
|
118
|
+
Object.defineProperty(request, 'cookies', {
|
|
119
|
+
get() {
|
|
120
|
+
const cookieHeader = this.headers.get('cookie') ?? '';
|
|
121
|
+
const cookies = {};
|
|
122
|
+
if (cookieHeader) {
|
|
123
|
+
for (const pair of cookieHeader.split(';')) {
|
|
124
|
+
const idx = pair.indexOf('=');
|
|
125
|
+
if (idx > 0) {
|
|
126
|
+
cookies[pair.slice(0, idx).trim()] = pair.slice(idx + 1).trim();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
Object.defineProperty(this, 'cookies', {
|
|
131
|
+
value: cookies,
|
|
132
|
+
writable: true,
|
|
133
|
+
configurable: true,
|
|
134
|
+
enumerable: true,
|
|
135
|
+
});
|
|
136
|
+
return cookies;
|
|
137
|
+
},
|
|
138
|
+
configurable: true,
|
|
139
|
+
enumerable: true,
|
|
140
|
+
});
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
143
|
wrapHandler(options, handler) {
|
|
@@ -124,7 +146,7 @@ export class VectorRouter {
|
|
|
124
146
|
const vectorRequest = request;
|
|
125
147
|
// Prepare the request with common logic
|
|
126
148
|
this.prepareRequest(vectorRequest, {
|
|
127
|
-
metadata: options.metadata
|
|
149
|
+
metadata: options.metadata,
|
|
128
150
|
});
|
|
129
151
|
request = vectorRequest;
|
|
130
152
|
try {
|
|
@@ -176,7 +198,7 @@ export class VectorRouter {
|
|
|
176
198
|
_isResponse: true,
|
|
177
199
|
body: await res.text(),
|
|
178
200
|
status: res.status,
|
|
179
|
-
headers: Object.fromEntries(res.headers.entries())
|
|
201
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
180
202
|
};
|
|
181
203
|
}
|
|
182
204
|
return res;
|
|
@@ -201,7 +223,7 @@ export class VectorRouter {
|
|
|
201
223
|
if (result && typeof result === 'object' && result._isResponse === true) {
|
|
202
224
|
result = new Response(result.body, {
|
|
203
225
|
status: result.status,
|
|
204
|
-
headers: result.headers
|
|
226
|
+
headers: result.headers,
|
|
205
227
|
});
|
|
206
228
|
}
|
|
207
229
|
let response;
|
|
@@ -227,11 +249,24 @@ export class VectorRouter {
|
|
|
227
249
|
this.routes.push(routeEntry);
|
|
228
250
|
this.sortRoutes(); // Sort routes after adding a new one
|
|
229
251
|
}
|
|
252
|
+
bulkAddRoutes(entries) {
|
|
253
|
+
for (const entry of entries) {
|
|
254
|
+
this.routes.push(entry);
|
|
255
|
+
}
|
|
256
|
+
this.sortRoutes(); // Sort once after all routes are added — O(n log n) instead of O(n²)
|
|
257
|
+
}
|
|
230
258
|
getRoutes() {
|
|
231
259
|
return this.routes;
|
|
232
260
|
}
|
|
233
261
|
async handle(request) {
|
|
234
|
-
|
|
262
|
+
let url;
|
|
263
|
+
try {
|
|
264
|
+
url = new URL(request.url);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return APIError.badRequest('Malformed request URL');
|
|
268
|
+
}
|
|
269
|
+
request._parsedUrl = url;
|
|
235
270
|
const pathname = url.pathname;
|
|
236
271
|
for (const [method, regex, handlers, path] of this.routes) {
|
|
237
272
|
if (request.method === 'OPTIONS' || request.method === method) {
|
|
@@ -241,7 +276,7 @@ export class VectorRouter {
|
|
|
241
276
|
// Prepare the request with common logic
|
|
242
277
|
this.prepareRequest(req, {
|
|
243
278
|
params: match.groups || {},
|
|
244
|
-
route: path || pathname
|
|
279
|
+
route: path || pathname,
|
|
245
280
|
});
|
|
246
281
|
for (const handler of handlers) {
|
|
247
282
|
const response = await handler(req);
|
|
@@ -255,6 +290,7 @@ export class VectorRouter {
|
|
|
255
290
|
}
|
|
256
291
|
clearRoutes() {
|
|
257
292
|
this.routes = [];
|
|
293
|
+
this.specificityCache.clear();
|
|
258
294
|
}
|
|
259
295
|
}
|
|
260
296
|
//# sourceMappingURL=router.js.map
|
package/dist/core/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AASnD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,OAAO,YAAY;IACf,iBAAiB,CAA4B;IAC7C,WAAW,CAAsB;IACjC,YAAY,CAAuB;IACnC,MAAM,GAAiB,EAAE,CAAC;IAC1B,gBAAgB,GAAwB,IAAI,GAAG,EAAE,CAAC;IAE1D,YACE,iBAA4C,EAC5C,WAAgC,EAChC,YAAkC;QAElC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEO,mBAAmB,CAAC,IAAY;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;QAExC,MAAM,qBAAqB,GAAG,IAAI,CAAC;QACnC,MAAM,oBAAoB,GAAG,EAAE,CAAC;QAChC,MAAM,eAAe,GAAG,CAAC,CAAC;QAC1B,MAAM,iBAAiB,GAAG,KAAK,CAAC;QAEhC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEjD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,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K,EAAE,CAAC;oBACV,MAAM,GAAG,GAAG,OAAuC,CAAC;oBAEpD,wCAAwC;oBACxC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE;wBACvB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;wBAC1B,KAAK,EAAE,IAAI,IAAI,QAAQ;qBACxB,CAAC,CAAC;oBAEH,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;wBAC/B,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAU,CAAC,CAAC;wBAC3C,IAAI,QAAQ;4BAAE,OAAO,QAAQ,CAAC;oBAChC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAC9C,CAAC;IAED,WAAW;QACT,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF"}
|
package/dist/core/server.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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;
|
|
7
7
|
private config;
|
|
8
8
|
private corsHandler;
|
|
9
|
+
private corsHeaders;
|
|
9
10
|
constructor(router: VectorRouter<TTypes>, config: VectorConfig<TTypes>);
|
|
10
11
|
private normalizeCorsOptions;
|
|
11
12
|
start(): Promise<Server>;
|
|
@@ -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,EAAe,kBAAkB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC3F,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;IACzB,OAAO,CAAC,WAAW,CAAuC;gBAE9C,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC;IA0BtE,OAAO,CAAC,oBAAoB;IAiBtB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAoE9B,IAAI;IAQJ,SAAS,IAAI,MAAM,GAAG,IAAI;IAI1B,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,MAAM;IAIrB,MAAM,IAAI,MAAM;CAKjB"}
|