From d6f9d382fea5f5dc3fe445e3d01c02899e9de244 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 5 Sep 2024 17:20:32 +1000 Subject: [PATCH] chore: migrate to std and commons v1 --- context.ts | 4 ---- deps.ts | 46 +++++++++++++++++++++++----------------------- deps_test.ts | 12 ++++++------ middleware/etag.ts | 5 +++-- response.test.ts | 2 +- send.test.ts | 10 +++++----- send.ts | 8 ++++---- 7 files changed, 42 insertions(+), 45 deletions(-) diff --git a/context.ts b/context.ts index fe95eaa..e94cf9c 100644 --- a/context.ts +++ b/context.ts @@ -230,10 +230,6 @@ export class Context< } const httpErrorOptions: HttpErrorOptions = {}; if (typeof props === "object") { - if ("headers" in props) { - httpErrorOptions.headers = props.headers; - delete props.headers; - } if ("expose" in props) { httpErrorOptions.expose = props.expose; delete props.expose; diff --git a/deps.ts b/deps.ts index 9f845fa..24bfbf4 100644 --- a/deps.ts +++ b/deps.ts @@ -4,28 +4,27 @@ // jsr dependencies -export { assert } from "jsr:@std/assert@0.223/assert"; -export { concat } from "jsr:@std/bytes@0.223/concat"; -export { copy as copyBytes } from "jsr:@std/bytes@0.223/copy"; -export { timingSafeEqual } from "jsr:@std/crypto@0.223/timing-safe-equal"; -export { KeyStack } from "jsr:@std/crypto@0.223/unstable-keystack"; +export { assert } from "jsr:@std/assert@^1.0/assert"; +export { concat } from "jsr:@std/bytes@^1.0/concat"; +export { copy as copyBytes } from "jsr:@std/bytes@^1.0/copy"; +export { timingSafeEqual } from "jsr:@std/crypto@^1.0/timing-safe-equal"; export { - calculate, + eTag, type ETagOptions, type FileInfo, ifMatch, ifNoneMatch, -} from "jsr:@std/http@0.223/etag"; +} from "jsr:@std/http@^1.0/etag"; export { accepts, acceptsEncodings, acceptsLanguages, -} from "jsr:@std/http@0.223/negotiation"; -export { UserAgent } from "jsr:@std/http@0.223/user-agent"; -export { LimitedReader } from "jsr:@std/io@0.223/limited-reader"; -export { readAll } from "jsr:@std/io@0.223/read-all"; -export { contentType } from "jsr:@std/media-types@0.223/content-type"; -export { typeByExtension } from "jsr:@std/media-types@0.223/type-by-extension"; +} from "jsr:@std/http@^1.0/negotiation"; +export { UserAgent } from "jsr:@std/http@^1.0/user-agent"; +export { LimitedReader } from "jsr:@std/io@0.224/limited-reader"; +export { readAll } from "jsr:@std/io@0.224/read-all"; +export { contentType } from "jsr:@std/media-types@^1.0/content-type"; +export { typeByExtension } from "jsr:@std/media-types@^1.0/type-by-extension"; export { basename, extname, @@ -34,7 +33,7 @@ export { normalize, parse, SEPARATOR, -} from "jsr:@std/path@0.223/"; +} from "jsr:@std/path@^1.0/"; // 3rd party dependencies @@ -43,30 +42,31 @@ export { SecureCookieMap, type SecureCookieMapGetOptions, type SecureCookieMapSetDeleteOptions, -} from "jsr:@oak/commons@0.11/cookie_map"; -export { parse as parseFormData } from "jsr:@oak/commons@0.11/form_data"; -export { parse as parseForwarded } from "jsr:@oak/commons@0.11/forwarded"; +} from "jsr:@oak/commons@^1.0/cookie_map"; +export { parse as parseFormData } from "jsr:@oak/commons@^1.0/form_data"; +export { parse as parseForwarded } from "jsr:@oak/commons@^1.0/forwarded"; export { createHttpError, errors, HttpError, type HttpErrorOptions, isHttpError, -} from "jsr:@oak/commons@0.11/http_errors"; -export { matches } from "jsr:@oak/commons@0.11/media_types"; -export { type HttpMethod as HTTPMethods } from "jsr:@oak/commons@0.11/method"; +} from "jsr:@oak/commons@^1.0/http_errors"; +export { KeyStack } from "jsr:@oak/commons@^1.0/keystack"; +export { matches } from "jsr:@oak/commons@^1.0/media_types"; +export { type HttpMethod as HTTPMethods } from "jsr:@oak/commons@^1.0/method"; export { type ByteRange, range, responseRange, -} from "jsr:@oak/commons@0.11/range"; +} from "jsr:@oak/commons@^1.0/range"; export { ServerSentEvent, type ServerSentEventInit, ServerSentEventStreamTarget, type ServerSentEventTarget, type ServerSentEventTargetOptions, -} from "jsr:@oak/commons@0.11/server_sent_event"; +} from "jsr:@oak/commons@^1.0/server_sent_event"; export { type ErrorStatus, isErrorStatus, @@ -74,7 +74,7 @@ export { type RedirectStatus, Status, STATUS_TEXT, -} from "jsr:@oak/commons@0.11/status"; +} from "jsr:@oak/commons@^1.0/status"; export { compile, diff --git a/deps_test.ts b/deps_test.ts index 6999d81..c472c73 100644 --- a/deps_test.ts +++ b/deps_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2024 the oak authors. All rights reserved. MIT license. -export { assertEquals } from "jsr:@std/assert@0.223/assert-equals"; -export { assertInstanceOf } from "jsr:@std/assert@0.223/assert-instance-of"; -export { assertRejects } from "jsr:@std/assert@0.223/assert-rejects"; -export { assertStrictEquals } from "jsr:@std/assert@0.223/assert-strict-equals"; -export { assertThrows } from "jsr:@std/assert@0.223/assert-throws"; -export { unreachable } from "jsr:@std/assert@0.223/unreachable"; +export { assertEquals } from "jsr:@std/assert@^1.0/equals"; +export { assertInstanceOf } from "jsr:@std/assert@^1.0/instance-of"; +export { assertRejects } from "jsr:@std/assert@^1.0/rejects"; +export { assertStrictEquals } from "jsr:@std/assert@^1.0/strict-equals"; +export { assertThrows } from "jsr:@std/assert@^1.0/throws"; +export { unreachable } from "jsr:@std/assert@^1.0/unreachable"; diff --git a/middleware/etag.ts b/middleware/etag.ts index e3d4f77..e1fd658 100644 --- a/middleware/etag.ts +++ b/middleware/etag.ts @@ -8,7 +8,7 @@ import type { State } from "../application.ts"; import type { Context } from "../context.ts"; -import { calculate, type ETagOptions } from "../deps.ts"; +import { eTag, type ETagOptions } from "../deps.ts"; import type { Middleware } from "../middleware.ts"; import { BODY_TYPES } from "../utils/consts.ts"; import { isAsyncIterable, isReader } from "../utils/type_guards.ts"; @@ -64,7 +64,8 @@ export function factory>( if (!context.response.headers.has("ETag")) { const entity = await getEntity(context); if (entity) { - const etag = await calculate(entity, options); + // @ts-ignore the overloads aren't quite right in the upstream library + const etag = await eTag(entity, options); if (etag) { context.response.headers.set("ETag", etag); } diff --git a/response.test.ts b/response.test.ts index e0795e3..527a78c 100644 --- a/response.test.ts +++ b/response.test.ts @@ -224,7 +224,7 @@ Deno.test({ assertEquals(nativeResponse.status, 200); assertEquals( nativeResponse.headers.get("content-type"), - "application/javascript; charset=UTF-8", + "text/javascript; charset=UTF-8", ); assertEquals(Array.from(nativeResponse.headers.entries()).length, 1); }, diff --git a/send.test.ts b/send.test.ts index 81fdd93..d10388c 100644 --- a/send.test.ts +++ b/send.test.ts @@ -9,7 +9,7 @@ import { import type { Application } from "./application.ts"; import type { Context } from "./context.ts"; -import { assert, calculate, errors } from "./deps.ts"; +import { assert, errors, eTag } from "./deps.ts"; import type { RouteParams } from "./router.ts"; import { send } from "./send.ts"; import { isNode } from "./utils/type_guards.ts"; @@ -322,7 +322,7 @@ Deno.test({ assertEquals(context.response.type, ".json"); assertStrictEquals(context.response.headers.get("content-encoding"), null); const etagHeader = context.response.headers.get("etag"); - assertEquals(etagHeader, await calculate(fixture)); + assertEquals(etagHeader, await eTag(fixture)); }, }); @@ -351,7 +351,7 @@ Deno.test({ async fn() { const { context } = setup("/test.jpg"); const fixture = await Deno.readFile("./fixtures/test.jpg"); - const ifNoneMatch = await calculate(fixture); + const ifNoneMatch = await eTag(fixture); assert(ifNoneMatch); context.request.headers.set("If-None-Match", ifNoneMatch); await send(context, context.request.url.pathname, { root: "./fixtures" }); @@ -359,7 +359,7 @@ Deno.test({ assertEquals(nativeResponse.status, 304); assertEquals( context.response.headers.get("etag"), - await calculate(fixture), + await eTag(fixture), ); }, }); @@ -380,7 +380,7 @@ Deno.test({ assertStrictEquals(context.response.headers.get("content-encoding"), null); assertEquals( context.response.headers.get("etag"), - await calculate(fixture), + await eTag(fixture), ); }, }); diff --git a/send.ts b/send.ts index 7c19302..95a804f 100644 --- a/send.ts +++ b/send.ts @@ -16,9 +16,9 @@ import type { Context } from "./context.ts"; import { basename, type ByteRange, - calculate, contentType, createHttpError, + eTag, extname, type FileInfo, ifNoneMatch, @@ -284,7 +284,7 @@ export async function send( maxbuffer, response, ); - const etag = await calculate(entity); + const etag = await eTag(entity as FileInfo); if ( etag && (!ifNoneMatch(request.headers.get("If-None-Match")!, etag)) ) { @@ -328,7 +328,7 @@ export async function send( } if (!response.headers.has("ETag")) { - const etag = await calculate(entity); + const etag = await eTag(entity as FileInfo); if (etag) { response.headers.set("ETag", etag); } @@ -337,7 +337,7 @@ export async function send( if (returnRanges && size) { response.with( responseRange(body, size, returnRanges, { headers: response.headers }, { - type: contentType(response.type), + type: response.type ? contentType(response.type) : "", }), ); } else {