Skip to content

Commit 3e84526

Browse files
committed
v0.14.0 - see CHANGELOG for details
1 parent 994c5de commit 3e84526

16 files changed

+441
-21
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
## [0.14.0] - 2025-02-03
2+
3+
## Changed
4+
5+
- multiple paths can now be registered on the same HTTP verb, and if the
6+
"static" and the "parameter" portions of the registered paths somehow overlap,
7+
then the handler is invoked **once for each matched path**; for example if we
8+
register `@Get("/foo/:bar")` and `@Get("/foo/bar")` (in that order) on the
9+
same handler function, then for every request to `/foo/bar`, the same handler
10+
is invoked **twice**, the first time having no "param" at all, and the 2nd
11+
time having the param `bar` with the value `"bar"`. This behavior follows TC39
12+
decorator specs where all decorators to a function are applied "from inside
13+
out" aka: the last declared decorator gets applied first, and so on
14+
15+
## Added
16+
17+
- `ctx.state._oakRoutingCtrl_regPath` is available as a pointer to the
18+
registered path that matches the URL request currently being handled; this is
19+
helpful in rare situations where multiple similar paths are registered on the
20+
same handler function, causing it to be invoked multiple times, and so we need
21+
a machanism to control when to write to the response body (as it can only be
22+
done once)
23+
124
## [0.13.0] - 2025-02-01
225

326
### Added

deno.jsonc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dklab/oak-routing-ctrl",
3-
"version": "0.13.0",
3+
"version": "0.14.0",
44
"exports": {
55
".": "./mod.ts",
66
"./mod": "./mod.ts"
@@ -15,7 +15,7 @@
1515
},
1616
"tasks": {
1717
"pretty": "deno lint --ignore=docs && deno check . && deno fmt",
18-
"test": "deno test -RE",
18+
"test": "deno test -REI -N=0.0.0.0,127.0.0.1",
1919
"check-doc": "deno check --doc .",
2020
"doc": "deno doc --html mod.ts"
2121
},
@@ -26,7 +26,8 @@
2626
"@std/io": "jsr:@std/io@^0.225.2",
2727
"@std/path": "jsr:@std/path@^1.0.8",
2828
"@std/testing": "jsr:@std/testing@^1.0.9",
29-
"zod": "npm:zod@^3.24.1"
29+
"zod": "npm:zod@^3.24.1",
30+
"superoak": "https://deno.land/x/[email protected]/mod.ts"
3031
},
3132
"fmt": {
3233
"useTabs": false,

deno.lock

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ export {
1818
z,
1919
type zInfer,
2020
} from "./src/utils/schema_utils.ts";
21+
22+
export type {
23+
/**
24+
* re-exporting from oak for convenient uses
25+
* @ignore
26+
*/
27+
Context,
28+
} from "@oak/oak";

src/Controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ export const Controller =
3535
for (const fnName of fnNames) {
3636
const pair = store.get(fnName);
3737
if (!pair) continue;
38-
pair.forEach((path, verb, p) => {
38+
const patchedPair = new Map();
39+
pair.forEach((verb, path) => {
3940
const fullPath = join(pathPrefix, path);
40-
p.set(verb, fullPath);
41+
patchedPair.set(fullPath, verb);
4142
patchOasPath(fnName, verb, fullPath);
4243
});
44+
store.set(fnName, patchedPair);
4345
}
4446
};

src/Delete_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Deno.test("@Delete decorator", () => {
2323
assertSpyCall(Delete, 0, { args: ["/bar"] });
2424
assertInstanceOf(Delete.calls[0].returned, Function);
2525
assertSpyCalls(Delete, 1);
26-
assertEquals(store.get("doSomething")?.get("delete"), "/bar");
26+
assertEquals(store.get("doSomething")?.get("/bar"), "delete");
2727
});

src/Get_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Deno.test("@Get decorator", () => {
2323
assertSpyCall(Get, 0, { args: ["/bar"] });
2424
assertInstanceOf(Get.calls[0].returned, Function);
2525
assertSpyCalls(Get, 1);
26-
assertEquals(store.get("doSomething")?.get("get"), "/bar");
26+
assertEquals(store.get("doSomething")?.get("/bar"), "get");
2727
});

src/Head_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Deno.test("@Head decorator", () => {
2323
assertSpyCall(Head, 0, { args: ["/bar"] });
2424
assertInstanceOf(Head.calls[0].returned, Function);
2525
assertSpyCalls(Head, 1);
26-
assertEquals(store.get("doSomething")?.get("head"), "/bar");
26+
assertEquals(store.get("doSomething")?.get("/bar"), "head");
2727
});

src/Options_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Deno.test("@Options decorator", () => {
2323
assertSpyCall(Options, 0, { args: ["/bar"] });
2424
assertInstanceOf(Options.calls[0].returned, Function);
2525
assertSpyCalls(Options, 1);
26-
assertEquals(store.get("doSomething")?.get("options"), "/bar");
26+
assertEquals(store.get("doSomething")?.get("/bar"), "options");
2727
});

src/Patch_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Deno.test("@Patch decorator", () => {
2323
assertSpyCall(Patch, 0, { args: ["/bar"] });
2424
assertInstanceOf(Patch.calls[0].returned, Function);
2525
assertSpyCalls(Patch, 1);
26-
assertEquals(store.get("doSomething")?.get("patch"), "/bar");
26+
assertEquals(store.get("doSomething")?.get("/bar"), "patch");
2727
});

0 commit comments

Comments
 (0)