vector-framework 0.9.4 → 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 +11 -5
- package/dist/cli/index.js +10 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/cli.js +25 -102
- package/dist/core/config-loader.d.ts +2 -3
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +34 -120
- 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/core/vector.d.ts +7 -7
- package/dist/core/vector.d.ts.map +1 -1
- package/dist/core/vector.js +25 -26
- package/dist/core/vector.js.map +1 -1
- package/dist/dev/route-generator.d.ts.map +1 -1
- package/dist/dev/route-generator.js +0 -1
- package/dist/dev/route-generator.js.map +1 -1
- package/dist/dev/route-scanner.d.ts.map +1 -1
- package/dist/dev/route-scanner.js +0 -6
- package/dist/dev/route-scanner.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/dist/types/index.d.ts +7 -18
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/index.ts +10 -5
- package/src/core/config-loader.ts +44 -132
- package/src/core/server.ts +28 -20
- package/src/core/vector.ts +40 -29
- package/src/dev/route-generator.ts +0 -1
- package/src/dev/route-scanner.ts +0 -6
- package/src/types/index.ts +14 -31
package/README.md
CHANGED
|
@@ -16,15 +16,18 @@ bun add vector-framework
|
|
|
16
16
|
|
|
17
17
|
Create a `vector.config.ts` file in your project root:
|
|
18
18
|
|
|
19
|
-
```
|
|
20
|
-
// vector.config.
|
|
21
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
// vector.config.ts
|
|
21
|
+
import type { VectorConfigSchema } from "vector-framework";
|
|
22
|
+
|
|
23
|
+
const config: VectorConfigSchema = {
|
|
24
|
+
// Server configuration
|
|
22
25
|
port: 3000, // Server port (default: 3000)
|
|
23
26
|
hostname: "localhost", // Server hostname (default: localhost)
|
|
24
27
|
routesDir: "./routes", // Routes directory (default: ./routes)
|
|
25
|
-
development:
|
|
28
|
+
development: process.env.NODE_ENV !== "production", // Development mode
|
|
26
29
|
reusePort: true, // Reuse port (default: true)
|
|
27
|
-
|
|
30
|
+
idleTimeout: 60, // Idle timeout in seconds (default: 60)
|
|
28
31
|
|
|
29
32
|
// CORS configuration
|
|
30
33
|
cors: {
|
|
@@ -36,6 +39,8 @@ export default {
|
|
|
36
39
|
maxAge: 86400, // Preflight cache duration in seconds
|
|
37
40
|
},
|
|
38
41
|
};
|
|
42
|
+
|
|
43
|
+
export default config;
|
|
39
44
|
```
|
|
40
45
|
|
|
41
46
|
### Your First API (Encore-style)
|
|
@@ -334,6 +339,7 @@ interface VectorConfig {
|
|
|
334
339
|
development?: boolean; // Development mode
|
|
335
340
|
routesDir?: string; // Routes directory (default: ./routes)
|
|
336
341
|
autoDiscover?: boolean; // Auto-discover routes (default: true)
|
|
342
|
+
idleTimeout?: number; // Idle timeout in seconds (default: 60)
|
|
337
343
|
cors?: CorsOptions; // CORS configuration
|
|
338
344
|
before?: BeforeMiddlewareHandler[]; // Pre-request middleware
|
|
339
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
|
|
@@ -53,8 +57,8 @@ async function runDev() {
|
|
|
53
57
|
config.port = config.port ?? Number.parseInt(values.port);
|
|
54
58
|
config.hostname = config.hostname ?? values.host;
|
|
55
59
|
config.routesDir = config.routesDir ?? values.routes;
|
|
56
|
-
config.development = isDev;
|
|
57
|
-
config.autoDiscover = true;
|
|
60
|
+
config.development = config.development ?? isDev;
|
|
61
|
+
config.autoDiscover = true; // Always auto-discover routes
|
|
58
62
|
// Apply CLI CORS option if not set in config
|
|
59
63
|
if (!config.cors && values.cors) {
|
|
60
64
|
config.cors = {
|
|
@@ -89,8 +93,8 @@ async function runDev() {
|
|
|
89
93
|
if (isDev && values.watch) {
|
|
90
94
|
console.log(` ${gray}Watching${reset} All project files`);
|
|
91
95
|
}
|
|
92
|
-
console.log(` ${gray}CORS${reset} ${
|
|
93
|
-
console.log(` ${gray}Mode${reset} ${
|
|
96
|
+
console.log(` ${gray}CORS${reset} ${config.cors ? "Enabled" : "Disabled"}`);
|
|
97
|
+
console.log(` ${gray}Mode${reset} ${config.development ? "Development" : "Production"}\n`);
|
|
94
98
|
console.log(` ${green}Ready${reset} → ${cyan}http://${config.hostname}:${config.port}${reset}\n`);
|
|
95
99
|
return { server, vector, config };
|
|
96
100
|
}
|
|
@@ -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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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
|
@@ -290,7 +290,6 @@ ${routeEntries.join(`
|
|
|
290
290
|
export default routes;
|
|
291
291
|
`;
|
|
292
292
|
await fs.writeFile(this.outputPath, content, "utf-8");
|
|
293
|
-
console.log(`Generated routes file: ${this.outputPath}`);
|
|
294
293
|
}
|
|
295
294
|
async generateDynamic(routes) {
|
|
296
295
|
const routeEntries = [];
|
|
@@ -331,16 +330,10 @@ class RouteScanner {
|
|
|
331
330
|
async scan() {
|
|
332
331
|
const routes = [];
|
|
333
332
|
if (!existsSync(this.routesDir)) {
|
|
334
|
-
console.log(` \u2192 Routes directory not found: ${this.routesDir}`);
|
|
335
|
-
console.log(" \u2192 No routes will be auto-discovered");
|
|
336
333
|
return [];
|
|
337
334
|
}
|
|
338
335
|
try {
|
|
339
|
-
console.log(` \u2192 Scanning routes from: ${this.routesDir}`);
|
|
340
336
|
await this.scanDirectory(this.routesDir, routes);
|
|
341
|
-
if (routes.length > 0) {
|
|
342
|
-
console.log(` \u2713 Found ${routes.length} route${routes.length === 1 ? "" : "s"}`);
|
|
343
|
-
}
|
|
344
337
|
} catch (error) {
|
|
345
338
|
if (error.code === "ENOENT") {
|
|
346
339
|
console.warn(` \u2717 Routes directory not accessible: ${this.routesDir}`);
|
|
@@ -811,6 +804,7 @@ class VectorServer {
|
|
|
811
804
|
hostname,
|
|
812
805
|
reusePort: this.config.reusePort !== false,
|
|
813
806
|
fetch,
|
|
807
|
+
idleTimeout: this.config.idleTimeout || 60,
|
|
814
808
|
error: (error) => {
|
|
815
809
|
console.error("[ERROR] Server error:", error);
|
|
816
810
|
return new Response("Internal Server Error", { status: 500 });
|
|
@@ -938,7 +932,6 @@ class Vector {
|
|
|
938
932
|
}
|
|
939
933
|
}
|
|
940
934
|
this.router.sortRoutes();
|
|
941
|
-
console.log(`\u2705 Loaded ${routes.length} routes from ${routesDir}`);
|
|
942
935
|
}
|
|
943
936
|
} catch (error) {
|
|
944
937
|
if (error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
@@ -969,13 +962,7 @@ class Vector {
|
|
|
969
962
|
isRouteDefinition(value) {
|
|
970
963
|
return value && typeof value === "object" && "entry" in value && "options" in value && "handler" in value;
|
|
971
964
|
}
|
|
972
|
-
logRouteLoaded(
|
|
973
|
-
if (Array.isArray(route)) {
|
|
974
|
-
console.log(` \u2713 Loaded route: ${route[0]} ${route[3] || route[1]}`);
|
|
975
|
-
} else {
|
|
976
|
-
console.log(` \u2713 Loaded route: ${route.method} ${route.path}`);
|
|
977
|
-
}
|
|
978
|
-
}
|
|
965
|
+
logRouteLoaded(_) {}
|
|
979
966
|
stop() {
|
|
980
967
|
if (this.server) {
|
|
981
968
|
this.server.stop();
|
|
@@ -1016,14 +1003,15 @@ import { parseArgs } from "util";
|
|
|
1016
1003
|
|
|
1017
1004
|
// src/core/config-loader.ts
|
|
1018
1005
|
import { existsSync as existsSync2 } from "fs";
|
|
1019
|
-
import { resolve as resolve2 } from "path";
|
|
1006
|
+
import { resolve as resolve2, isAbsolute } from "path";
|
|
1020
1007
|
|
|
1021
1008
|
class ConfigLoader {
|
|
1022
1009
|
configPath;
|
|
1023
1010
|
config = null;
|
|
1024
1011
|
configSource = "default";
|
|
1025
|
-
constructor(configPath
|
|
1026
|
-
|
|
1012
|
+
constructor(configPath) {
|
|
1013
|
+
const path = configPath || "vector.config.ts";
|
|
1014
|
+
this.configPath = isAbsolute(path) ? path : resolve2(process.cwd(), path);
|
|
1027
1015
|
}
|
|
1028
1016
|
async load() {
|
|
1029
1017
|
if (existsSync2(this.configPath)) {
|
|
@@ -1051,22 +1039,15 @@ class ConfigLoader {
|
|
|
1051
1039
|
}
|
|
1052
1040
|
async buildLegacyConfig() {
|
|
1053
1041
|
const config = {};
|
|
1054
|
-
if (this.config
|
|
1055
|
-
config.port = this.config.
|
|
1056
|
-
config.hostname = this.config.
|
|
1057
|
-
config.reusePort = this.config.
|
|
1058
|
-
config.development = this.config.
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
config.routesDir = this.config.routes.dir || "./routes";
|
|
1062
|
-
config.autoDiscover = this.config.routes.autoDiscover !== false;
|
|
1063
|
-
} else if (this.config?.routesDir) {
|
|
1064
|
-
config.routesDir = this.config.routesDir;
|
|
1065
|
-
config.autoDiscover = this.config.autoDiscover !== false;
|
|
1066
|
-
} else {
|
|
1067
|
-
config.routesDir = "./routes";
|
|
1068
|
-
config.autoDiscover = true;
|
|
1042
|
+
if (this.config) {
|
|
1043
|
+
config.port = this.config.port;
|
|
1044
|
+
config.hostname = this.config.hostname;
|
|
1045
|
+
config.reusePort = this.config.reusePort;
|
|
1046
|
+
config.development = this.config.development;
|
|
1047
|
+
config.routesDir = this.config.routesDir || "./routes";
|
|
1048
|
+
config.idleTimeout = this.config.idleTimeout;
|
|
1069
1049
|
}
|
|
1050
|
+
config.autoDiscover = true;
|
|
1070
1051
|
if (this.config?.cors) {
|
|
1071
1052
|
if (typeof this.config.cors === "boolean") {
|
|
1072
1053
|
config.cors = this.config.cors ? {
|
|
@@ -1083,80 +1064,17 @@ class ConfigLoader {
|
|
|
1083
1064
|
}
|
|
1084
1065
|
if (this.config?.before) {
|
|
1085
1066
|
config.before = this.config.before;
|
|
1086
|
-
} else if (this.config?.middleware?.before) {
|
|
1087
|
-
config.before = await this.loadMiddleware(this.config.middleware.before);
|
|
1088
1067
|
}
|
|
1089
1068
|
if (this.config?.after) {
|
|
1090
1069
|
config.finally = this.config.after;
|
|
1091
|
-
} else if (this.config?.middleware?.after) {
|
|
1092
|
-
config.finally = await this.loadMiddleware(this.config.middleware.after);
|
|
1093
1070
|
}
|
|
1094
1071
|
return config;
|
|
1095
1072
|
}
|
|
1096
|
-
async loadMiddleware(paths) {
|
|
1097
|
-
const middleware = [];
|
|
1098
|
-
for (const path of paths) {
|
|
1099
|
-
try {
|
|
1100
|
-
const modulePath = resolve2(process.cwd(), path);
|
|
1101
|
-
const importPath = toFileUrl(modulePath);
|
|
1102
|
-
const module = await import(importPath);
|
|
1103
|
-
const handler = module.default || module;
|
|
1104
|
-
if (typeof handler === "function") {
|
|
1105
|
-
middleware.push(handler);
|
|
1106
|
-
} else {
|
|
1107
|
-
console.warn(`Middleware at ${path} does not export a function`);
|
|
1108
|
-
}
|
|
1109
|
-
} catch (error) {
|
|
1110
|
-
console.error(`Failed to load middleware from ${path}:`, error);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
return middleware;
|
|
1114
|
-
}
|
|
1115
1073
|
async loadAuthHandler() {
|
|
1116
|
-
|
|
1117
|
-
return this.config.auth;
|
|
1118
|
-
}
|
|
1119
|
-
if (!this.config?.handlers?.auth) {
|
|
1120
|
-
return null;
|
|
1121
|
-
}
|
|
1122
|
-
try {
|
|
1123
|
-
const modulePath = resolve2(process.cwd(), this.config.handlers.auth);
|
|
1124
|
-
const importPath = toFileUrl(modulePath);
|
|
1125
|
-
const module = await import(importPath);
|
|
1126
|
-
const handler = module.default || module;
|
|
1127
|
-
if (typeof handler === "function") {
|
|
1128
|
-
return handler;
|
|
1129
|
-
} else {
|
|
1130
|
-
console.warn(`Auth handler at ${this.config.handlers.auth} does not export a function`);
|
|
1131
|
-
return null;
|
|
1132
|
-
}
|
|
1133
|
-
} catch (error) {
|
|
1134
|
-
console.error(`Failed to load auth handler from ${this.config.handlers.auth}:`, error);
|
|
1135
|
-
return null;
|
|
1136
|
-
}
|
|
1074
|
+
return this.config?.auth || null;
|
|
1137
1075
|
}
|
|
1138
1076
|
async loadCacheHandler() {
|
|
1139
|
-
|
|
1140
|
-
return this.config.cache;
|
|
1141
|
-
}
|
|
1142
|
-
if (!this.config?.handlers?.cache) {
|
|
1143
|
-
return null;
|
|
1144
|
-
}
|
|
1145
|
-
try {
|
|
1146
|
-
const modulePath = resolve2(process.cwd(), this.config.handlers.cache);
|
|
1147
|
-
const importPath = toFileUrl(modulePath);
|
|
1148
|
-
const module = await import(importPath);
|
|
1149
|
-
const handler = module.default || module;
|
|
1150
|
-
if (typeof handler === "function") {
|
|
1151
|
-
return handler;
|
|
1152
|
-
} else {
|
|
1153
|
-
console.warn(`Cache handler at ${this.config.handlers.cache} does not export a function`);
|
|
1154
|
-
return null;
|
|
1155
|
-
}
|
|
1156
|
-
} catch (error) {
|
|
1157
|
-
console.error(`Failed to load cache handler from ${this.config.handlers.cache}:`, error);
|
|
1158
|
-
return null;
|
|
1159
|
-
}
|
|
1077
|
+
return this.config?.cache || null;
|
|
1160
1078
|
}
|
|
1161
1079
|
getConfig() {
|
|
1162
1080
|
return this.config;
|
|
@@ -1191,6 +1109,10 @@ var { values, positionals } = parseArgs({
|
|
|
1191
1109
|
cors: {
|
|
1192
1110
|
type: "boolean",
|
|
1193
1111
|
default: true
|
|
1112
|
+
},
|
|
1113
|
+
config: {
|
|
1114
|
+
type: "string",
|
|
1115
|
+
short: "c"
|
|
1194
1116
|
}
|
|
1195
1117
|
},
|
|
1196
1118
|
strict: true,
|
|
@@ -1206,13 +1128,13 @@ async function runDev() {
|
|
|
1206
1128
|
let vector = null;
|
|
1207
1129
|
async function startServer() {
|
|
1208
1130
|
try {
|
|
1209
|
-
const configLoader = new ConfigLoader;
|
|
1131
|
+
const configLoader = new ConfigLoader(values.config);
|
|
1210
1132
|
const config = await configLoader.load();
|
|
1211
1133
|
const configSource = configLoader.getConfigSource();
|
|
1212
1134
|
config.port = config.port ?? Number.parseInt(values.port);
|
|
1213
1135
|
config.hostname = config.hostname ?? values.host;
|
|
1214
1136
|
config.routesDir = config.routesDir ?? values.routes;
|
|
1215
|
-
config.development = isDev;
|
|
1137
|
+
config.development = config.development ?? isDev;
|
|
1216
1138
|
config.autoDiscover = true;
|
|
1217
1139
|
if (!config.cors && values.cors) {
|
|
1218
1140
|
config.cors = {
|
|
@@ -1243,8 +1165,8 @@ async function runDev() {
|
|
|
1243
1165
|
if (isDev && values.watch) {
|
|
1244
1166
|
console.log(` ${gray}Watching${reset} All project files`);
|
|
1245
1167
|
}
|
|
1246
|
-
console.log(` ${gray}CORS${reset} ${
|
|
1247
|
-
console.log(` ${gray}Mode${reset} ${
|
|
1168
|
+
console.log(` ${gray}CORS${reset} ${config.cors ? "Enabled" : "Disabled"}`);
|
|
1169
|
+
console.log(` ${gray}Mode${reset} ${config.development ? "Development" : "Production"}
|
|
1248
1170
|
`);
|
|
1249
1171
|
console.log(` ${green}Ready${reset} \u2192 ${cyan}http://${config.hostname}:${config.port}${reset}
|
|
1250
1172
|
`);
|
|
@@ -1373,6 +1295,7 @@ Options:
|
|
|
1373
1295
|
-h, --host <host> Hostname to bind to (default: localhost)
|
|
1374
1296
|
-r, --routes <dir> Routes directory (default: ./routes)
|
|
1375
1297
|
-w, --watch Watch for file changes (default: true)
|
|
1298
|
+
-c, --config <path> Path to config file (default: vector.config.ts)
|
|
1376
1299
|
--cors Enable CORS (default: true)
|
|
1377
1300
|
`);
|
|
1378
1301
|
process.exit(1);
|
|
@@ -1,13 +1,12 @@
|
|
|
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
|
-
private loadMiddleware;
|
|
11
10
|
loadAuthHandler(): Promise<ProtectedHandler<TTypes> | null>;
|
|
12
11
|
loadCacheHandler(): Promise<CacheHandler | null>;
|
|
13
12
|
getConfig(): VectorConfigSchema<TTypes> | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/core/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
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
|
-
import { existsSync } from
|
|
2
|
-
import { resolve } 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 =
|
|
8
|
-
constructor(configPath
|
|
9
|
-
//
|
|
10
|
-
|
|
7
|
+
configSource = "default";
|
|
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
|
|
@@ -18,19 +22,19 @@ export class ConfigLoader {
|
|
|
18
22
|
const userConfigPath = toFileUrl(this.configPath);
|
|
19
23
|
const userConfig = await import(userConfigPath);
|
|
20
24
|
this.config = userConfig.default || userConfig;
|
|
21
|
-
this.configSource =
|
|
22
|
-
console.log(
|
|
25
|
+
this.configSource = "user";
|
|
26
|
+
console.log(" ✓ User config loaded successfully");
|
|
23
27
|
}
|
|
24
28
|
catch (error) {
|
|
25
29
|
console.error(` ✗ Failed to load config from ${this.configPath}:`, error);
|
|
26
|
-
console.log(
|
|
30
|
+
console.log(" → Using default configuration");
|
|
27
31
|
this.config = {};
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
else {
|
|
31
35
|
// Config file doesn't exist, use defaults
|
|
32
36
|
console.log(` → No config file found at: ${this.configPath}`);
|
|
33
|
-
console.log(
|
|
37
|
+
console.log(" → Using default configuration");
|
|
34
38
|
this.config = {};
|
|
35
39
|
}
|
|
36
40
|
// Convert new config schema to legacy VectorConfig format
|
|
@@ -41,38 +45,27 @@ export class ConfigLoader {
|
|
|
41
45
|
}
|
|
42
46
|
async buildLegacyConfig() {
|
|
43
47
|
const config = {};
|
|
44
|
-
//
|
|
45
|
-
if (this.config
|
|
46
|
-
config.port = this.config.
|
|
47
|
-
config.hostname = this.config.
|
|
48
|
-
config.reusePort = this.config.
|
|
49
|
-
config.development = this.config.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
config.autoDiscover = this.config.routes.autoDiscover !== false;
|
|
56
|
-
}
|
|
57
|
-
else if (this.config?.routesDir) {
|
|
58
|
-
// Legacy format: { routesDir: string }
|
|
59
|
-
config.routesDir = this.config.routesDir;
|
|
60
|
-
config.autoDiscover = this.config.autoDiscover !== false;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
config.routesDir = './routes';
|
|
64
|
-
config.autoDiscover = true;
|
|
65
|
-
}
|
|
48
|
+
// Direct mapping - schemas are now the same (flat)
|
|
49
|
+
if (this.config) {
|
|
50
|
+
config.port = this.config.port;
|
|
51
|
+
config.hostname = this.config.hostname;
|
|
52
|
+
config.reusePort = this.config.reusePort;
|
|
53
|
+
config.development = this.config.development;
|
|
54
|
+
config.routesDir = this.config.routesDir || "./routes";
|
|
55
|
+
config.idleTimeout = this.config.idleTimeout;
|
|
56
|
+
}
|
|
57
|
+
// Always auto-discover routes
|
|
58
|
+
config.autoDiscover = true;
|
|
66
59
|
// CORS configuration
|
|
67
60
|
if (this.config?.cors) {
|
|
68
|
-
if (typeof this.config.cors ===
|
|
61
|
+
if (typeof this.config.cors === "boolean") {
|
|
69
62
|
config.cors = this.config.cors
|
|
70
63
|
? {
|
|
71
|
-
origin:
|
|
64
|
+
origin: "*",
|
|
72
65
|
credentials: true,
|
|
73
|
-
allowHeaders:
|
|
74
|
-
allowMethods:
|
|
75
|
-
exposeHeaders:
|
|
66
|
+
allowHeaders: "Content-Type, Authorization",
|
|
67
|
+
allowMethods: "GET, POST, PUT, PATCH, DELETE, OPTIONS",
|
|
68
|
+
exposeHeaders: "Authorization",
|
|
76
69
|
maxAge: 86400,
|
|
77
70
|
}
|
|
78
71
|
: undefined;
|
|
@@ -81,99 +74,20 @@ export class ConfigLoader {
|
|
|
81
74
|
config.cors = this.config.cors;
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
|
-
//
|
|
77
|
+
// Middleware mapping (VectorConfig uses 'finally' instead of 'after')
|
|
85
78
|
if (this.config?.before) {
|
|
86
|
-
// Direct functions provided
|
|
87
79
|
config.before = this.config.before;
|
|
88
80
|
}
|
|
89
|
-
else if (this.config?.middleware?.before) {
|
|
90
|
-
// File paths provided (legacy)
|
|
91
|
-
config.before = await this.loadMiddleware(this.config.middleware.before);
|
|
92
|
-
}
|
|
93
81
|
if (this.config?.after) {
|
|
94
|
-
// Direct functions provided
|
|
95
82
|
config.finally = this.config.after;
|
|
96
83
|
}
|
|
97
|
-
else if (this.config?.middleware?.after) {
|
|
98
|
-
// File paths provided (legacy)
|
|
99
|
-
config.finally = await this.loadMiddleware(this.config.middleware.after);
|
|
100
|
-
}
|
|
101
84
|
return config;
|
|
102
85
|
}
|
|
103
|
-
async loadMiddleware(paths) {
|
|
104
|
-
const middleware = [];
|
|
105
|
-
for (const path of paths) {
|
|
106
|
-
try {
|
|
107
|
-
const modulePath = resolve(process.cwd(), path);
|
|
108
|
-
const importPath = toFileUrl(modulePath);
|
|
109
|
-
const module = await import(importPath);
|
|
110
|
-
const handler = module.default || module;
|
|
111
|
-
if (typeof handler === 'function') {
|
|
112
|
-
middleware.push(handler);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
console.warn(`Middleware at ${path} does not export a function`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error(`Failed to load middleware from ${path}:`, error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return middleware;
|
|
123
|
-
}
|
|
124
86
|
async loadAuthHandler() {
|
|
125
|
-
|
|
126
|
-
if (this.config?.auth) {
|
|
127
|
-
return this.config.auth;
|
|
128
|
-
}
|
|
129
|
-
// File path provided (legacy)
|
|
130
|
-
if (!this.config?.handlers?.auth) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
const modulePath = resolve(process.cwd(), this.config.handlers.auth);
|
|
135
|
-
const importPath = toFileUrl(modulePath);
|
|
136
|
-
const module = await import(importPath);
|
|
137
|
-
const handler = module.default || module;
|
|
138
|
-
if (typeof handler === 'function') {
|
|
139
|
-
return handler;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
console.warn(`Auth handler at ${this.config.handlers.auth} does not export a function`);
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
console.error(`Failed to load auth handler from ${this.config.handlers.auth}:`, error);
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
87
|
+
return this.config?.auth || null;
|
|
150
88
|
}
|
|
151
89
|
async loadCacheHandler() {
|
|
152
|
-
|
|
153
|
-
if (this.config?.cache) {
|
|
154
|
-
return this.config.cache;
|
|
155
|
-
}
|
|
156
|
-
// File path provided (legacy)
|
|
157
|
-
if (!this.config?.handlers?.cache) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const modulePath = resolve(process.cwd(), this.config.handlers.cache);
|
|
162
|
-
const importPath = toFileUrl(modulePath);
|
|
163
|
-
const module = await import(importPath);
|
|
164
|
-
const handler = module.default || module;
|
|
165
|
-
if (typeof handler === 'function') {
|
|
166
|
-
return handler;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
console.warn(`Cache handler at ${this.config.handlers.cache} does not export a function`);
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
console.error(`Failed to load cache handler from ${this.config.handlers.cache}:`, error);
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
90
|
+
return this.config?.cache || null;
|
|
177
91
|
}
|
|
178
92
|
getConfig() {
|
|
179
93
|
return this.config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/core/config-loader.ts"],"names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AAI,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"}
|