Skip to content

Commit

Permalink
refactor: migrate to oak commons for media type utils
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jan 30, 2024
1 parent 2d859f1 commit b075f2e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 487 deletions.
7 changes: 4 additions & 3 deletions body.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createHttpError, Status } from "./deps.ts";
// Copyright 2018-2023 the oak authors. All rights reserved. MIT license.

import { createHttpError, matches, Status } from "./deps.ts";
import { parse } from "./form_data.ts";
import { isMediaType } from "./isMediaType.ts";
import type { ServerRequest } from "./types.d.ts";

type JsonReviver = (key: string, value: unknown) => unknown;
Expand Down Expand Up @@ -191,7 +192,7 @@ export class Body {
if (contentType) {
for (const [bodyType, knownMediaTypes] of KNOWN_BODY_TYPES) {
const customTypes = customMediaTypes[bodyType] ?? [];
if (isMediaType(contentType, [...knownMediaTypes, ...customTypes])) {
if (matches(contentType, [...knownMediaTypes, ...customTypes])) {
this.#type = bodyType;
return this.#type;
}
Expand Down
11 changes: 6 additions & 5 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,31 @@ export {
SecureCookieMap,
type SecureCookieMapGetOptions,
type SecureCookieMapSetDeleteOptions,
} from "https://deno.land/x/oak_commons@0.5.2/cookie_map.ts";
} from "https://deno.land/x/oak_commons@0.6.0/cookie_map.ts";
export {
createHttpError,
errors,
HttpError,
type HttpErrorOptions,
isHttpError,
} from "https://deno.land/x/[email protected]/http_errors.ts";
export { type HttpMethod as HTTPMethods } from "https://deno.land/x/[email protected]/method.ts";
} from "https://deno.land/x/[email protected]/http_errors.ts";
export { matches } from "https://deno.land/x/[email protected]/media_types.ts";
export { type HttpMethod as HTTPMethods } from "https://deno.land/x/[email protected]/method.ts";
export {
ServerSentEvent,
type ServerSentEventInit,
ServerSentEventStreamTarget,
type ServerSentEventTarget,
type ServerSentEventTargetOptions,
} from "https://deno.land/x/oak_commons@0.5.2/server_sent_event.ts";
} from "https://deno.land/x/oak_commons@0.6.0/server_sent_event.ts";
export {
type ErrorStatus,
isErrorStatus,
isRedirectStatus,
type RedirectStatus,
Status,
STATUS_TEXT,
} from "https://deno.land/x/oak_commons@0.5.2/status.ts";
} from "https://deno.land/x/oak_commons@0.6.0/status.ts";

export {
compile,
Expand Down
89 changes: 0 additions & 89 deletions isMediaType.ts

This file was deleted.

189 changes: 0 additions & 189 deletions isMediaType_test.ts

This file was deleted.

Loading

0 comments on commit b075f2e

Please sign in to comment.