Skip to content

Commit 37ac46a

Browse files
authored
Release/0.10.0 (#34)
* v0.10.0 - see CHANGELOG for details
1 parent 41c2bc8 commit 37ac46a

File tree

7 files changed

+168
-39
lines changed

7 files changed

+168
-39
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [0.10.0] - 2024-09-08
2+
3+
### Added
4+
5+
- support for `headers` in `ControllerMethodArg` as a shortcut to parse &
6+
retrieve request headers
7+
8+
### Changed
9+
10+
- upgraded dependencies (`@oak/[email protected]`, `@std/[email protected]`
11+
12+
13+
- minor TypeScript syntax updates to better support Deno 2
14+
115
## [0.9.0] - 2024-07-16
216

317
### Changed

deps.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export { join } from "jsr:@std/path@^0.225.2";
1+
export { join } from "jsr:@std/path@^1.0.4";
22

3-
export { Router } from "jsr:@oak/oak@^16.1.0";
3+
export { Router } from "jsr:@oak/oak@^17.0.0";
44

55
export type {
66
Application,
77
Context,
88
Next,
99
RouteContext,
10-
} from "jsr:@oak/oak@^16.1.0";
10+
} from "jsr:@oak/oak@^17.0.0";
1111

1212
import {
1313
extendZodWithOpenApi,

dev_deps.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ export {
55
assertObjectMatch,
66
assertStringIncludes,
77
assertThrows,
8-
} from "jsr:@std/assert@^1.0.0";
8+
} from "jsr:@std/assert@^1.0.4";
99

1010
export {
1111
type BodyType,
1212
type Middleware,
1313
Request,
1414
testing as oakTesting,
15-
} from "jsr:@oak/oak@^16.1.0";
15+
} from "jsr:@oak/oak@^17.0.0";
1616

17-
export { Body } from "jsr:@oak/oak@^16.1.0/body";
17+
export { Body } from "jsr:@oak/oak@^17.0.0/body";
1818

1919
export {
2020
assertSpyCall,
@@ -24,17 +24,17 @@ export {
2424
spy,
2525
type Stub,
2626
stub,
27-
} from "jsr:@std/testing@^0.225.3/mock";
27+
} from "jsr:@std/testing@^1.0.2/mock";
2828

29-
export { assertSnapshot } from "jsr:@std/testing@^0.225.3/snapshot";
29+
export { assertSnapshot } from "jsr:@std/testing@^1.0.2/snapshot";
3030

31-
export { Buffer } from "jsr:@std/io@^0.224.3";
31+
export { Buffer } from "jsr:@std/io@^0.224.7";
3232

3333
export {
3434
afterEach,
3535
beforeEach,
3636
describe,
3737
it,
38-
} from "jsr:@std/testing@^0.225.3/bdd";
38+
} from "jsr:@std/testing@^1.0.2/bdd";
3939

4040
export { ZodObject } from "npm:zod@^3.23.8";

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dklab/oak-routing-ctrl",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"exports": {
55
".": "./mod.ts",
66
"./mod": "./mod.ts"

src/ControllerMethodArgs.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { ERR_UNSUPPORTED_CLASS_METHOD_DECORATOR_RUNTIME_BEHAVIOR } from "./Const
1717
export type ControllerMethodArg =
1818
| "param"
1919
| "body"
20-
| "query";
20+
| "query"
21+
| "headers";
2122

2223
// an enhanced version of a (decorated) method which
2324
// is declared in the (decorated) Controller Class
@@ -127,22 +128,26 @@ function getEnhancedHandler(
127128
try {
128129
parsedReqBody = await _internal.parseOakReqBody(ctx);
129130
} catch (e) {
130-
return ctx.throw(400, `Unable to parse request body: ${e.message}`, {
131-
stack: e.stack,
132-
});
131+
return ctx.throw(
132+
400,
133+
`Unable to parse request body: ${(e as Error).message}`,
134+
{
135+
stack: (e as Error).stack,
136+
},
137+
);
133138
}
134139

135140
const parsedReqSearchParams: Record<string, string> = {};
136141
try {
137-
ctx.request.url.searchParams.forEach((value, key) =>
142+
ctx.request.url.searchParams.forEach((value: string, key: string) =>
138143
parsedReqSearchParams[key] = value
139144
);
140145
} catch (e) {
141146
return ctx.throw(
142147
400,
143-
`Unable to parse request search params: ${e.message}`,
148+
`Unable to parse request search params: ${(e as Error).message}`,
144149
{
145-
stack: e.stack,
150+
stack: (e as Error).stack,
146151
},
147152
);
148153
}
@@ -164,6 +169,13 @@ function getEnhancedHandler(
164169
// search query a.k.a URLSearchParams
165170
decoratedArgs.push(parsedReqSearchParams);
166171
break;
172+
case p === "headers": {
173+
// request headers
174+
const headers: Record<string, string> = {};
175+
ctx.request.headers.forEach((v: string, k: string) => headers[k] = v);
176+
decoratedArgs.push(headers);
177+
break;
178+
}
167179
case ["ctx", "context"].includes(p):
168180
// `ctx` or `context` is supported by default (as the last argument)
169181
// but can also be declared explicitly

0 commit comments

Comments
 (0)