Skip to content

Commit

Permalink
refactor: break apart util, move form_data to commons
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Apr 18, 2024
1 parent 90db374 commit ba0ecaf
Show file tree
Hide file tree
Showing 35 changed files with 403 additions and 1,056 deletions.
3 changes: 2 additions & 1 deletion application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import type {
ServerRequest,
ServeTlsOptions,
} from "./types.ts";
import { createPromiseWithResolvers, isNode } from "./util.ts";
import { isNode } from "./utils/type_guards.ts";
import { createPromiseWithResolvers } from "./utils/create_promise_with_resolvers.ts";

let optionsStack: Array<ListenOptions | ListenOptionsTls> = [];
let serverClosed = false;
Expand Down
8 changes: 2 additions & 6 deletions application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ import type {
ServerConstructor,
ServerRequest,
} from "./types.ts";
import {
createPromiseWithResolvers,
isBun,
isNetAddr,
isNode,
} from "./util.ts";
import { isBun, isNetAddr, isNode } from "./utils/type_guards.ts";
import { createPromiseWithResolvers } from "./utils/create_promise_with_resolvers.ts";

/** Base interface for application listening options. */
export interface ListenOptionsBase {
Expand Down
5 changes: 2 additions & 3 deletions body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* @module
*/

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

type JsonReviver = (key: string, value: unknown) => unknown;
Expand Down Expand Up @@ -125,7 +124,7 @@ export class Body {
if (this.#body && this.#headers) {
const contentType = this.#headers.get("content-type");
if (contentType) {
return parse(contentType, this.#body);
return parseFormData(contentType, this.#body);
}
}
throw createHttpError(Status.BadRequest, "Missing content type.");
Expand Down
36 changes: 0 additions & 36 deletions content_disposition.test.ts

This file was deleted.

143 changes: 0 additions & 143 deletions content_disposition.ts

This file was deleted.

3 changes: 2 additions & 1 deletion context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { Request as OakRequest } from "./request.ts";
import { Response as OakResponse } from "./response.ts";
import { cloneState } from "./structured_clone.ts";
import type { UpgradeWebSocketFn, UpgradeWebSocketOptions } from "./types.ts";
import { createPromiseWithResolvers, isNode } from "./util.ts";
import { isNode } from "./utils/type_guards.ts";
import { createPromiseWithResolvers } from "./utils/create_promise_with_resolvers.ts";

function createMockApp<S extends State = Record<string, any>>(
state = {} as S,
Expand Down
1 change: 0 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"./body": "./body.ts",
"./context": "./context.ts",
"./etag": "./etag.ts",
"./form_data": "./form_data.ts",
"./helpers": "./helpers.ts",
"./http_server_bun": "./http_server_bun.ts",
"./http_server_native": "./http_server_native.ts",
Expand Down
16 changes: 8 additions & 8 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export { concat } from "jsr:@std/bytes@0.222/concat";
export { copy as copyBytes } from "jsr:@std/bytes@0.222/copy";
export { timingSafeEqual } from "jsr:@std/crypto@0.222/timing-safe-equal";
export { KeyStack } from "jsr:@std/crypto@0.222/unstable-keystack";
export { encodeBase64 } from "jsr:@std/encoding@0.222/base64";
export {
calculate,
type ETagOptions,
Expand Down Expand Up @@ -44,36 +43,37 @@ export {
SecureCookieMap,
type SecureCookieMapGetOptions,
type SecureCookieMapSetDeleteOptions,
} from "jsr:@oak/commons@0.9/cookie_map";
} from "jsr:@oak/commons@0.10/cookie_map";
export { parse as parseFormData } from "jsr:@oak/commons@0.10/form_data";
export {
createHttpError,
errors,
HttpError,
type HttpErrorOptions,
isHttpError,
} from "jsr:@oak/commons@0.9/http_errors";
export { matches } from "jsr:@oak/commons@0.9/media_types";
export { type HttpMethod as HTTPMethods } from "jsr:@oak/commons@0.9/method";
} from "jsr:@oak/commons@0.10/http_errors";
export { matches } from "jsr:@oak/commons@0.10/media_types";
export { type HttpMethod as HTTPMethods } from "jsr:@oak/commons@0.10/method";
export {
type ByteRange,
range,
responseRange,
} from "jsr:@oak/commons@0.9/range";
} from "jsr:@oak/commons@0.10/range";
export {
ServerSentEvent,
type ServerSentEventInit,
ServerSentEventStreamTarget,
type ServerSentEventTarget,
type ServerSentEventTargetOptions,
} from "jsr:@oak/commons@0.9/server_sent_event";
} from "jsr:@oak/commons@0.10/server_sent_event";
export {
type ErrorStatus,
isErrorStatus,
isRedirectStatus,
type RedirectStatus,
Status,
STATUS_TEXT,
} from "jsr:@oak/commons@0.9/status";
} from "jsr:@oak/commons@0.10/status";

export {
compile,
Expand Down
3 changes: 2 additions & 1 deletion etag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type { State } from "./application.ts";
import type { Context } from "./context.ts";
import { calculate, type ETagOptions } from "./deps.ts";
import type { Middleware } from "./middleware.ts";
import { BODY_TYPES, isAsyncIterable, isReader } from "./util.ts";
import { BODY_TYPES } from "./utils/consts.ts";
import { isAsyncIterable, isReader } from "./utils/type_guards.ts";

// re-exports to maintain backwards compatibility
export {
Expand Down
Loading

0 comments on commit ba0ecaf

Please sign in to comment.