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/src/core/vector.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Server } from
|
|
2
|
-
import type { RouteEntry } from
|
|
3
|
-
import { AuthManager } from
|
|
4
|
-
import { CacheManager } from
|
|
5
|
-
import { RouteGenerator } from
|
|
6
|
-
import { RouteScanner } from
|
|
7
|
-
import { MiddlewareManager } from
|
|
8
|
-
import { toFileUrl } from
|
|
1
|
+
import type { Server } from "bun";
|
|
2
|
+
import type { RouteEntry } from "itty-router";
|
|
3
|
+
import { AuthManager } from "../auth/protected";
|
|
4
|
+
import { CacheManager } from "../cache/manager";
|
|
5
|
+
import { RouteGenerator } from "../dev/route-generator";
|
|
6
|
+
import { RouteScanner } from "../dev/route-scanner";
|
|
7
|
+
import { MiddlewareManager } from "../middleware/manager";
|
|
8
|
+
import { toFileUrl } from "../utils/path";
|
|
9
9
|
import type {
|
|
10
10
|
CacheHandler,
|
|
11
11
|
DefaultVectorTypes,
|
|
@@ -14,9 +14,9 @@ import type {
|
|
|
14
14
|
RouteOptions,
|
|
15
15
|
VectorConfig,
|
|
16
16
|
VectorTypes,
|
|
17
|
-
} from
|
|
18
|
-
import { VectorRouter } from
|
|
19
|
-
import { VectorServer } from
|
|
17
|
+
} from "../types";
|
|
18
|
+
import { VectorRouter } from "./router";
|
|
19
|
+
import { VectorServer } from "./server";
|
|
20
20
|
|
|
21
21
|
// Internal-only class - not exposed to users
|
|
22
22
|
export class Vector<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
@@ -72,7 +72,10 @@ export class Vector<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Internal method to add route
|
|
75
|
-
addRoute(
|
|
75
|
+
addRoute(
|
|
76
|
+
options: RouteOptions<TTypes>,
|
|
77
|
+
handler: RouteHandler<TTypes>
|
|
78
|
+
): RouteEntry {
|
|
76
79
|
return this.router.route(options, handler);
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -102,7 +105,7 @@ export class Vector<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
private async discoverRoutes() {
|
|
105
|
-
const routesDir = this.config.routesDir ||
|
|
108
|
+
const routesDir = this.config.routesDir || "./routes";
|
|
106
109
|
|
|
107
110
|
// Always create a new RouteScanner with the current config's routesDir
|
|
108
111
|
// to ensure we're using the correct path from the user's config
|
|
@@ -125,7 +128,8 @@ export class Vector<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
125
128
|
const importPath = toFileUrl(route.path);
|
|
126
129
|
|
|
127
130
|
const module = await import(importPath);
|
|
128
|
-
const exported =
|
|
131
|
+
const exported =
|
|
132
|
+
route.name === "default" ? module.default : module[route.name];
|
|
129
133
|
|
|
130
134
|
if (exported) {
|
|
131
135
|
if (this.isRouteDefinition(exported)) {
|
|
@@ -137,36 +141,41 @@ export class Vector<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
137
141
|
// Legacy support for direct RouteEntry (won't have middleware)
|
|
138
142
|
this.router.addRoute(exported as RouteEntry);
|
|
139
143
|
this.logRouteLoaded(exported as RouteEntry);
|
|
140
|
-
} else if (typeof exported ===
|
|
144
|
+
} else if (typeof exported === "function") {
|
|
141
145
|
this.router.route(route.options as any, exported);
|
|
142
146
|
this.logRouteLoaded(route.options);
|
|
143
147
|
}
|
|
144
148
|
}
|
|
145
149
|
} catch (error) {
|
|
146
|
-
console.error(
|
|
150
|
+
console.error(
|
|
151
|
+
`Failed to load route ${route.name} from ${route.path}:`,
|
|
152
|
+
error
|
|
153
|
+
);
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
// Ensure routes are properly sorted after loading all
|
|
151
158
|
this.router.sortRoutes();
|
|
152
|
-
console.log(`✅ Loaded ${routes.length} routes from ${routesDir}`);
|
|
153
159
|
}
|
|
154
160
|
} catch (error) {
|
|
155
|
-
if (
|
|
156
|
-
|
|
161
|
+
if (
|
|
162
|
+
(error as any).code !== "ENOENT" &&
|
|
163
|
+
(error as any).code !== "ENOTDIR"
|
|
164
|
+
) {
|
|
165
|
+
console.error("Failed to discover routes:", error);
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
async loadRoute(routeModule: any) {
|
|
162
|
-
if (typeof routeModule ===
|
|
171
|
+
if (typeof routeModule === "function") {
|
|
163
172
|
const routeEntry = routeModule();
|
|
164
173
|
if (Array.isArray(routeEntry)) {
|
|
165
174
|
this.router.addRoute(routeEntry as RouteEntry);
|
|
166
175
|
}
|
|
167
|
-
} else if (routeModule && typeof routeModule ===
|
|
176
|
+
} else if (routeModule && typeof routeModule === "object") {
|
|
168
177
|
for (const [, value] of Object.entries(routeModule)) {
|
|
169
|
-
if (typeof value ===
|
|
178
|
+
if (typeof value === "function") {
|
|
170
179
|
const routeEntry = (value as any)();
|
|
171
180
|
if (Array.isArray(routeEntry)) {
|
|
172
181
|
this.router.addRoute(routeEntry as RouteEntry);
|
|
@@ -181,15 +190,17 @@ export class Vector<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
181
190
|
}
|
|
182
191
|
|
|
183
192
|
private isRouteDefinition(value: any): boolean {
|
|
184
|
-
return
|
|
193
|
+
return (
|
|
194
|
+
value &&
|
|
195
|
+
typeof value === "object" &&
|
|
196
|
+
"entry" in value &&
|
|
197
|
+
"options" in value &&
|
|
198
|
+
"handler" in value
|
|
199
|
+
);
|
|
185
200
|
}
|
|
186
201
|
|
|
187
|
-
private logRouteLoaded(
|
|
188
|
-
|
|
189
|
-
console.log(` ✓ Loaded route: ${route[0]} ${route[3] || route[1]}`);
|
|
190
|
-
} else {
|
|
191
|
-
console.log(` ✓ Loaded route: ${route.method} ${route.path}`);
|
|
192
|
-
}
|
|
202
|
+
private logRouteLoaded(_: RouteEntry | RouteOptions): void {
|
|
203
|
+
// Silent - no logging
|
|
193
204
|
}
|
|
194
205
|
|
|
195
206
|
stop(): void {
|
package/src/dev/route-scanner.ts
CHANGED
|
@@ -15,17 +15,11 @@ export class RouteScanner {
|
|
|
15
15
|
|
|
16
16
|
// Check if routes directory exists before attempting to scan
|
|
17
17
|
if (!existsSync(this.routesDir)) {
|
|
18
|
-
console.log(` → Routes directory not found: ${this.routesDir}`);
|
|
19
|
-
console.log(' → No routes will be auto-discovered');
|
|
20
18
|
return [];
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
try {
|
|
24
|
-
console.log(` → Scanning routes from: ${this.routesDir}`);
|
|
25
22
|
await this.scanDirectory(this.routesDir, routes);
|
|
26
|
-
if (routes.length > 0) {
|
|
27
|
-
console.log(` ✓ Found ${routes.length} route${routes.length === 1 ? '' : 's'}`);
|
|
28
|
-
}
|
|
29
23
|
} catch (error) {
|
|
30
24
|
if ((error as any).code === 'ENOENT') {
|
|
31
25
|
console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`);
|
package/src/types/index.ts
CHANGED
|
@@ -83,47 +83,30 @@ 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
|
-
// New config-driven schema
|
|
89
|
+
// New config-driven schema - flat structure
|
|
89
90
|
export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
90
91
|
// Server configuration
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
routes?: {
|
|
100
|
-
dir?: string;
|
|
101
|
-
autoDiscover?: boolean;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// Middleware configuration - supports both file paths and direct functions
|
|
105
|
-
middleware?: {
|
|
106
|
-
before?: string[];
|
|
107
|
-
after?: string[];
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Direct middleware functions (preferred approach)
|
|
92
|
+
port?: number;
|
|
93
|
+
hostname?: string;
|
|
94
|
+
reusePort?: boolean;
|
|
95
|
+
development?: boolean;
|
|
96
|
+
routesDir?: string;
|
|
97
|
+
idleTimeout?: number;
|
|
98
|
+
|
|
99
|
+
// Middleware functions
|
|
111
100
|
before?: BeforeMiddlewareHandler<TTypes>[];
|
|
112
101
|
after?: AfterMiddlewareHandler<TTypes>[];
|
|
113
|
-
|
|
114
|
-
// Handler
|
|
115
|
-
handlers?: {
|
|
116
|
-
auth?: string;
|
|
117
|
-
cache?: string;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Direct handler functions (preferred approach)
|
|
102
|
+
|
|
103
|
+
// Handler functions
|
|
121
104
|
auth?: ProtectedHandler<TTypes>;
|
|
122
105
|
cache?: CacheHandler;
|
|
123
|
-
|
|
106
|
+
|
|
124
107
|
// CORS configuration
|
|
125
108
|
cors?: CorsOptions | boolean;
|
|
126
|
-
|
|
109
|
+
|
|
127
110
|
// Custom types for TypeScript
|
|
128
111
|
types?: VectorTypes;
|
|
129
112
|
}
|