Skip to content

Commit f04cbdc

Browse files
Merge pull request #2 from httpland/beta
Beta
2 parents 8eab50f + 2ff3b5d commit f04cbdc

7 files changed

Lines changed: 57 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [1.1.0-beta.1](https://github.com/httpland/chain-handler/compare/1.0.0...1.1.0-beta.1) (2023-02-08)
2+
3+
4+
### Features
5+
6+
* **types.ts:** split interface and export types ([02b49b9](https://github.com/httpland/chain-handler/commit/02b49b99cac229c1dc9ed7c64690df6c0fbe1e1e))
7+
18
# 1.0.0 (2023-02-06)
29

310

_dev_deps.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export {
22
assertEquals,
33
assertNotEquals,
4-
} from "https://deno.land/std@0.176.0/testing/asserts.ts";
4+
} from "https://deno.land/std@0.177.0/testing/asserts.ts";
55
export {
66
assertSpyCalls,
77
spy,
8-
} from "https://deno.land/std@0.176.0/testing/mock.ts";
9-
export { describe, it } from "https://deno.land/std@0.176.0/testing/bdd.ts";
8+
} from "https://deno.land/std@0.177.0/testing/mock.ts";
9+
export { describe, it } from "https://deno.land/std@0.177.0/testing/bdd.ts";

chain.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
22
// This module is browser compatible.
33

4-
import type { Chainable, ChainableHandler, OptionalHandler } from "./types.ts";
4+
import type {
5+
Chainable,
6+
ChainableHandler,
7+
OptionalHandler,
8+
Responsive,
9+
} from "./types.ts";
510

611
/** Immutable chain builder for HTTP handlers.
712
*
@@ -38,7 +43,7 @@ import type { Chainable, ChainableHandler, OptionalHandler } from "./types.ts";
3843
* assertEquals(response.headers.get("server"), "deno")
3944
* ```
4045
*/
41-
export class Chain implements Chainable {
46+
export class Chain implements Chainable, Responsive {
4247
#handlers: readonly ChainableHandler[] = [];
4348

4449
/**
@@ -48,16 +53,24 @@ export class Chain implements Chainable {
4853
this.#handlers = init ?? [];
4954
}
5055

51-
/**
52-
* @param handlers
56+
/** Register chainable HTTP handlers.
57+
* @param handlers HTTP chainable handlers.
58+
*
59+
* @example
60+
* ```ts
61+
* import { Chain } from "https://deno.land/x/chain_handler@$VERSION/mod.ts";
62+
*
63+
* const chain = new Chain().next((request, next) => next(), () => new Response("hello"))
64+
* ```
5365
*/
5466
readonly next = (...handlers: readonly ChainableHandler[]): this => {
5567
this.#handlers = this.#handlers.concat(handlers);
5668

5769
return this;
5870
};
5971

60-
/**
72+
/** All registered handlers.
73+
*
6174
* @example
6275
* ```ts
6376
* import { Chain } from "https://deno.land/x/chain_handler@$VERSION/mod.ts";
@@ -73,6 +86,16 @@ export class Chain implements Chainable {
7386
/**
7487
* @param request `Request` object. The `Request` is cloned and not mutate.
7588
* @param defaultResponse The default `Response` object. Change the response when the {@link handlers} is empty.
89+
*
90+
* @example
91+
* ```ts
92+
* import { Chain } from "https://deno.land/x/chain_handler@$VERSION/mod.ts";
93+
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
94+
*
95+
* const chain = new Chain()
96+
* const response = await chain.respond(new Request("http://localhost"))
97+
* assertEquals(response.status, 404)
98+
* ```
7699
*/
77100
readonly respond = (
78101
request: Request,

deno.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
// This module is browser compatible.
33

44
export { Chain, chain } from "./chain.ts";
5-
export type { Chainable, ChainableHandler, OptionalHandler } from "./types.ts";
5+
export type {
6+
Chainable,
7+
ChainableHandler,
8+
OptionalHandler,
9+
Responsive,
10+
} from "./types.ts";
611
export type { Handler } from "./deps.ts";

test_import_map.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"imports": {
33
"https://deno.land/x/chain_handler@$VERSION/": "./",
4-
"https://deno.land/std/": "https://deno.land/std@0.176.0/"
4+
"https://deno.land/std/": "https://deno.land/std@0.177.0/"
55
}
66
}

types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export interface OptionalHandler {
2424
export interface Chainable {
2525
/** Register chainable HTTP handlers. */
2626
readonly next: (...handlers: readonly ChainableHandler[]) => this;
27+
}
2728

29+
/** HTTP responsive API.
30+
* Accept `Request` and respond `Response`.
31+
*/
32+
export interface Responsive {
2833
/** Respond `Response` from `Request`. */
2934
readonly respond: Handler;
30-
31-
/** All registered handlers. */
32-
readonly handlers: readonly ChainableHandler[];
3335
}

0 commit comments

Comments
 (0)