@stacksjs/bun-router 0.0.9 → 0.0.11

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/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  middleware
4
- } from "./chunk-n5pvpz7q.js";
4
+ } from "./chunk-1mvtv6jw.js";
5
5
 
6
6
  // src/cli/index.ts
7
7
  import process13 from "process";
@@ -1879,7 +1879,7 @@ var prefix = getPrefix();
1879
1879
  var color18 = __toESM(require_picocolors(), 1);
1880
1880
  var import_picocolors19 = __toESM(require_picocolors(), 1);
1881
1881
  // package.json
1882
- var version = "0.0.9";
1882
+ var version = "0.0.11";
1883
1883
 
1884
1884
  // src/cli/middleware.ts
1885
1885
  import fs from "fs/promises";
package/dist/index.js CHANGED
@@ -66,7 +66,7 @@ import {
66
66
  signRequest,
67
67
  singleFileUpload,
68
68
  verifySignature
69
- } from "./chunk-n5pvpz7q.js";
69
+ } from "./chunk-1mvtv6jw.js";
70
70
 
71
71
  // src/auth.ts
72
72
  function base64UrlEncode(str) {
@@ -10085,6 +10085,21 @@ function registerServerHandling(RouterClass) {
10085
10085
  _cookiesToDelete: []
10086
10086
  });
10087
10087
  RequestWithMacros.applyMacros(enhancedReq);
10088
+ enhancedReq.getParam = (name, defaultValue) => {
10089
+ const value = params?.[name];
10090
+ return value !== undefined ? value : defaultValue;
10091
+ };
10092
+ enhancedReq.cookie = (name, defaultValue) => {
10093
+ const value = getCookies()[name];
10094
+ return value !== undefined ? value : defaultValue ?? null;
10095
+ };
10096
+ if (typeof enhancedReq.get !== "function") {
10097
+ enhancedReq.get = (key, defaultValue) => {
10098
+ const url2 = new URL(req.url);
10099
+ const value = url2.searchParams.get(key);
10100
+ return value !== null && value !== undefined ? value : defaultValue;
10101
+ };
10102
+ }
10088
10103
  Object.assign(enhancedReq, { cookies: { ...getCookies(), ...cookies } });
10089
10104
  return enhancedReq;
10090
10105
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/bun-router",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "description": "A fast, type-safe router for Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -85,7 +85,7 @@
85
85
  "dependencies": {
86
86
  "@stacksjs/clapp": "^0.2.0",
87
87
  "bun-query-builder": "^0.1.13",
88
- "ts-rate-limiter": "^0.4.1"
88
+ "ts-rate-limiter": "^0.4.2"
89
89
  },
90
90
  "lint-staged": {
91
91
  "*.{js,ts}": "bunx --bun pickier . --fix"
@@ -340,6 +340,32 @@ export function registerServerHandling(RouterClass: typeof Router): void {
340
340
  // overwrite the get/set/delete object form consumers depend on.
341
341
  RequestWithMacros.applyMacros(enhancedReq)
342
342
 
343
+ // Attach the helpers consumers reach for that aren't shaped as
344
+ // generic input macros — `getParam`, the function-form `cookie`,
345
+ // the parsed-query `get` shorthand. These mirror the methods the
346
+ // bare `Router.enhanceRequest` (router.ts) attaches; without them
347
+ // here, requests that flow through the registered server.ts
348
+ // override are missing exactly the helpers that frameworks
349
+ // layered on bun-router (Stacks, etc.) treat as guaranteed.
350
+ ;(enhancedReq as any).getParam = <T = string>(name: string, defaultValue?: T): T | undefined => {
351
+ const value = params?.[name] as T | undefined
352
+ return value !== undefined ? value : defaultValue
353
+ }
354
+ ;(enhancedReq as any).cookie = (name: string, defaultValue?: string): string | null => {
355
+ const value = getCookies()[name]
356
+ return value !== undefined ? value : (defaultValue ?? null)
357
+ }
358
+ // `get(key)` — read query params (and only query params; the full
359
+ // input merge with body etc. is provided by the `input` macro).
360
+ // Skip if a macro already registered it under the same name.
361
+ if (typeof (enhancedReq as any).get !== 'function') {
362
+ ;(enhancedReq as any).get = <T = unknown>(key: string, defaultValue?: T): T | undefined => {
363
+ const url = new URL(req.url)
364
+ const value = url.searchParams.get(key) as T | null
365
+ return value !== null && value !== undefined ? value : defaultValue
366
+ }
367
+ }
368
+
343
369
  // Add cookie methods to the request (overrides any macro named `cookies`).
344
370
  Object.assign(enhancedReq, { cookies: { ...getCookies(), ...cookies } })
345
371