Skip to content

Commit

Permalink
chore: migrate to std and commons v1
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Sep 5, 2024
1 parent fa402c9 commit d6f9d38
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 45 deletions.
4 changes: 0 additions & 4 deletions context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 23 additions & 23 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@

// jsr dependencies

export { assert } from "jsr:@std/[email protected]/assert";
export { concat } from "jsr:@std/[email protected]/concat";
export { copy as copyBytes } from "jsr:@std/[email protected]/copy";
export { timingSafeEqual } from "jsr:@std/[email protected]/timing-safe-equal";
export { KeyStack } from "jsr:@std/[email protected]/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,
Expand All @@ -34,7 +33,7 @@ export {
normalize,
parse,
SEPARATOR,
} from "jsr:@std/path@0.223/";
} from "jsr:@std/path@^1.0/";

// 3rd party dependencies

Expand All @@ -43,38 +42,39 @@ 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/[email protected]/http_errors";
export { matches } from "jsr:@oak/[email protected]/media_types";
export { type HttpMethod as HTTPMethods } from "jsr:@oak/[email protected]/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,
isRedirectStatus,
type RedirectStatus,
Status,
STATUS_TEXT,
} from "jsr:@oak/commons@0.11/status";
} from "jsr:@oak/commons@^1.0/status";

export {
compile,
Expand Down
12 changes: 6 additions & 6 deletions deps_test.ts
Original file line number Diff line number Diff line change
@@ -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";
5 changes: 3 additions & 2 deletions middleware/etag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -64,7 +64,8 @@ export function factory<S extends State = Record<string, any>>(
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);
}
Expand Down
2 changes: 1 addition & 1 deletion response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
10 changes: 5 additions & 5 deletions send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
},
});

Expand Down Expand Up @@ -351,15 +351,15 @@ 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" });
const nativeResponse = await context.response.toDomResponse();
assertEquals(nativeResponse.status, 304);
assertEquals(
context.response.headers.get("etag"),
await calculate(fixture),
await eTag(fixture),
);
},
});
Expand All @@ -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),
);
},
});
Expand Down
8 changes: 4 additions & 4 deletions send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import type { Context } from "./context.ts";
import {
basename,
type ByteRange,
calculate,
contentType,
createHttpError,
eTag,
extname,
type FileInfo,
ifNoneMatch,
Expand Down Expand Up @@ -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))
) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down

0 comments on commit d6f9d38

Please sign in to comment.