Skip to content

Commit

Permalink
feat(types.ts): rename types from NextHandler to OptionalHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Feb 5, 2023
1 parent f8ced47 commit f6720cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions chain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
// This module is browser compatible.

import type { Chainable, ChainableHandler, NextHandler } from "./types.ts";
import type { Chainable, ChainableHandler, OptionalHandler } from "./types.ts";

/** Immutable chain builder for HTTP handlers.
*
Expand Down Expand Up @@ -123,7 +123,7 @@ export function chain(

if (!first) return response.clone();

const nextHandler: NextHandler = async (nextRequest = request) =>
const nextHandler: OptionalHandler = async (nextRequest = request) =>
(await run(nextRequest.clone(), response.clone(), ...rest)).clone();

return (await first(request.clone(), nextHandler)).clone();
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// This module is browser compatible.

export { Chain, chain } from "./chain.ts";
export type { Chainable, ChainableHandler, NextHandler } from "./types.ts";
export type { Chainable, ChainableHandler, OptionalHandler } from "./types.ts";
export type { Handler } from "./deps.ts";
11 changes: 7 additions & 4 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { type Handler } from "./deps.ts";
* Accepts `Request` and the next HTTP handlers.
*/
export interface ChainableHandler {
(request: Request, next: NextHandler): Response | Promise<Response>;
(
request: Request,
next: OptionalHandler,
): Response | Promise<Response>;
}

/** Next HTTP handler.
* A new `Request` can be passed to the next handler.
/** Optional `Request` HTTP handler.
* It is possible not to pass the `Request` object.
*/
export interface NextHandler {
export interface OptionalHandler {
(request?: Request): Response | Promise<Response>;
}

Expand Down

0 comments on commit f6720cb

Please sign in to comment.