bxo 0.0.5-dev.12 → 0.0.5-dev.15

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.
Files changed (2) hide show
  1. package/index.ts +30 -9
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -43,7 +43,7 @@ export type Context<TConfig extends RouteConfig = {}> = {
43
43
  };
44
44
 
45
45
  // Handler function type
46
- type Handler<TConfig extends RouteConfig = {}> = (ctx: Context<TConfig>) => Promise<any> | any;
46
+ type Handler<TConfig extends RouteConfig = {}, EC = {}> = (ctx: Context<TConfig> & EC) => Promise<any> | any;
47
47
 
48
48
  // Route definition
49
49
  interface Route {
@@ -231,9 +231,28 @@ export default class BXO {
231
231
  return this;
232
232
  }
233
233
 
234
+ // Helper methods to get all routes including plugin routes
235
+ private getAllRoutes(): Route[] {
236
+ const allRoutes = [...this._routes];
237
+ for (const plugin of this.plugins) {
238
+ allRoutes.push(...plugin._routes);
239
+ }
240
+ return allRoutes;
241
+ }
242
+
243
+ private getAllWSRoutes(): WSRoute[] {
244
+ const allWSRoutes = [...this._wsRoutes];
245
+ for (const plugin of this.plugins) {
246
+ allWSRoutes.push(...plugin._wsRoutes);
247
+ }
248
+ return allWSRoutes;
249
+ }
250
+
234
251
  // Route matching utility
235
252
  private matchRoute(method: string, pathname: string): { route: Route; params: Record<string, string> } | null {
236
- for (const route of this._routes) {
253
+ const allRoutes = this.getAllRoutes();
254
+
255
+ for (const route of allRoutes) {
237
256
  if (route.method !== method) continue;
238
257
 
239
258
  const routeSegments = route.path.split('/').filter(Boolean);
@@ -244,7 +263,7 @@ export default class BXO {
244
263
 
245
264
  // Handle wildcard at the end (catch-all)
246
265
  const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
247
-
266
+
248
267
  if (hasWildcardAtEnd) {
249
268
  // For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
250
269
  if (pathSegments.length < routeSegments.length - 1) continue;
@@ -297,7 +316,9 @@ export default class BXO {
297
316
 
298
317
  // WebSocket route matching utility
299
318
  private matchWSRoute(pathname: string): { route: WSRoute; params: Record<string, string> } | null {
300
- for (const route of this._wsRoutes) {
319
+ const allWSRoutes = this.getAllWSRoutes();
320
+
321
+ for (const route of allWSRoutes) {
301
322
  const routeSegments = route.path.split('/').filter(Boolean);
302
323
  const pathSegments = pathname.split('/').filter(Boolean);
303
324
 
@@ -306,7 +327,7 @@ export default class BXO {
306
327
 
307
328
  // Handle wildcard at the end (catch-all)
308
329
  const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
309
-
330
+
310
331
  if (hasWildcardAtEnd) {
311
332
  // For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
312
333
  if (pathSegments.length < routeSegments.length - 1) continue;
@@ -727,7 +748,7 @@ export default class BXO {
727
748
  }));
728
749
 
729
750
  // Get routes from all plugins
730
- const pluginRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
751
+ const pluginRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
731
752
  plugin._routes.map((route: Route) => ({
732
753
  method: route.method,
733
754
  path: route.path,
@@ -756,7 +777,7 @@ export default class BXO {
756
777
  }));
757
778
 
758
779
  // Get WebSocket routes from all plugins
759
- const pluginWsRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
780
+ const pluginWsRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
760
781
  plugin._wsRoutes.map((route: WSRoute) => ({
761
782
  path: route.path,
762
783
  hasHandlers: {
@@ -781,7 +802,7 @@ const error = (error: Error | string, status: number = 500) => {
781
802
  // File helper function (like Elysia)
782
803
  const file = (path: string, options?: { type?: string; headers?: Record<string, string> }) => {
783
804
  const bunFile = Bun.file(path);
784
-
805
+
785
806
  if (options?.type) {
786
807
  // Create a wrapper to override the MIME type
787
808
  return {
@@ -790,7 +811,7 @@ const file = (path: string, options?: { type?: string; headers?: Record<string,
790
811
  headers: options.headers
791
812
  };
792
813
  }
793
-
814
+
794
815
  return bunFile;
795
816
  }
796
817
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bxo",
3
3
  "module": "index.ts",
4
- "version": "0.0.5-dev.12",
4
+ "version": "0.0.5-dev.15",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "devDependencies": {