Skip to content

Commit d1fd693

Browse files
committed
chore: update deps and changes for Deno 2
1 parent b4fb1e4 commit d1fd693

File tree

9 files changed

+51
-20
lines changed

9 files changed

+51
-20
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"respondable",
66
"valibot"
77
],
8-
"deno.unstable": true
8+
"deno.unstable": ["kv"]
99
}

context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class Context<
321321
});
322322
if (location) {
323323
if (params) {
324-
const toPath = compile(location, { strict: true });
324+
const toPath = compile(location);
325325
response.headers.set("location", toPath(params));
326326
} else {
327327
response.headers.set("location", location);

deno.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
"tasks": {
1616
"bench": "deno bench --allow-write --allow-read",
1717
"check": "deno check mod.ts",
18-
"example": "deno run --allow-net --allow-env --allow-hrtime --unstable-kv _examples/server.ts",
19-
"test": "deno test --allow-net --allow-env --allow-hrtime"
18+
"example": "deno run --allow-net --allow-env --unstable-kv _examples/server.ts",
19+
"test": "deno test --allow-net --allow-env"
2020
},
2121
"imports": {
2222
"@oak/commons": "jsr:@oak/commons@^1.0",
2323
"@std/assert": "jsr:@std/assert@^1.0",
2424
"@std/http": "jsr:@std/http@^1.0",
2525
"@std/log": "jsr:@std/log@^0.224",
2626
"@std/media-types": "jsr:@std/media-types@^1.0",
27-
"@valibot/valibot": "jsr:@valibot/valibot@^0.39",
28-
"hyperid": "npm:hyperid@^3.2",
29-
"path-to-regexp": "npm:path-to-regexp@^7.1",
30-
"qs": "npm:qs@^6.12"
27+
"@valibot/valibot": "jsr:@valibot/valibot@^0.42",
28+
"hyperid": "npm:hyperid@^3.3",
29+
"path-to-regexp": "npm:path-to-regexp@^8.2",
30+
"qs": "npm:qs@^6.13"
3131
},
3232
"lock": false
3333
}

request_server_bun.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { createHttpError } from "@oak/commons/http_errors";
44
import { Status } from "@oak/commons/status";
55
import hyperid from "hyperid";
6+
import process from "node:process";
67

78
import type {
89
Addr,
@@ -102,8 +103,7 @@ class BunRequestEvent<
102103
}
103104

104105
get env(): Env {
105-
// @ts-ignore available when running under Bun
106-
return process.env;
106+
return process.env as Env;
107107
}
108108

109109
get request(): Request {

request_server_node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Status } from "@oak/commons/status";
55
import hyperid from "hyperid";
66
import type { IncomingMessage, ServerResponse } from "node:http";
77
import type { AddressInfo } from "node:net";
8+
import process from "node:process";
89

910
import type {
1011
Addr,
@@ -43,8 +44,7 @@ class NodeRequestEvent<Env extends Record<string, string>>
4344
}
4445

4546
get env(): Env {
46-
// @ts-ignore available when running under Node.js
47-
return process.env;
47+
return process.env as Env;
4848
}
4949

5050
get id(): string {

route.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class PathRoute<
123123
#params?: Params;
124124
#paramKeys: Key[];
125125
#path: Path;
126-
#regex: RegExp & { keys: Key[] };
126+
#regexp: RegExp;
127127
#schema: Schema<QSSchema, BSchema, ResSchema>;
128128

129129
/**
@@ -154,7 +154,7 @@ export class PathRoute<
154154
* The path pattern that has been converted into {@linkcode RegExp}.
155155
*/
156156
get regex(): RegExp {
157-
return this.#regex;
157+
return this.#regexp;
158158
}
159159

160160
/**
@@ -189,8 +189,9 @@ export class PathRoute<
189189
this.#handler = handler;
190190
this.#keys = keys;
191191
this.#expose = expose;
192-
this.#regex = pathToRegexp(path, { ...options, strict: true });
193-
this.#paramKeys = this.#regex.keys;
192+
const { regexp, keys: paramKeys } = pathToRegexp(path, { ...options });
193+
this.#regexp = regexp;
194+
this.#paramKeys = paramKeys;
194195
this.#logger = getLogger("acorn.route");
195196
this.#logger
196197
.debug(`created route with path: ${path} and methods: ${methods}`);
@@ -268,7 +269,7 @@ export class PathRoute<
268269
* Determines if the request should be handled by the route.
269270
*/
270271
matches(method: HttpMethod, pathname: string): boolean | NotAllowed {
271-
const match = pathname.match(this.#regex);
272+
const match = pathname.match(this.#regexp);
272273
if (match) {
273274
if (!this.#methods.includes(method)) {
274275
return NOT_ALLOWED;
@@ -297,7 +298,7 @@ export class PathRoute<
297298
inspect({
298299
params: this.#params,
299300
path: this.#path,
300-
regex: this.#regex,
301+
regex: this.#regexp,
301302
schema: this.#schema,
302303
})
303304
}`;
@@ -321,7 +322,7 @@ export class PathRoute<
321322
inspect({
322323
params: this.#params,
323324
path: this.#path,
324-
regex: this.#regex,
325+
regex: this.#regexp,
325326
schema: this.#schema,
326327
}, newOptions)
327328
}`;

routing.bench.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { pathToRegexp as pathToRegexp7 } from "npm:[email protected]";
22
import { pathToRegexp as pathToRegexp71 } from "npm:[email protected]";
3+
import { pathToRegexp as pathToRegexp8 } from "npm:[email protected]";
34
import { pathToRegexp } from "npm:[email protected]";
45
import { URLPattern as URLPatternPolyfill } from "npm:[email protected]";
56

@@ -60,3 +61,14 @@ Deno.bench({
6061
}
6162
},
6263
});
64+
65+
const { regexp: regexp8 } = pathToRegexp8("/book/:id");
66+
67+
Deno.bench({
68+
name: "pathToRegexp 8",
69+
fn() {
70+
if (regexp8.exec("/book/1234")) {
71+
true;
72+
}
73+
},
74+
});

utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ export function isBun(): boolean {
5353
/** Determines if the runtime is Node.js or not. */
5454
export function isNode(): boolean {
5555
return "process" in globalThis && "global" in globalThis &&
56-
!("Bun" in globalThis) && !("WebSocketPair" in globalThis);
56+
!("Bun" in globalThis) && !("WebSocketPair" in globalThis) &&
57+
!("Deno" in globalThis);
5758
}

uuid.bench.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import hyperid from "hyperid";
2+
3+
const instance = hyperid({ urlSafe: true });
4+
5+
Deno.bench({
6+
name: "hyperid",
7+
fn() {
8+
instance();
9+
},
10+
});
11+
12+
Deno.bench({
13+
name: "crypto.randomUUID",
14+
fn() {
15+
crypto.randomUUID();
16+
},
17+
});

0 commit comments

Comments
 (0)