@bunary/http 0.0.2 → 0.0.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +170 -3
  3. package/dist/app.d.ts +7 -25
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +344 -42
  8. package/dist/pathUtils.d.ts +34 -0
  9. package/dist/pathUtils.d.ts.map +1 -0
  10. package/dist/response.d.ts +26 -0
  11. package/dist/response.d.ts.map +1 -0
  12. package/dist/router.d.ts +49 -0
  13. package/dist/router.d.ts.map +1 -0
  14. package/dist/routes/builder.d.ts +17 -0
  15. package/dist/routes/builder.d.ts.map +1 -0
  16. package/dist/routes/find.d.ts +27 -0
  17. package/dist/routes/find.d.ts.map +1 -0
  18. package/dist/routes/group.d.ts +7 -0
  19. package/dist/routes/group.d.ts.map +1 -0
  20. package/dist/routes/index.d.ts +4 -0
  21. package/dist/routes/index.d.ts.map +1 -0
  22. package/dist/types/appOptions.d.ts +8 -0
  23. package/dist/types/appOptions.d.ts.map +1 -0
  24. package/dist/types/bunaryApp.d.ts +97 -0
  25. package/dist/types/bunaryApp.d.ts.map +1 -0
  26. package/dist/types/bunaryServer.d.ts +14 -0
  27. package/dist/types/bunaryServer.d.ts.map +1 -0
  28. package/dist/types/groupOptions.d.ts +13 -0
  29. package/dist/types/groupOptions.d.ts.map +1 -0
  30. package/dist/types/groupRouter.d.ts +26 -0
  31. package/dist/types/groupRouter.d.ts.map +1 -0
  32. package/dist/types/handlerResponse.d.ts +8 -0
  33. package/dist/types/handlerResponse.d.ts.map +1 -0
  34. package/dist/types/httpMethod.d.ts +5 -0
  35. package/dist/types/httpMethod.d.ts.map +1 -0
  36. package/dist/types/index.d.ts +19 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/dist/types/middleware.d.ts +21 -0
  39. package/dist/types/middleware.d.ts.map +1 -0
  40. package/dist/types/pathParams.d.ts +6 -0
  41. package/dist/types/pathParams.d.ts.map +1 -0
  42. package/dist/types/queryParams.d.ts +5 -0
  43. package/dist/types/queryParams.d.ts.map +1 -0
  44. package/dist/types/requestContext.d.ts +36 -0
  45. package/dist/types/requestContext.d.ts.map +1 -0
  46. package/dist/types/route.d.ts +27 -0
  47. package/dist/types/route.d.ts.map +1 -0
  48. package/dist/types/routeBuilder.d.ts +24 -0
  49. package/dist/types/routeBuilder.d.ts.map +1 -0
  50. package/dist/types/routeHandler.d.ts +17 -0
  51. package/dist/types/routeHandler.d.ts.map +1 -0
  52. package/dist/types/routeInfo.d.ts +13 -0
  53. package/dist/types/routeInfo.d.ts.map +1 -0
  54. package/package.json +5 -1
@@ -0,0 +1,97 @@
1
+ import type { BunaryServer } from "./bunaryServer.js";
2
+ import type { GroupOptions } from "./groupOptions.js";
3
+ import type { GroupCallback } from "./groupRouter.js";
4
+ import type { Middleware } from "./middleware.js";
5
+ import type { RouteBuilder } from "./routeBuilder.js";
6
+ import type { RouteHandler } from "./routeHandler.js";
7
+ import type { RouteInfo } from "./routeInfo.js";
8
+ /**
9
+ * The Bunary application instance for HTTP routing and middleware.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const app = createApp();
14
+ *
15
+ * app.get("/", () => ({ message: "Hello!" }));
16
+ * app.get("/users/:id", (ctx) => ({ id: ctx.params.id }));
17
+ *
18
+ * app.listen(3000);
19
+ * ```
20
+ */
21
+ export interface BunaryApp {
22
+ /**
23
+ * Register a GET route.
24
+ * @param path - URL path pattern (supports :param and :param? syntax)
25
+ * @param handler - Function to handle requests
26
+ */
27
+ get: (path: string, handler: RouteHandler) => RouteBuilder;
28
+ /**
29
+ * Register a POST route.
30
+ * @param path - URL path pattern (supports :param and :param? syntax)
31
+ * @param handler - Function to handle requests
32
+ */
33
+ post: (path: string, handler: RouteHandler) => RouteBuilder;
34
+ /**
35
+ * Register a PUT route.
36
+ * @param path - URL path pattern (supports :param and :param? syntax)
37
+ * @param handler - Function to handle requests
38
+ */
39
+ put: (path: string, handler: RouteHandler) => RouteBuilder;
40
+ /**
41
+ * Register a DELETE route.
42
+ * @param path - URL path pattern (supports :param and :param? syntax)
43
+ * @param handler - Function to handle requests
44
+ */
45
+ delete: (path: string, handler: RouteHandler) => RouteBuilder;
46
+ /**
47
+ * Register a PATCH route.
48
+ * @param path - URL path pattern (supports :param and :param? syntax)
49
+ * @param handler - Function to handle requests
50
+ */
51
+ patch: (path: string, handler: RouteHandler) => RouteBuilder;
52
+ /**
53
+ * Add middleware to the request pipeline.
54
+ * Middleware executes in registration order.
55
+ * @param middleware - Middleware function
56
+ */
57
+ use: (middleware: Middleware) => BunaryApp;
58
+ /**
59
+ * Create a route group with shared prefix, middleware, or name prefix.
60
+ * @param prefix - URL prefix for all routes in the group
61
+ * @param callback - Function to define routes within the group
62
+ */
63
+ group: ((prefix: string, callback: GroupCallback) => BunaryApp) & ((options: GroupOptions, callback: GroupCallback) => BunaryApp);
64
+ /**
65
+ * Generate a URL for a named route.
66
+ * @param name - The route name
67
+ * @param params - Route parameters and query string values
68
+ * @returns The generated URL path
69
+ * @throws If route name not found or required params missing
70
+ */
71
+ route: (name: string, params?: Record<string, string | number>) => string;
72
+ /**
73
+ * Check if a named route exists.
74
+ * @param name - The route name to check
75
+ * @returns True if the route exists
76
+ */
77
+ hasRoute: (name: string) => boolean;
78
+ /**
79
+ * Get a list of all registered routes.
80
+ * @returns Array of route information objects
81
+ */
82
+ getRoutes: () => RouteInfo[];
83
+ /**
84
+ * Start the HTTP server.
85
+ * @param port - Port number to listen on (default: 3000)
86
+ * @param hostname - Hostname to bind to (default: "localhost")
87
+ * @returns Server instance with stop() method
88
+ */
89
+ listen: (port?: number, hostname?: string) => BunaryServer;
90
+ /**
91
+ * Handle an incoming request (used internally and for testing).
92
+ * @param request - The incoming Request object
93
+ * @returns Response object
94
+ */
95
+ fetch: (request: Request) => Promise<Response>;
96
+ }
97
+ //# sourceMappingURL=bunaryApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bunaryApp.d.ts","sourceRoot":"","sources":["../../src/types/bunaryApp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,SAAS;IACzB;;;;OAIG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAE3D;;;;OAIG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAE5D;;;;OAIG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAE3D;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAE9D;;;;OAIG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAE7D;;;;OAIG;IACH,GAAG,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,SAAS,CAAC;IAE3C;;;;OAIG;IACH,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,SAAS,CAAC,GAC9D,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC;IAEjE;;;;;;OAMG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,MAAM,CAAC;IAE1E;;;;OAIG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAEpC;;;OAGG;IACH,SAAS,EAAE,MAAM,SAAS,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,YAAY,CAAC;IAE3D;;;;OAIG;IACH,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC/C"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Server instance returned by app.listen().
3
+ */
4
+ export interface BunaryServer {
5
+ /** The underlying Bun server */
6
+ server: ReturnType<typeof Bun.serve>;
7
+ /** Stop the server */
8
+ stop: () => void;
9
+ /** Port the server is listening on */
10
+ port: number;
11
+ /** Hostname the server is bound to */
12
+ hostname: string;
13
+ }
14
+ //# sourceMappingURL=bunaryServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bunaryServer.d.ts","sourceRoot":"","sources":["../../src/types/bunaryServer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,gCAAgC;IAChC,MAAM,EAAE,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACrC,sBAAsB;IACtB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,13 @@
1
+ import type { Middleware } from "./middleware.js";
2
+ /**
3
+ * Options for route groups.
4
+ */
5
+ export interface GroupOptions {
6
+ /** URL prefix for all routes in the group */
7
+ prefix: string;
8
+ /** Middleware to apply to all routes in the group */
9
+ middleware?: Middleware[];
10
+ /** Name prefix for all routes in the group */
11
+ name?: string;
12
+ }
13
+ //# sourceMappingURL=groupOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupOptions.d.ts","sourceRoot":"","sources":["../../src/types/groupOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;IAC1B,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1,26 @@
1
+ import type { GroupOptions } from "./groupOptions.js";
2
+ import type { RouteBuilder } from "./routeBuilder.js";
3
+ import type { RouteHandler } from "./routeHandler.js";
4
+ /**
5
+ * Router interface for route groups.
6
+ * Provides the same routing methods as BunaryApp but scoped to a group.
7
+ */
8
+ export interface GroupRouter {
9
+ /** Register a GET route */
10
+ get: (path: string, handler: RouteHandler) => RouteBuilder;
11
+ /** Register a POST route */
12
+ post: (path: string, handler: RouteHandler) => RouteBuilder;
13
+ /** Register a PUT route */
14
+ put: (path: string, handler: RouteHandler) => RouteBuilder;
15
+ /** Register a DELETE route */
16
+ delete: (path: string, handler: RouteHandler) => RouteBuilder;
17
+ /** Register a PATCH route */
18
+ patch: (path: string, handler: RouteHandler) => RouteBuilder;
19
+ /** Create a nested route group */
20
+ group: ((prefix: string, callback: GroupCallback) => GroupRouter) & ((options: GroupOptions, callback: GroupCallback) => GroupRouter);
21
+ }
22
+ /**
23
+ * Callback function for defining routes within a group.
24
+ */
25
+ export type GroupCallback = (router: GroupRouter) => void;
26
+ //# sourceMappingURL=groupRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupRouter.d.ts","sourceRoot":"","sources":["../../src/types/groupRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,2BAA2B;IAC3B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAC3D,4BAA4B;IAC5B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAC5D,2BAA2B;IAC3B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAC3D,8BAA8B;IAC9B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAC9D,6BAA6B;IAC7B,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAC7D,kCAAkC;IAClC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,WAAW,CAAC,GAChE,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,KAAK,WAAW,CAAC,CAAC;CACnE;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Return type for route handlers.
3
+ * - Objects/arrays are automatically serialized to JSON.
4
+ * - Response objects are passed through unchanged.
5
+ * - Primitives (string, number) are converted to text responses.
6
+ */
7
+ export type HandlerResponse = Response | object | string | number | null | undefined;
8
+ //# sourceMappingURL=handlerResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlerResponse.d.ts","sourceRoot":"","sources":["../../src/types/handlerResponse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * HTTP method types supported by the router.
3
+ */
4
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
5
+ //# sourceMappingURL=httpMethod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpMethod.d.ts","sourceRoot":"","sources":["../../src/types/httpMethod.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @bunary/http - Type Definitions
3
+ */
4
+ export type { AppOptions } from "./appOptions.js";
5
+ export type { BunaryApp } from "./bunaryApp.js";
6
+ export type { BunaryServer } from "./bunaryServer.js";
7
+ export type { GroupCallback, GroupRouter } from "./groupRouter.js";
8
+ export type { GroupOptions } from "./groupOptions.js";
9
+ export type { HandlerResponse } from "./handlerResponse.js";
10
+ export type { HttpMethod } from "./httpMethod.js";
11
+ export type { Middleware } from "./middleware.js";
12
+ export type { PathParams } from "./pathParams.js";
13
+ export type { QueryParams } from "./queryParams.js";
14
+ export type { RequestContext } from "./requestContext.js";
15
+ export type { Route } from "./route.js";
16
+ export type { RouteBuilder } from "./routeBuilder.js";
17
+ export type { RouteHandler } from "./routeHandler.js";
18
+ export type { RouteInfo } from "./routeInfo.js";
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACnE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { HandlerResponse } from "./handlerResponse.js";
2
+ import type { RequestContext } from "./requestContext.js";
3
+ /**
4
+ * Middleware function for processing requests in a pipeline.
5
+ *
6
+ * @param ctx - The request context
7
+ * @param next - Function to call the next middleware or route handler
8
+ * @returns Response data or void (if next() handles it)
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const logger: Middleware = async (ctx, next) => {
13
+ * console.log(`${ctx.request.method} ${ctx.request.url}`);
14
+ * const response = await next();
15
+ * console.log("Response sent");
16
+ * return response;
17
+ * };
18
+ * ```
19
+ */
20
+ export type Middleware = (ctx: RequestContext, next: () => Promise<HandlerResponse>) => HandlerResponse | Promise<HandlerResponse>;
21
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/types/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,GAAG,CACxB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,KAChC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Path parameters extracted from route patterns (e.g., `/users/:id` → `{ id: "123" }`).
3
+ * Optional parameters may be undefined when not provided.
4
+ */
5
+ export type PathParams = Record<string, string | undefined>;
6
+ //# sourceMappingURL=pathParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathParams.d.ts","sourceRoot":"","sources":["../../src/types/pathParams.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Query parameters parsed from the URL search string.
3
+ */
4
+ export type QueryParams = Record<string, string | string[]>;
5
+ //# sourceMappingURL=queryParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryParams.d.ts","sourceRoot":"","sources":["../../src/types/queryParams.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { PathParams } from "./pathParams.js";
2
+ /**
3
+ * Context object passed to route handlers containing request data.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * app.get("/users/:id", (ctx) => {
8
+ * console.log(ctx.params.id); // "123"
9
+ * console.log(ctx.query.get("sort")); // "name"
10
+ * return { id: ctx.params.id };
11
+ * });
12
+ * ```
13
+ */
14
+ export interface RequestContext {
15
+ /** The original Bun Request object */
16
+ request: Request;
17
+ /** Path parameters extracted from the route pattern */
18
+ params: PathParams;
19
+ /** Query parameters from the URL search string */
20
+ query: URLSearchParams;
21
+ /**
22
+ * Per-request storage for middleware and handlers.
23
+ *
24
+ * This object is **initialized per request** (never shared across requests).
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * app.use(async (ctx, next) => {
29
+ * ctx.locals.userId = "123";
30
+ * return await next();
31
+ * });
32
+ * ```
33
+ */
34
+ locals: Record<string, unknown>;
35
+ }
36
+ //# sourceMappingURL=requestContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestContext.d.ts","sourceRoot":"","sources":["../../src/types/requestContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,cAAc;IAC9B,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,uDAAuD;IACvD,MAAM,EAAE,UAAU,CAAC;IACnB,kDAAkD;IAClD,KAAK,EAAE,eAAe,CAAC;IACvB;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC"}
@@ -0,0 +1,27 @@
1
+ import type { HttpMethod } from "./httpMethod.js";
2
+ import type { Middleware } from "./middleware.js";
3
+ import type { RouteHandler } from "./routeHandler.js";
4
+ /**
5
+ * Internal route definition stored by the router.
6
+ */
7
+ export interface Route {
8
+ /** HTTP method for this route */
9
+ method: HttpMethod;
10
+ /** Route path pattern (e.g., "/users/:id") */
11
+ path: string;
12
+ /** Compiled regex for matching */
13
+ pattern: RegExp;
14
+ /** Parameter names extracted from path */
15
+ paramNames: string[];
16
+ /** Handler function for this route */
17
+ handler: RouteHandler;
18
+ /** Optional route name for URL generation */
19
+ name?: string;
20
+ /** Parameter constraints (regex patterns) */
21
+ constraints?: Record<string, RegExp>;
22
+ /** Route-specific middleware */
23
+ middleware?: Middleware[];
24
+ /** Names of optional parameters */
25
+ optionalParams?: string[];
26
+ }
27
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/types/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,KAAK;IACrB,iCAAiC;IACjC,MAAM,EAAE,UAAU,CAAC;IACnB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,sCAAsC;IACtC,OAAO,EAAE,YAAY,CAAC;IACtB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,gCAAgC;IAChC,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;IAC1B,mCAAmC;IACnC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B"}
@@ -0,0 +1,24 @@
1
+ import type { BunaryApp } from "./bunaryApp.js";
2
+ /**
3
+ * Fluent builder for route configuration.
4
+ * Allows chaining methods like name(), where(), etc.
5
+ */
6
+ export interface RouteBuilder extends BunaryApp {
7
+ /** Assign a name to the route for URL generation */
8
+ name: (name: string) => RouteBuilder;
9
+ /** Add a regex constraint to a route parameter */
10
+ where: ((param: string, pattern: RegExp | string) => RouteBuilder) & ((constraints: Record<string, RegExp | string>) => RouteBuilder);
11
+ /** Constrain parameter to digits only */
12
+ whereNumber: (param: string) => RouteBuilder;
13
+ /** Constrain parameter to letters only */
14
+ whereAlpha: (param: string) => RouteBuilder;
15
+ /** Constrain parameter to letters and digits only */
16
+ whereAlphaNumeric: (param: string) => RouteBuilder;
17
+ /** Constrain parameter to UUID format */
18
+ whereUuid: (param: string) => RouteBuilder;
19
+ /** Constrain parameter to ULID format */
20
+ whereUlid: (param: string) => RouteBuilder;
21
+ /** Constrain parameter to specific allowed values */
22
+ whereIn: (param: string, values: string[]) => RouteBuilder;
23
+ }
24
+ //# sourceMappingURL=routeBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routeBuilder.d.ts","sourceRoot":"","sources":["../../src/types/routeBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC9C,oDAAoD;IACpD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,YAAY,CAAC;IACrC,kDAAkD;IAClD,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,KAAK,YAAY,CAAC,GACjE,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,YAAY,CAAC,CAAC;IAClE,yCAAyC;IACzC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;IAC7C,0CAA0C;IAC1C,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;IAC5C,qDAAqD;IACrD,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;IACnD,yCAAyC;IACzC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;IAC3C,yCAAyC;IACzC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,YAAY,CAAC;IAC3C,qDAAqD;IACrD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,YAAY,CAAC;CAC3D"}
@@ -0,0 +1,17 @@
1
+ import type { HandlerResponse } from "./handlerResponse.js";
2
+ import type { RequestContext } from "./requestContext.js";
3
+ /**
4
+ * Route handler function that processes incoming requests.
5
+ *
6
+ * @param ctx - The request context containing request, params, and query
7
+ * @returns Response data (object for JSON, Response for custom, or primitive)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const handler: RouteHandler = (ctx) => {
12
+ * return { message: "Hello, World!" };
13
+ * };
14
+ * ```
15
+ */
16
+ export type RouteHandler = (ctx: RequestContext) => HandlerResponse | Promise<HandlerResponse>;
17
+ //# sourceMappingURL=routeHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routeHandler.d.ts","sourceRoot":"","sources":["../../src/types/routeHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { HttpMethod } from "./httpMethod.js";
2
+ /**
3
+ * Route information returned by getRoutes().
4
+ */
5
+ export interface RouteInfo {
6
+ /** Route name (null if unnamed) */
7
+ name: string | null;
8
+ /** HTTP method */
9
+ method: HttpMethod;
10
+ /** Route path pattern */
11
+ path: string;
12
+ }
13
+ //# sourceMappingURL=routeInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routeInfo.d.ts","sourceRoot":"","sources":["../../src/types/routeInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,mCAAmC;IACnC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,kBAAkB;IAClB,MAAM,EAAE,UAAU,CAAC;IACnB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;CACb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunary/http",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "HTTP routing and middleware for Bunary - a Bun-first backend framework inspired by Laravel",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -37,6 +37,10 @@
37
37
  "type": "git",
38
38
  "url": "https://github.com/bunary-dev/http.git"
39
39
  },
40
+ "homepage": "https://github.com/bunary-dev/http#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/bunary-dev/http/issues"
43
+ },
40
44
  "engines": {
41
45
  "bun": ">=1.0.0"
42
46
  },