Skip to content

Commit

Permalink
chore: update deps and changes for Deno 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Oct 7, 2024
1 parent b4fb1e4 commit d1fd693
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"respondable",
"valibot"
],
"deno.unstable": true
"deno.unstable": ["kv"]
}
2 changes: 1 addition & 1 deletion context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class Context<
});
if (location) {
if (params) {
const toPath = compile(location, { strict: true });
const toPath = compile(location);
response.headers.set("location", toPath(params));
} else {
response.headers.set("location", location);
Expand Down
12 changes: 6 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
"tasks": {
"bench": "deno bench --allow-write --allow-read",
"check": "deno check mod.ts",
"example": "deno run --allow-net --allow-env --allow-hrtime --unstable-kv _examples/server.ts",
"test": "deno test --allow-net --allow-env --allow-hrtime"
"example": "deno run --allow-net --allow-env --unstable-kv _examples/server.ts",
"test": "deno test --allow-net --allow-env"
},
"imports": {
"@oak/commons": "jsr:@oak/commons@^1.0",
"@std/assert": "jsr:@std/assert@^1.0",
"@std/http": "jsr:@std/http@^1.0",
"@std/log": "jsr:@std/log@^0.224",
"@std/media-types": "jsr:@std/media-types@^1.0",
"@valibot/valibot": "jsr:@valibot/valibot@^0.39",
"hyperid": "npm:hyperid@^3.2",
"path-to-regexp": "npm:path-to-regexp@^7.1",
"qs": "npm:qs@^6.12"
"@valibot/valibot": "jsr:@valibot/valibot@^0.42",
"hyperid": "npm:hyperid@^3.3",
"path-to-regexp": "npm:path-to-regexp@^8.2",
"qs": "npm:qs@^6.13"
},
"lock": false
}
4 changes: 2 additions & 2 deletions request_server_bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { createHttpError } from "@oak/commons/http_errors";
import { Status } from "@oak/commons/status";
import hyperid from "hyperid";
import process from "node:process";

import type {
Addr,
Expand Down Expand Up @@ -102,8 +103,7 @@ class BunRequestEvent<
}

get env(): Env {
// @ts-ignore available when running under Bun
return process.env;
return process.env as Env;
}

get request(): Request {
Expand Down
4 changes: 2 additions & 2 deletions request_server_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Status } from "@oak/commons/status";
import hyperid from "hyperid";
import type { IncomingMessage, ServerResponse } from "node:http";
import type { AddressInfo } from "node:net";
import process from "node:process";

import type {
Addr,
Expand Down Expand Up @@ -43,8 +44,7 @@ class NodeRequestEvent<Env extends Record<string, string>>
}

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

get id(): string {
Expand Down
15 changes: 8 additions & 7 deletions route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class PathRoute<
#params?: Params;
#paramKeys: Key[];
#path: Path;
#regex: RegExp & { keys: Key[] };
#regexp: RegExp;
#schema: Schema<QSSchema, BSchema, ResSchema>;

/**
Expand Down Expand Up @@ -154,7 +154,7 @@ export class PathRoute<
* The path pattern that has been converted into {@linkcode RegExp}.
*/
get regex(): RegExp {
return this.#regex;
return this.#regexp;
}

/**
Expand Down Expand Up @@ -189,8 +189,9 @@ export class PathRoute<
this.#handler = handler;
this.#keys = keys;
this.#expose = expose;
this.#regex = pathToRegexp(path, { ...options, strict: true });
this.#paramKeys = this.#regex.keys;
const { regexp, keys: paramKeys } = pathToRegexp(path, { ...options });
this.#regexp = regexp;
this.#paramKeys = paramKeys;
this.#logger = getLogger("acorn.route");
this.#logger
.debug(`created route with path: ${path} and methods: ${methods}`);
Expand Down Expand Up @@ -268,7 +269,7 @@ export class PathRoute<
* Determines if the request should be handled by the route.
*/
matches(method: HttpMethod, pathname: string): boolean | NotAllowed {
const match = pathname.match(this.#regex);
const match = pathname.match(this.#regexp);
if (match) {
if (!this.#methods.includes(method)) {
return NOT_ALLOWED;
Expand Down Expand Up @@ -297,7 +298,7 @@ export class PathRoute<
inspect({
params: this.#params,
path: this.#path,
regex: this.#regex,
regex: this.#regexp,
schema: this.#schema,
})
}`;
Expand All @@ -321,7 +322,7 @@ export class PathRoute<
inspect({
params: this.#params,
path: this.#path,
regex: this.#regex,
regex: this.#regexp,
schema: this.#schema,
}, newOptions)
}`;
Expand Down
12 changes: 12 additions & 0 deletions routing.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pathToRegexp as pathToRegexp7 } from "npm:[email protected]";
import { pathToRegexp as pathToRegexp71 } from "npm:[email protected]";
import { pathToRegexp as pathToRegexp8 } from "npm:[email protected]";
import { pathToRegexp } from "npm:[email protected]";
import { URLPattern as URLPatternPolyfill } from "npm:[email protected]";

Expand Down Expand Up @@ -60,3 +61,14 @@ Deno.bench({
}
},
});

const { regexp: regexp8 } = pathToRegexp8("/book/:id");

Deno.bench({
name: "pathToRegexp 8",
fn() {
if (regexp8.exec("/book/1234")) {
true;
}
},
});
3 changes: 2 additions & 1 deletion utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ export function isBun(): boolean {
/** Determines if the runtime is Node.js or not. */
export function isNode(): boolean {
return "process" in globalThis && "global" in globalThis &&
!("Bun" in globalThis) && !("WebSocketPair" in globalThis);
!("Bun" in globalThis) && !("WebSocketPair" in globalThis) &&
!("Deno" in globalThis);
}
17 changes: 17 additions & 0 deletions uuid.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import hyperid from "hyperid";

const instance = hyperid({ urlSafe: true });

Deno.bench({
name: "hyperid",
fn() {
instance();
},
});

Deno.bench({
name: "crypto.randomUUID",
fn() {
crypto.randomUUID();
},
});

0 comments on commit d1fd693

Please sign in to comment.