@bunary/http 0.1.0 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -5,6 +5,44 @@ All notable changes to `@bunary/http` will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.3] - 2026-02-15
9
+
10
+ ### Fixed
11
+
12
+ - Path parameters are now decoded with `decodeURIComponent` (#52)
13
+ - `hello%20world` → `"hello world"`, `caf%C3%A9` → `"café"`, emoji and CJK characters decoded correctly
14
+ - Malformed percent-sequences (e.g., `%ZZ`) gracefully return raw value
15
+ - Route constraints now check against decoded values
16
+ - `joinPaths("/", "/users")` no longer returns `"//users"` (#49)
17
+
18
+ ### Added
19
+
20
+ - 83 new unit tests for utility functions and URL encoding behaviour (#49, #52)
21
+ - Direct unit tests for `compilePath()`, `extractParams()`, `checkConstraints()`, `normalizePrefix()`, `joinPaths()`, `toResponse()`
22
+ - Full coverage of URL-encoded paths, unicode, double-encoding, and encoded slashes
23
+
24
+ ## [0.1.2] - 2026-02-15
25
+
26
+ ### Changed
27
+
28
+ - Single-pass route resolution replaces multiple scans of the route table (#42, #48)
29
+ - HEAD requests now resolve in one pass instead of three separate `findRoute()` calls
30
+ - 405 responses reuse allowed-methods collected during matching instead of a second full scan
31
+ - New internal `resolveRoute()` function combines matching, HEAD→GET fallback, and method collection
32
+ - No public API changes — purely internal performance improvement
33
+
34
+ ## [0.1.1] - 2026-02-15
35
+
36
+ ### Fixed
37
+
38
+ - Default error handler no longer leaks `error.message` in production (#44)
39
+ - Returns generic `"Internal Server Error"` when `NODE_ENV=production`
40
+ - Full error message still shown in development and test modes
41
+
42
+ ### Removed
43
+
44
+ - Removed internal `Route` type from public exports — use `RouteInfo` for route metadata (#45)
45
+
8
46
  ## [0.1.0] - 2026-01-31
9
47
 
10
48
  ### Added
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACX,UAAU,EACV,SAAS,EAWT,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAiPzD"}
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACX,UAAU,EACV,SAAS,EAWT,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CA+OzD"}
@@ -2,6 +2,10 @@ import type { AppOptions, RequestContext } from "../types/index.js";
2
2
  /**
3
3
  * Handle 500 Internal Server Error responses.
4
4
  * Uses custom onError handler if provided, otherwise returns default JSON response.
5
+ *
6
+ * In production (`NODE_ENV=production`), the default handler returns a generic
7
+ * "Internal Server Error" message to avoid leaking sensitive information.
8
+ * In development and test, the full error message is included.
5
9
  */
6
10
  export declare function handleError(ctx: RequestContext, error: unknown, options?: AppOptions): Promise<Response>;
7
11
  //# sourceMappingURL=error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/handlers/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEpE;;;GAGG;AACH,wBAAsB,WAAW,CAChC,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,QAAQ,CAAC,CAUnB"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/handlers/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEpE;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAChC,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,QAAQ,CAAC,CAenB"}
@@ -1,5 +1,5 @@
1
1
  export { handleError } from "./error.js";
2
- export { normalizeHeadMethod, toHeadResponse } from "./head.js";
2
+ export { toHeadResponse } from "./head.js";
3
3
  export { handleMethodNotAllowed } from "./methodNotAllowed.js";
4
4
  export { handleNotFound } from "./notFound.js";
5
5
  export { handleOptions } from "./options.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -3,6 +3,9 @@ import type { AppOptions, Route } from "../types/index.js";
3
3
  * Handle 405 Method Not Allowed responses.
4
4
  * Uses custom onMethodNotAllowed handler if provided, otherwise returns default JSON response.
5
5
  * Ensures Allow header is always present.
6
+ *
7
+ * @param precomputed - Pre-computed allowed methods from resolveRoute() to avoid re-scanning.
8
+ * Falls back to scanning routes if not provided.
6
9
  */
7
- export declare function handleMethodNotAllowed(request: Request, path: string, routes: Route[], options?: AppOptions): Promise<Response>;
10
+ export declare function handleMethodNotAllowed(request: Request, path: string, routes: Route[], options?: AppOptions, precomputed?: string[]): Promise<Response>;
8
11
  //# sourceMappingURL=methodNotAllowed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"methodNotAllowed.d.ts","sourceRoot":"","sources":["../../src/handlers/methodNotAllowed.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAkB,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,QAAQ,CAAC,CAgCnB"}
1
+ {"version":3,"file":"methodNotAllowed.d.ts","sourceRoot":"","sources":["../../src/handlers/methodNotAllowed.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAkB,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,CAAC,EAAE,UAAU,EACpB,WAAW,CAAC,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,QAAQ,CAAC,CAgCnB"}
@@ -2,6 +2,9 @@ import type { AppOptions, Route } from "../types/index.js";
2
2
  /**
3
3
  * Handle OPTIONS requests.
4
4
  * Returns 204 with Allow header if path exists, otherwise delegates to 404 handler.
5
+ *
6
+ * Uses a single getAllowedMethods() scan — if the result is non-empty the path
7
+ * exists, avoiding a separate hasMatchingPath() pass.
5
8
  */
6
9
  export declare function handleOptions(request: Request, path: string, routes: Route[], options?: AppOptions): Promise<Response>;
7
10
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/handlers/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;GAGG;AACH,wBAAsB,aAAa,CAClC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,QAAQ,CAAC,CAUnB"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/handlers/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;;;;GAMG;AACH,wBAAsB,aAAa,CAClC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,EAAE,EACf,OAAO,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,QAAQ,CAAC,CAUnB"}
package/dist/index.d.ts CHANGED
@@ -19,5 +19,5 @@
19
19
  * @packageDocumentation
20
20
  */
21
21
  export { createApp } from "./app.js";
22
- export type { AppOptions, BunaryApp, BunaryServer, GroupCallback, GroupOptions, GroupRouter, HandlerResponse, HttpMethod, ListenOptions, Middleware, PathParams, RequestContext, Route, RouteBuilder, RouteHandler, RouteInfo, } from "./types/index.js";
22
+ export type { AppOptions, BunaryApp, BunaryServer, GroupCallback, GroupOptions, GroupRouter, HandlerResponse, HttpMethod, ListenOptions, Middleware, PathParams, RequestContext, RouteBuilder, RouteHandler, RouteInfo, } from "./types/index.js";
23
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,YAAY,EACX,UAAU,EACV,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,EACX,eAAe,EACf,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,cAAc,EACd,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,GACT,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,YAAY,EACX,UAAU,EACV,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,EACX,eAAe,EACf,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,SAAS,GACT,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -31,7 +31,8 @@ async function handleError(ctx, error, options) {
31
31
  const result = await options.onError(ctx, error);
32
32
  return toResponse(result);
33
33
  }
34
- const message = error instanceof Error ? error.message : "Internal server error";
34
+ const isProduction = Bun.env.NODE_ENV === "production";
35
+ const message = isProduction ? "Internal Server Error" : error instanceof Error ? error.message : "Internal server error";
35
36
  return new Response(JSON.stringify({ error: message }), {
36
37
  status: 500,
37
38
  headers: { "Content-Type": "application/json" }
@@ -181,6 +182,13 @@ function compilePath(path) {
181
182
  optionalParams
182
183
  };
183
184
  }
185
+ function safeDecodeURIComponent(value) {
186
+ try {
187
+ return decodeURIComponent(value);
188
+ } catch {
189
+ return value;
190
+ }
191
+ }
184
192
  function extractParams(path, route) {
185
193
  const match = path.match(route.pattern);
186
194
  if (!match)
@@ -189,7 +197,7 @@ function extractParams(path, route) {
189
197
  for (let i = 0;i < route.paramNames.length; i++) {
190
198
  const value = match[i + 1];
191
199
  if (value !== undefined && value !== "") {
192
- params[route.paramNames[i]] = value;
200
+ params[route.paramNames[i]] = safeDecodeURIComponent(value);
193
201
  }
194
202
  }
195
203
  return params;
@@ -208,27 +216,30 @@ function checkConstraints(params, constraints) {
208
216
  }
209
217
 
210
218
  // src/routes/find.ts
211
- function findRoute(routes, method, path) {
219
+ function resolveRoute(routes, method, path) {
220
+ let getFallback = null;
221
+ const allowedMethods = new Set;
212
222
  for (const route of routes) {
213
- if (route.pattern.test(path)) {
214
- if (route.method === method) {
215
- const params = extractParams(path, route);
216
- if (!checkConstraints(params, route.constraints)) {
217
- continue;
218
- }
219
- return { route, params };
220
- }
221
- }
222
- }
223
- return null;
224
- }
225
- function hasMatchingPath(routes, path) {
226
- return routes.some((route) => {
227
223
  if (!route.pattern.test(path))
228
- return false;
224
+ continue;
229
225
  const params = extractParams(path, route);
230
- return checkConstraints(params, route.constraints);
231
- });
226
+ if (!checkConstraints(params, route.constraints))
227
+ continue;
228
+ allowedMethods.add(route.method);
229
+ if (route.method === method) {
230
+ return { match: { route, params }, allowedMethods: [] };
231
+ }
232
+ if (method === "HEAD" && route.method === "GET" && !getFallback) {
233
+ getFallback = { route, params };
234
+ }
235
+ }
236
+ if (getFallback) {
237
+ return { match: getFallback, allowedMethods: [] };
238
+ }
239
+ return {
240
+ match: null,
241
+ allowedMethods: Array.from(allowedMethods).sort()
242
+ };
232
243
  }
233
244
  function getAllowedMethods(routes, path) {
234
245
  const methods = new Set;
@@ -262,6 +273,9 @@ function joinPaths(prefix, path) {
262
273
  if (normalizedPath === "/") {
263
274
  return normalizedPrefix;
264
275
  }
276
+ if (normalizedPrefix === "/") {
277
+ return normalizedPath;
278
+ }
265
279
  return normalizedPrefix + normalizedPath;
266
280
  }
267
281
 
@@ -302,20 +316,6 @@ function createGroupRouter(prefix, groupMiddleware, namePrefix, addRoute) {
302
316
  return router;
303
317
  }
304
318
  // src/handlers/head.ts
305
- function normalizeHeadMethod(method, path, routes) {
306
- if (method !== "HEAD") {
307
- return method;
308
- }
309
- const headMatch = findRoute(routes, "HEAD", path);
310
- if (headMatch) {
311
- return "HEAD";
312
- }
313
- const getMatch = findRoute(routes, "GET", path);
314
- if (getMatch) {
315
- return "GET";
316
- }
317
- return "HEAD";
318
- }
319
319
  function toHeadResponse(response) {
320
320
  return new Response(null, {
321
321
  status: response.status,
@@ -324,9 +324,9 @@ function toHeadResponse(response) {
324
324
  });
325
325
  }
326
326
  // src/handlers/methodNotAllowed.ts
327
- async function handleMethodNotAllowed(request, path, routes, options) {
327
+ async function handleMethodNotAllowed(request, path, routes, options, precomputed) {
328
328
  const url = new URL(request.url);
329
- const allowedMethods = getAllowedMethods(routes, path);
329
+ const allowedMethods = precomputed ?? getAllowedMethods(routes, path);
330
330
  const methodNotAllowedCtx = {
331
331
  request,
332
332
  params: {},
@@ -376,8 +376,8 @@ async function handleNotFound(request, _path, options) {
376
376
  }
377
377
  // src/handlers/options.ts
378
378
  async function handleOptions(request, path, routes, options) {
379
- if (hasMatchingPath(routes, path)) {
380
- const allowedMethods = getAllowedMethods(routes, path);
379
+ const allowedMethods = getAllowedMethods(routes, path);
380
+ if (allowedMethods.length > 0) {
381
381
  return new Response(null, {
382
382
  status: 204,
383
383
  headers: { Allow: allowedMethods.join(", ") }
@@ -439,11 +439,10 @@ function createApp(options) {
439
439
  if (method === "OPTIONS") {
440
440
  return await handleOptions(request, path, routes, options);
441
441
  }
442
- const actualMethod = normalizeHeadMethod(method, path, routes);
443
- const match = findRoute(routes, actualMethod, path);
442
+ const { match, allowedMethods } = resolveRoute(routes, method, path);
444
443
  if (!match) {
445
- if (hasMatchingPath(routes, path)) {
446
- return await handleMethodNotAllowed(request, path, routes, options);
444
+ if (allowedMethods.length > 0) {
445
+ return await handleMethodNotAllowed(request, path, routes, options, allowedMethods);
447
446
  }
448
447
  return await handleNotFound(request, path, options);
449
448
  }
@@ -1 +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"}
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,CAmB9D"}
package/dist/router.d.ts CHANGED
@@ -32,10 +32,11 @@ export declare function compilePath(path: string): CompiledPath;
32
32
  /**
33
33
  * Extract path parameters from a matched route.
34
34
  * Handles optional parameters by only including them if they have values.
35
+ * Applies `decodeURIComponent` to each captured value (standard behaviour).
35
36
  *
36
37
  * @param path - The request path
37
38
  * @param route - The matched route
38
- * @returns Record of parameter names to values (undefined for missing optional params)
39
+ * @returns Record of parameter names to decoded values (undefined for missing optional params)
39
40
  */
40
41
  export declare function extractParams(path: string, route: Route): Record<string, string | undefined>;
41
42
  /**
@@ -1 +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"}
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;AAgBD;;;;;;;;GAQG;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"}
@@ -3,6 +3,29 @@ export interface RouteMatch {
3
3
  route: Route;
4
4
  params: Record<string, string | undefined>;
5
5
  }
6
+ /**
7
+ * Result of a single-pass route resolution.
8
+ *
9
+ * Combines route matching, HEAD→GET fallback, and allowed-method
10
+ * collection into one scan of the route table.
11
+ */
12
+ export interface RouteResolution {
13
+ /** The matched route and extracted params, or null if no match */
14
+ match: RouteMatch | null;
15
+ /** Methods that match this path (populated when match is null and path exists for other methods) */
16
+ allowedMethods: string[];
17
+ }
18
+ /**
19
+ * Resolve a route in a single pass through the route table.
20
+ *
21
+ * For HEAD requests this also checks for a GET fallback.
22
+ * When no exact match is found it collects all methods whose path
23
+ * pattern matches (with constraints), enabling 405 responses and
24
+ * OPTIONS Allow headers without a second scan.
25
+ *
26
+ * **Complexity**: O(n) — one pass regardless of outcome.
27
+ */
28
+ export declare function resolveRoute(routes: Route[], method: string, path: string): RouteResolution;
6
29
  /**
7
30
  * Find a matching route for the given method and path.
8
31
  *
@@ -1 +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;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAYzE"}
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;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,kEAAkE;IAClE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACzB,oGAAoG;IACpG,cAAc,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAiC3F;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;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAYzE"}
@@ -1,4 +1,4 @@
1
1
  export { compilePattern, createRouteBuilder, wrapBuilderWithNamePrefix } from "./builder.js";
2
- export { findRoute, getAllowedMethods, hasMatchingPath, type RouteMatch } from "./find.js";
2
+ export { findRoute, getAllowedMethods, hasMatchingPath, type RouteMatch, type RouteResolution, resolveRoute, } from "./find.js";
3
3
  export { type AddRouteFn, createGroupRouter } from "./group.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,KAAK,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,YAAY,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunary/http",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
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",