bxo 0.0.5-dev.14 → 0.0.5-dev.16

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 +9 -11
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -37,13 +37,11 @@ export type Context<TConfig extends RouteConfig = {}> = {
37
37
  status?: number;
38
38
  headers?: Record<string, string>;
39
39
  };
40
- // Extended properties that can be added by plugins
41
- user?: any;
42
40
  [key: string]: any;
43
41
  };
44
42
 
45
43
  // Handler function type
46
- type Handler<TConfig extends RouteConfig = {}> = (ctx: Context<TConfig>) => Promise<any> | any;
44
+ type Handler<TConfig extends RouteConfig = {}, EC = {}> = (ctx: Context<TConfig> & EC) => Promise<any> | any;
47
45
 
48
46
  // Route definition
49
47
  interface Route {
@@ -251,7 +249,7 @@ export default class BXO {
251
249
  // Route matching utility
252
250
  private matchRoute(method: string, pathname: string): { route: Route; params: Record<string, string> } | null {
253
251
  const allRoutes = this.getAllRoutes();
254
-
252
+
255
253
  for (const route of allRoutes) {
256
254
  if (route.method !== method) continue;
257
255
 
@@ -263,7 +261,7 @@ export default class BXO {
263
261
 
264
262
  // Handle wildcard at the end (catch-all)
265
263
  const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
266
-
264
+
267
265
  if (hasWildcardAtEnd) {
268
266
  // For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
269
267
  if (pathSegments.length < routeSegments.length - 1) continue;
@@ -317,7 +315,7 @@ export default class BXO {
317
315
  // WebSocket route matching utility
318
316
  private matchWSRoute(pathname: string): { route: WSRoute; params: Record<string, string> } | null {
319
317
  const allWSRoutes = this.getAllWSRoutes();
320
-
318
+
321
319
  for (const route of allWSRoutes) {
322
320
  const routeSegments = route.path.split('/').filter(Boolean);
323
321
  const pathSegments = pathname.split('/').filter(Boolean);
@@ -327,7 +325,7 @@ export default class BXO {
327
325
 
328
326
  // Handle wildcard at the end (catch-all)
329
327
  const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
330
-
328
+
331
329
  if (hasWildcardAtEnd) {
332
330
  // For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
333
331
  if (pathSegments.length < routeSegments.length - 1) continue;
@@ -748,7 +746,7 @@ export default class BXO {
748
746
  }));
749
747
 
750
748
  // Get routes from all plugins
751
- const pluginRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
749
+ const pluginRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
752
750
  plugin._routes.map((route: Route) => ({
753
751
  method: route.method,
754
752
  path: route.path,
@@ -777,7 +775,7 @@ export default class BXO {
777
775
  }));
778
776
 
779
777
  // Get WebSocket routes from all plugins
780
- const pluginWsRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
778
+ const pluginWsRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
781
779
  plugin._wsRoutes.map((route: WSRoute) => ({
782
780
  path: route.path,
783
781
  hasHandlers: {
@@ -802,7 +800,7 @@ const error = (error: Error | string, status: number = 500) => {
802
800
  // File helper function (like Elysia)
803
801
  const file = (path: string, options?: { type?: string; headers?: Record<string, string> }) => {
804
802
  const bunFile = Bun.file(path);
805
-
803
+
806
804
  if (options?.type) {
807
805
  // Create a wrapper to override the MIME type
808
806
  return {
@@ -811,7 +809,7 @@ const file = (path: string, options?: { type?: string; headers?: Record<string,
811
809
  headers: options.headers
812
810
  };
813
811
  }
814
-
812
+
815
813
  return bunFile;
816
814
  }
817
815
 
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.14",
4
+ "version": "0.0.5-dev.16",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "devDependencies": {