@bunary/http 0.0.2 → 0.0.4
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 +166 -3
- package/dist/app.d.ts +7 -25
- package/dist/app.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +342 -41
- package/dist/pathUtils.d.ts +34 -0
- package/dist/pathUtils.d.ts.map +1 -0
- package/dist/response.d.ts +26 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/router.d.ts +49 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/routes/builder.d.ts +17 -0
- package/dist/routes/builder.d.ts.map +1 -0
- package/dist/routes/find.d.ts +27 -0
- package/dist/routes/find.d.ts.map +1 -0
- package/dist/routes/group.d.ts +7 -0
- package/dist/routes/group.d.ts.map +1 -0
- package/dist/routes/index.d.ts +4 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/types/appOptions.d.ts +8 -0
- package/dist/types/appOptions.d.ts.map +1 -0
- package/dist/types/bunaryApp.d.ts +97 -0
- package/dist/types/bunaryApp.d.ts.map +1 -0
- package/dist/types/bunaryServer.d.ts +14 -0
- package/dist/types/bunaryServer.d.ts.map +1 -0
- package/dist/types/groupOptions.d.ts +13 -0
- package/dist/types/groupOptions.d.ts.map +1 -0
- package/dist/types/groupRouter.d.ts +26 -0
- package/dist/types/groupRouter.d.ts.map +1 -0
- package/dist/types/handlerResponse.d.ts +8 -0
- package/dist/types/handlerResponse.d.ts.map +1 -0
- package/dist/types/httpMethod.d.ts +5 -0
- package/dist/types/httpMethod.d.ts.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/middleware.d.ts +21 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/pathParams.d.ts +6 -0
- package/dist/types/pathParams.d.ts.map +1 -0
- package/dist/types/queryParams.d.ts +5 -0
- package/dist/types/queryParams.d.ts.map +1 -0
- package/dist/types/requestContext.d.ts +22 -0
- package/dist/types/requestContext.d.ts.map +1 -0
- package/dist/types/route.d.ts +27 -0
- package/dist/types/route.d.ts.map +1 -0
- package/dist/types/routeBuilder.d.ts +24 -0
- package/dist/types/routeBuilder.d.ts.map +1 -0
- package/dist/types/routeHandler.d.ts +17 -0
- package/dist/types/routeHandler.d.ts.map +1 -0
- package/dist/types/routeInfo.d.ts +13 -0
- package/dist/types/routeInfo.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path manipulation utilities for route handling.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a path prefix (ensure leading slash, no trailing slash).
|
|
6
|
+
*
|
|
7
|
+
* @param prefix - Path prefix to normalize
|
|
8
|
+
* @returns Normalized prefix with leading slash and no trailing slash
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* normalizePrefix("api") // "/api"
|
|
13
|
+
* normalizePrefix("/api/") // "/api"
|
|
14
|
+
* normalizePrefix("/") // "/"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function normalizePrefix(prefix: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Join path segments, handling slashes correctly.
|
|
20
|
+
*
|
|
21
|
+
* @param prefix - Path prefix
|
|
22
|
+
* @param path - Path to append
|
|
23
|
+
* @returns Combined path
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* joinPaths("/api", "/users") // "/api/users"
|
|
28
|
+
* joinPaths("/api", "users") // "/api/users"
|
|
29
|
+
* joinPaths("/api/", "/users") // "/api/users"
|
|
30
|
+
* joinPaths("/", "/") // "/"
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function joinPaths(prefix: string, path: string): string;
|
|
34
|
+
//# sourceMappingURL=pathUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../src/pathUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAStD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAc9D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response conversion utilities for route handlers.
|
|
3
|
+
*/
|
|
4
|
+
import type { HandlerResponse } from "./types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Convert a handler response to a proper Response object.
|
|
7
|
+
*
|
|
8
|
+
* Handles the following response types:
|
|
9
|
+
* - Response: passed through unchanged
|
|
10
|
+
* - null/undefined: 204 No Content
|
|
11
|
+
* - string: text/plain response
|
|
12
|
+
* - number: text/plain response
|
|
13
|
+
* - object/array: JSON response
|
|
14
|
+
*
|
|
15
|
+
* @param result - The handler return value
|
|
16
|
+
* @returns A proper Response object
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* toResponse({ message: "Hello" }); // JSON response
|
|
21
|
+
* toResponse("Hello"); // text/plain response
|
|
22
|
+
* toResponse(null); // 204 No Content
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function toResponse(result: HandlerResponse): Response;
|
|
26
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,QAAQ,CAgC5D"}
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route matching utilities for compiling paths and extracting parameters.
|
|
3
|
+
*/
|
|
4
|
+
import type { Route } from "./types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Result of compiling a path pattern.
|
|
7
|
+
*/
|
|
8
|
+
export interface CompiledPath {
|
|
9
|
+
/** Regex pattern for matching */
|
|
10
|
+
pattern: RegExp;
|
|
11
|
+
/** Parameter names in order */
|
|
12
|
+
paramNames: string[];
|
|
13
|
+
/** Names of optional parameters */
|
|
14
|
+
optionalParams: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compile a path pattern into a regex and extract parameter names.
|
|
18
|
+
* Supports optional parameters with :param? syntax.
|
|
19
|
+
*
|
|
20
|
+
* @param path - Route path pattern (e.g., "/users/:id" or "/users/:id?")
|
|
21
|
+
* @returns Object with regex pattern, parameter names, and optional param names
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const { pattern, paramNames, optionalParams } = compilePath("/users/:id?");
|
|
26
|
+
* // pattern matches "/users" and "/users/123"
|
|
27
|
+
* // paramNames = ["id"]
|
|
28
|
+
* // optionalParams = ["id"]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function compilePath(path: string): CompiledPath;
|
|
32
|
+
/**
|
|
33
|
+
* Extract path parameters from a matched route.
|
|
34
|
+
* Handles optional parameters by only including them if they have values.
|
|
35
|
+
*
|
|
36
|
+
* @param path - The request path
|
|
37
|
+
* @param route - The matched route
|
|
38
|
+
* @returns Record of parameter names to values (undefined for missing optional params)
|
|
39
|
+
*/
|
|
40
|
+
export declare function extractParams(path: string, route: Route): Record<string, string | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if route constraints are satisfied.
|
|
43
|
+
*
|
|
44
|
+
* @param params - Extracted route parameters
|
|
45
|
+
* @param constraints - Parameter constraints (regex patterns)
|
|
46
|
+
* @returns True if all constraints pass
|
|
47
|
+
*/
|
|
48
|
+
export declare function checkConstraints(params: Record<string, string | undefined>, constraints?: Record<string, RegExp>): boolean;
|
|
49
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,mCAAmC;IACnC,cAAc,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAmCtD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAa5F;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAC1C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAUT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BunaryApp, Route, RouteBuilder } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Safely compile a string pattern to RegExp with error handling.
|
|
4
|
+
* Provides better error messages for invalid regex patterns.
|
|
5
|
+
*/
|
|
6
|
+
export declare function compilePattern(pattern: string, param: string): RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Create a RouteBuilder for a specific route.
|
|
9
|
+
* Each builder captures its own route reference to avoid shared mutable state issues.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRouteBuilder(route: Route, namedRoutes: Map<string, Route>, app: BunaryApp): RouteBuilder;
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a route builder to auto-apply name prefix.
|
|
14
|
+
* Uses a Proxy to maintain dynamic getter behavior from the original builder.
|
|
15
|
+
*/
|
|
16
|
+
export declare function wrapBuilderWithNamePrefix(builder: RouteBuilder, namePrefix: string): RouteBuilder;
|
|
17
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/routes/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAExE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOrE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,EAC/B,GAAG,EAAE,SAAS,GACZ,YAAY,CAmHd;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,CAajG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Route } from "../types/index.js";
|
|
2
|
+
export interface RouteMatch {
|
|
3
|
+
route: Route;
|
|
4
|
+
params: Record<string, string | undefined>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Find a matching route for the given method and path.
|
|
8
|
+
*
|
|
9
|
+
* **Complexity**: O(n) where n is the number of registered routes.
|
|
10
|
+
* Routes are tested sequentially until a match is found.
|
|
11
|
+
*
|
|
12
|
+
* This linear search is suitable for most applications (up to ~100 routes).
|
|
13
|
+
* For applications with hundreds of routes, consider:
|
|
14
|
+
* - Grouping routes by common prefixes (reduces regex tests per request)
|
|
15
|
+
* - Using method-based route maps (the 405 "Method Not Allowed" check already
|
|
16
|
+
* iterates separately, so grouping by method could help)
|
|
17
|
+
* - Implementing a radix/prefix tree for static path segments
|
|
18
|
+
*
|
|
19
|
+
* The current design prioritizes simplicity and correctness. Route order matters:
|
|
20
|
+
* the first matching route wins, allowing intentional route shadowing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function findRoute(routes: Route[], method: string, path: string): RouteMatch | null;
|
|
23
|
+
/**
|
|
24
|
+
* Check if any route matches the path (regardless of method).
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasMatchingPath(routes: Route[], path: string): boolean;
|
|
27
|
+
//# sourceMappingURL=find.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../src/routes/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAc1F;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMtE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GroupRouter, Middleware, RouteBuilder, RouteHandler } from "../types/index.js";
|
|
2
|
+
export type AddRouteFn = (method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH", path: string, handler: RouteHandler, groupMiddleware?: Middleware[]) => RouteBuilder;
|
|
3
|
+
/**
|
|
4
|
+
* Create a group router for defining routes within a group.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createGroupRouter(prefix: string, groupMiddleware: Middleware[], namePrefix: string, addRoute: AddRouteFn): GroupRouter;
|
|
7
|
+
//# sourceMappingURL=group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/routes/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGX,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,MAAM,mBAAmB,CAAC;AAG3B,MAAM,MAAM,UAAU,GAAG,CACxB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,EACnD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,EACrB,eAAe,CAAC,EAAE,UAAU,EAAE,KAC1B,YAAY,CAAC;AAElB;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,UAAU,EAAE,EAC7B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,UAAU,GAClB,WAAW,CAoDb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appOptions.d.ts","sourceRoot":"","sources":["../../src/types/appOptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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,22 @@
|
|
|
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
|
+
//# 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;CACvB"}
|
|
@@ -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"}
|