vector-framework 0.9.3 → 0.9.5
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 +9 -5
- package/dist/cli/index.js +42 -15
- package/dist/cli/index.js.map +1 -1
- package/dist/cli.js +33 -112
- 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 +27 -126
- package/dist/core/config-loader.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 +5 -18
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/index.ts +53 -16
- package/src/core/config-loader.ts +36 -138
- 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 +8 -27
package/README.md
CHANGED
|
@@ -16,15 +16,17 @@ 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
|
-
autoDiscover: true, // Auto-discover routes (default: true)
|
|
28
30
|
|
|
29
31
|
// CORS configuration
|
|
30
32
|
cors: {
|
|
@@ -36,6 +38,8 @@ export default {
|
|
|
36
38
|
maxAge: 86400, // Preflight cache duration in seconds
|
|
37
39
|
},
|
|
38
40
|
};
|
|
41
|
+
|
|
42
|
+
export default config;
|
|
39
43
|
```
|
|
40
44
|
|
|
41
45
|
### Your First API (Encore-style)
|
package/dist/cli/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parseArgs } from "node:util";
|
|
|
4
4
|
import { getVectorInstance } from "../core/vector";
|
|
5
5
|
import { ConfigLoader } from "../core/config-loader";
|
|
6
6
|
// Compatibility layer for both Node and Bun
|
|
7
|
-
const args = typeof Bun !==
|
|
7
|
+
const args = typeof Bun !== "undefined" ? Bun.argv.slice(2) : process.argv.slice(2);
|
|
8
8
|
const { values, positionals } = parseArgs({
|
|
9
9
|
args,
|
|
10
10
|
options: {
|
|
@@ -53,8 +53,8 @@ async function runDev() {
|
|
|
53
53
|
config.port = config.port ?? Number.parseInt(values.port);
|
|
54
54
|
config.hostname = config.hostname ?? values.host;
|
|
55
55
|
config.routesDir = config.routesDir ?? values.routes;
|
|
56
|
-
config.development = isDev;
|
|
57
|
-
config.autoDiscover = true;
|
|
56
|
+
config.development = config.development ?? isDev;
|
|
57
|
+
config.autoDiscover = true; // Always auto-discover routes
|
|
58
58
|
// Apply CLI CORS option if not set in config
|
|
59
59
|
if (!config.cors && values.cors) {
|
|
60
60
|
config.cors = {
|
|
@@ -84,13 +84,13 @@ async function runDev() {
|
|
|
84
84
|
const reset = "\x1b[0m";
|
|
85
85
|
const cyan = "\x1b[36m";
|
|
86
86
|
const green = "\x1b[32m";
|
|
87
|
-
console.log(` ${gray}Config${reset} ${configSource ===
|
|
87
|
+
console.log(` ${gray}Config${reset} ${configSource === "user" ? "User config loaded" : "Using defaults"}`);
|
|
88
88
|
console.log(` ${gray}Routes${reset} ${config.routesDir}`);
|
|
89
89
|
if (isDev && values.watch) {
|
|
90
90
|
console.log(` ${gray}Watching${reset} All project files`);
|
|
91
91
|
}
|
|
92
|
-
console.log(` ${gray}CORS${reset} ${
|
|
93
|
-
console.log(` ${gray}Mode${reset} ${
|
|
92
|
+
console.log(` ${gray}CORS${reset} ${config.cors ? "Enabled" : "Disabled"}`);
|
|
93
|
+
console.log(` ${gray}Mode${reset} ${config.development ? "Development" : "Production"}\n`);
|
|
94
94
|
console.log(` ${green}Ready${reset} → ${cyan}http://${config.hostname}:${config.port}${reset}\n`);
|
|
95
95
|
return { server, vector, config };
|
|
96
96
|
}
|
|
@@ -107,25 +107,45 @@ async function runDev() {
|
|
|
107
107
|
if (isDev && values.watch) {
|
|
108
108
|
try {
|
|
109
109
|
let reloadTimeout = null;
|
|
110
|
+
let isReloading = false;
|
|
111
|
+
const changedFiles = new Set();
|
|
112
|
+
let lastReloadTime = 0;
|
|
110
113
|
// Watch entire project directory for changes
|
|
111
114
|
watch(process.cwd(), { recursive: true }, async (_, filename) => {
|
|
115
|
+
// Skip if already reloading or if it's too soon after last reload
|
|
116
|
+
const now = Date.now();
|
|
117
|
+
if (isReloading || now - lastReloadTime < 1000)
|
|
118
|
+
return;
|
|
112
119
|
if (filename &&
|
|
113
120
|
(filename.endsWith(".ts") ||
|
|
114
121
|
filename.endsWith(".js") ||
|
|
115
122
|
filename.endsWith(".json")) &&
|
|
116
123
|
!filename.includes("node_modules") &&
|
|
117
|
-
!filename.includes(".git")
|
|
124
|
+
!filename.includes(".git") &&
|
|
125
|
+
!filename.includes(".vector") && // Ignore generated files
|
|
126
|
+
!filename.includes("dist") && // Ignore dist folder
|
|
127
|
+
!filename.includes("bun.lockb") && // Ignore lock files
|
|
128
|
+
!filename.endsWith(".generated.ts") // Ignore generated files
|
|
129
|
+
) {
|
|
130
|
+
// Track changed files
|
|
131
|
+
changedFiles.add(filename);
|
|
118
132
|
// Debounce reload to avoid multiple restarts
|
|
119
133
|
if (reloadTimeout) {
|
|
120
134
|
clearTimeout(reloadTimeout);
|
|
121
135
|
}
|
|
122
136
|
reloadTimeout = setTimeout(async () => {
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
if (isReloading || changedFiles.size === 0)
|
|
138
|
+
return;
|
|
139
|
+
isReloading = true;
|
|
140
|
+
lastReloadTime = Date.now();
|
|
141
|
+
// Clear changed files
|
|
142
|
+
changedFiles.clear();
|
|
125
143
|
// Stop the current server
|
|
126
144
|
if (vector) {
|
|
127
145
|
vector.stop();
|
|
128
146
|
}
|
|
147
|
+
// Small delay to ensure file system operations complete
|
|
148
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
129
149
|
// Clear module cache to ensure fresh imports
|
|
130
150
|
for (const key in require.cache) {
|
|
131
151
|
if (!key.includes("node_modules")) {
|
|
@@ -136,11 +156,18 @@ async function runDev() {
|
|
|
136
156
|
try {
|
|
137
157
|
const result = await startServer();
|
|
138
158
|
server = result.server;
|
|
159
|
+
vector = result.vector;
|
|
139
160
|
}
|
|
140
161
|
catch (error) {
|
|
141
162
|
console.error(" ❌ Failed to reload server:", error);
|
|
142
163
|
}
|
|
143
|
-
|
|
164
|
+
finally {
|
|
165
|
+
// Reset flag after a delay
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
isReloading = false;
|
|
168
|
+
}, 2000); // 2 second cooldown
|
|
169
|
+
}
|
|
170
|
+
}, 500); // Increased debounce to 500ms
|
|
144
171
|
}
|
|
145
172
|
});
|
|
146
173
|
}
|
|
@@ -165,7 +192,7 @@ async function runBuild() {
|
|
|
165
192
|
await generator.generate(routes);
|
|
166
193
|
console.log(` Generated ${routes.length} routes`);
|
|
167
194
|
// Use spawn based on runtime
|
|
168
|
-
if (typeof Bun !==
|
|
195
|
+
if (typeof Bun !== "undefined") {
|
|
169
196
|
const buildProcess = Bun.spawn([
|
|
170
197
|
"bun",
|
|
171
198
|
"build",
|
|
@@ -178,10 +205,10 @@ async function runBuild() {
|
|
|
178
205
|
}
|
|
179
206
|
else {
|
|
180
207
|
// For Node.js, use child_process
|
|
181
|
-
const { spawnSync } = await import(
|
|
182
|
-
spawnSync(
|
|
183
|
-
stdio:
|
|
184
|
-
shell: true
|
|
208
|
+
const { spawnSync } = await import("child_process");
|
|
209
|
+
spawnSync("bun", ["build", "src/index.ts", "--outdir", "dist", "--minify"], {
|
|
210
|
+
stdio: "inherit",
|
|
211
|
+
shell: true,
|
|
185
212
|
});
|
|
186
213
|
}
|
|
187
214
|
console.log("\n ✓ Build complete\n");
|
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,
|
|
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,M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U,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;;;;;;;;;;;;;;CAcf,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}`);
|
|
@@ -938,7 +931,6 @@ class Vector {
|
|
|
938
931
|
}
|
|
939
932
|
}
|
|
940
933
|
this.router.sortRoutes();
|
|
941
|
-
console.log(`\u2705 Loaded ${routes.length} routes from ${routesDir}`);
|
|
942
934
|
}
|
|
943
935
|
} catch (error) {
|
|
944
936
|
if (error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
@@ -969,13 +961,7 @@ class Vector {
|
|
|
969
961
|
isRouteDefinition(value) {
|
|
970
962
|
return value && typeof value === "object" && "entry" in value && "options" in value && "handler" in value;
|
|
971
963
|
}
|
|
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
|
-
}
|
|
964
|
+
logRouteLoaded(_) {}
|
|
979
965
|
stop() {
|
|
980
966
|
if (this.server) {
|
|
981
967
|
this.server.stop();
|
|
@@ -1051,22 +1037,14 @@ class ConfigLoader {
|
|
|
1051
1037
|
}
|
|
1052
1038
|
async buildLegacyConfig() {
|
|
1053
1039
|
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
|
-
if (this.config?.routes) {
|
|
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;
|
|
1040
|
+
if (this.config) {
|
|
1041
|
+
config.port = this.config.port;
|
|
1042
|
+
config.hostname = this.config.hostname;
|
|
1043
|
+
config.reusePort = this.config.reusePort;
|
|
1044
|
+
config.development = this.config.development;
|
|
1045
|
+
config.routesDir = this.config.routesDir || "./routes";
|
|
1069
1046
|
}
|
|
1047
|
+
config.autoDiscover = true;
|
|
1070
1048
|
if (this.config?.cors) {
|
|
1071
1049
|
if (typeof this.config.cors === "boolean") {
|
|
1072
1050
|
config.cors = this.config.cors ? {
|
|
@@ -1082,89 +1060,18 @@ class ConfigLoader {
|
|
|
1082
1060
|
}
|
|
1083
1061
|
}
|
|
1084
1062
|
if (this.config?.before) {
|
|
1085
|
-
console.log("Using direct before middleware functions:", this.config.before.length);
|
|
1086
1063
|
config.before = this.config.before;
|
|
1087
|
-
} else if (this.config?.middleware?.before) {
|
|
1088
|
-
console.log("Loading before middleware from file paths:", this.config.middleware.before);
|
|
1089
|
-
config.before = await this.loadMiddleware(this.config.middleware.before);
|
|
1090
|
-
console.log("Loaded before middleware:", config.before?.length);
|
|
1091
1064
|
}
|
|
1092
1065
|
if (this.config?.after) {
|
|
1093
|
-
console.log("Using direct after middleware functions:", this.config.after.length);
|
|
1094
1066
|
config.finally = this.config.after;
|
|
1095
|
-
} else if (this.config?.middleware?.after) {
|
|
1096
|
-
console.log("Loading after middleware from file paths:", this.config.middleware.after);
|
|
1097
|
-
config.finally = await this.loadMiddleware(this.config.middleware.after);
|
|
1098
|
-
console.log("Loaded after middleware:", config.finally?.length);
|
|
1099
1067
|
}
|
|
1100
1068
|
return config;
|
|
1101
1069
|
}
|
|
1102
|
-
async loadMiddleware(paths) {
|
|
1103
|
-
const middleware = [];
|
|
1104
|
-
for (const path of paths) {
|
|
1105
|
-
try {
|
|
1106
|
-
const modulePath = resolve2(process.cwd(), path);
|
|
1107
|
-
const importPath = toFileUrl(modulePath);
|
|
1108
|
-
const module = await import(importPath);
|
|
1109
|
-
const handler = module.default || module;
|
|
1110
|
-
if (typeof handler === "function") {
|
|
1111
|
-
middleware.push(handler);
|
|
1112
|
-
} else {
|
|
1113
|
-
console.warn(`Middleware at ${path} does not export a function`);
|
|
1114
|
-
}
|
|
1115
|
-
} catch (error) {
|
|
1116
|
-
console.error(`Failed to load middleware from ${path}:`, error);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
return middleware;
|
|
1120
|
-
}
|
|
1121
1070
|
async loadAuthHandler() {
|
|
1122
|
-
|
|
1123
|
-
console.log("Using direct auth handler function");
|
|
1124
|
-
return this.config.auth;
|
|
1125
|
-
}
|
|
1126
|
-
if (!this.config?.handlers?.auth) {
|
|
1127
|
-
return null;
|
|
1128
|
-
}
|
|
1129
|
-
try {
|
|
1130
|
-
const modulePath = resolve2(process.cwd(), this.config.handlers.auth);
|
|
1131
|
-
const importPath = toFileUrl(modulePath);
|
|
1132
|
-
const module = await import(importPath);
|
|
1133
|
-
const handler = module.default || module;
|
|
1134
|
-
if (typeof handler === "function") {
|
|
1135
|
-
return handler;
|
|
1136
|
-
} else {
|
|
1137
|
-
console.warn(`Auth handler at ${this.config.handlers.auth} does not export a function`);
|
|
1138
|
-
return null;
|
|
1139
|
-
}
|
|
1140
|
-
} catch (error) {
|
|
1141
|
-
console.error(`Failed to load auth handler from ${this.config.handlers.auth}:`, error);
|
|
1142
|
-
return null;
|
|
1143
|
-
}
|
|
1071
|
+
return this.config?.auth || null;
|
|
1144
1072
|
}
|
|
1145
1073
|
async loadCacheHandler() {
|
|
1146
|
-
|
|
1147
|
-
console.log("Using direct cache handler function");
|
|
1148
|
-
return this.config.cache;
|
|
1149
|
-
}
|
|
1150
|
-
if (!this.config?.handlers?.cache) {
|
|
1151
|
-
return null;
|
|
1152
|
-
}
|
|
1153
|
-
try {
|
|
1154
|
-
const modulePath = resolve2(process.cwd(), this.config.handlers.cache);
|
|
1155
|
-
const importPath = toFileUrl(modulePath);
|
|
1156
|
-
const module = await import(importPath);
|
|
1157
|
-
const handler = module.default || module;
|
|
1158
|
-
if (typeof handler === "function") {
|
|
1159
|
-
return handler;
|
|
1160
|
-
} else {
|
|
1161
|
-
console.warn(`Cache handler at ${this.config.handlers.cache} does not export a function`);
|
|
1162
|
-
return null;
|
|
1163
|
-
}
|
|
1164
|
-
} catch (error) {
|
|
1165
|
-
console.error(`Failed to load cache handler from ${this.config.handlers.cache}:`, error);
|
|
1166
|
-
return null;
|
|
1167
|
-
}
|
|
1074
|
+
return this.config?.cache || null;
|
|
1168
1075
|
}
|
|
1169
1076
|
getConfig() {
|
|
1170
1077
|
return this.config;
|
|
@@ -1220,7 +1127,7 @@ async function runDev() {
|
|
|
1220
1127
|
config.port = config.port ?? Number.parseInt(values.port);
|
|
1221
1128
|
config.hostname = config.hostname ?? values.host;
|
|
1222
1129
|
config.routesDir = config.routesDir ?? values.routes;
|
|
1223
|
-
config.development = isDev;
|
|
1130
|
+
config.development = config.development ?? isDev;
|
|
1224
1131
|
config.autoDiscover = true;
|
|
1225
1132
|
if (!config.cors && values.cors) {
|
|
1226
1133
|
config.cors = {
|
|
@@ -1251,8 +1158,8 @@ async function runDev() {
|
|
|
1251
1158
|
if (isDev && values.watch) {
|
|
1252
1159
|
console.log(` ${gray}Watching${reset} All project files`);
|
|
1253
1160
|
}
|
|
1254
|
-
console.log(` ${gray}CORS${reset} ${
|
|
1255
|
-
console.log(` ${gray}Mode${reset} ${
|
|
1161
|
+
console.log(` ${gray}CORS${reset} ${config.cors ? "Enabled" : "Disabled"}`);
|
|
1162
|
+
console.log(` ${gray}Mode${reset} ${config.development ? "Development" : "Production"}
|
|
1256
1163
|
`);
|
|
1257
1164
|
console.log(` ${green}Ready${reset} \u2192 ${cyan}http://${config.hostname}:${config.port}${reset}
|
|
1258
1165
|
`);
|
|
@@ -1268,19 +1175,28 @@ async function runDev() {
|
|
|
1268
1175
|
if (isDev && values.watch) {
|
|
1269
1176
|
try {
|
|
1270
1177
|
let reloadTimeout = null;
|
|
1178
|
+
let isReloading = false;
|
|
1179
|
+
const changedFiles = new Set;
|
|
1180
|
+
let lastReloadTime = 0;
|
|
1271
1181
|
watch(process.cwd(), { recursive: true }, async (_, filename) => {
|
|
1272
|
-
|
|
1182
|
+
const now = Date.now();
|
|
1183
|
+
if (isReloading || now - lastReloadTime < 1000)
|
|
1184
|
+
return;
|
|
1185
|
+
if (filename && (filename.endsWith(".ts") || filename.endsWith(".js") || filename.endsWith(".json")) && !filename.includes("node_modules") && !filename.includes(".git") && !filename.includes(".vector") && !filename.includes("dist") && !filename.includes("bun.lockb") && !filename.endsWith(".generated.ts")) {
|
|
1186
|
+
changedFiles.add(filename);
|
|
1273
1187
|
if (reloadTimeout) {
|
|
1274
1188
|
clearTimeout(reloadTimeout);
|
|
1275
1189
|
}
|
|
1276
1190
|
reloadTimeout = setTimeout(async () => {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1191
|
+
if (isReloading || changedFiles.size === 0)
|
|
1192
|
+
return;
|
|
1193
|
+
isReloading = true;
|
|
1194
|
+
lastReloadTime = Date.now();
|
|
1195
|
+
changedFiles.clear();
|
|
1281
1196
|
if (vector) {
|
|
1282
1197
|
vector.stop();
|
|
1283
1198
|
}
|
|
1199
|
+
await new Promise((resolve3) => setTimeout(resolve3, 100));
|
|
1284
1200
|
for (const key in __require.cache) {
|
|
1285
1201
|
if (!key.includes("node_modules")) {
|
|
1286
1202
|
delete __require.cache[key];
|
|
@@ -1289,10 +1205,15 @@ async function runDev() {
|
|
|
1289
1205
|
try {
|
|
1290
1206
|
const result2 = await startServer();
|
|
1291
1207
|
server = result2.server;
|
|
1208
|
+
vector = result2.vector;
|
|
1292
1209
|
} catch (error) {
|
|
1293
1210
|
console.error(" \u274C Failed to reload server:", error);
|
|
1211
|
+
} finally {
|
|
1212
|
+
setTimeout(() => {
|
|
1213
|
+
isReloading = false;
|
|
1214
|
+
}, 2000);
|
|
1294
1215
|
}
|
|
1295
|
-
},
|
|
1216
|
+
}, 500);
|
|
1296
1217
|
}
|
|
1297
1218
|
});
|
|
1298
1219
|
} catch (err) {
|
|
@@ -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,SAAqB;IAKrC,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAgC3C,eAAe,IAAI,MAAM,GAAG,SAAS;YAIvB,iBAAiB;IA6CzB,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"}
|