hono 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,10 @@
1
- # Hono
1
+ # Hono\[炎\]
2
+
3
+ <p>
4
+ <a href="https://github.com/yusukebe/hono/blob/master/README.md">English</a>
5
+ &#x000B7;
6
+ <a href="https://github.com/yusukebe/hono/blob/master/docs/README.ja.md">日本語</a>
7
+ </p>
2
8
 
3
9
  [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/yusukebe/hono/ci)](https://github.com/yusukebe/hono/actions)
4
10
  [![GitHub](https://img.shields.io/github/license/yusukebe/hono)](https://github.com/yusukebe/hono/blob/master/LICENSE)
@@ -8,7 +14,7 @@
8
14
  [![GitHub commit activity](https://img.shields.io/github/commit-activity/m/yusukebe/hono)](https://github.com/yusukebe/hono/pulse)
9
15
  [![GitHub last commit](https://img.shields.io/github/last-commit/yusukebe/hono)](https://github.com/yusukebe/hono/commits/master)
10
16
 
11
- Hono[炎] - _**means flame🔥 in Japanese**_ - is small, simple, and ultrafast web framework for Service Worker based serverless applications like Cloudflare Workers and Fastly Compute@Edge.
17
+ Hono[炎] - _**means flame🔥 in Japanese**_ - is small, simple, and ultrafast web framework for Cloudflare Workers and Fastly Compute@Edge.
12
18
 
13
19
  ```js
14
20
  import { Hono } from 'hono'
@@ -22,7 +28,7 @@ app.fire()
22
28
  ## Features
23
29
 
24
30
  - **Ultrafast** - the router does not use linear loops.
25
- - **Zero-dependencies** - using only Web standard API.
31
+ - **Zero-dependencies** - using only Service Worker and Web standard API.
26
32
  - **Middleware** - built-in middleware and ability to extend with your own middleware.
27
33
  - **Optimized** - for Cloudflare Workers.
28
34
 
@@ -53,13 +59,13 @@ Now, the named path parameter has types.
53
59
 
54
60
  You can install Hono from the npm registry.
55
61
 
56
- ```sh
62
+ ```
57
63
  $ yarn add hono
58
64
  ```
59
65
 
60
66
  or
61
67
 
62
- ```sh
68
+ ```
63
69
  $ npm install hono
64
70
  ```
65
71
 
@@ -75,6 +81,7 @@ An instance of `Hono` has these methods.
75
81
  - app.**onError**(err, handler)
76
82
  - app.**fire**()
77
83
  - app.**fetch**(request, env, event)
84
+ - app.**request**(path, option)
78
85
 
79
86
  ## Routing
80
87
 
@@ -149,6 +156,8 @@ app.get('/fetch-url', async (c) => {
149
156
 
150
157
  ### Built-in Middleware
151
158
 
159
+ Hono has built-in middleware.
160
+
152
161
  ```js
153
162
  import { Hono } from 'hono'
154
163
  import { poweredBy } from 'hono/powered-by'
@@ -213,7 +222,7 @@ app.onError((err, c) => {
213
222
 
214
223
  ## Context
215
224
 
216
- To handle Request and Reponse, you can use Context object.
225
+ To handle Request and Reponse, you can use `Context` object.
217
226
 
218
227
  ### c.req
219
228
 
@@ -303,7 +312,7 @@ app.get('/', (c) => {
303
312
 
304
313
  ### c.notFound()
305
314
 
306
- Return the `404 Not Found` Response.
315
+ Return the `Not Found` Response.
307
316
 
308
317
  ```js
309
318
  app.get('/notfound', (c) => {
@@ -379,6 +388,17 @@ export default app
379
388
  */
380
389
  ```
381
390
 
391
+ ## request
392
+
393
+ `request` is a useful method for testing.
394
+
395
+ ```js
396
+ test('GET /hello is ok', async () => {
397
+ const res = await app.request('http://localhost/hello')
398
+ expect(res.status).toBe(200)
399
+ })
400
+ ```
401
+
382
402
  ## Cloudflare Workers with Hono
383
403
 
384
404
  Using [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/) or [Miniflare](https://miniflare.dev), you can develop the application locally and publish it with few commands.
@@ -400,10 +420,10 @@ Let's write your first code for Cloudflare Workers with Hono.
400
420
 
401
421
  Make a npm skeleton directory.
402
422
 
403
- ```sh
404
- mkdir hono-example
405
- cd hono-example
406
- npm init -y
423
+ ```
424
+ $ mkdir hono-example
425
+ $ cd hono-example
426
+ $ npm init -y
407
427
  ```
408
428
 
409
429
  ### 2. `wrangler init`
@@ -426,7 +446,7 @@ Would you like to create a Worker at src/index.js? (y/n) <--- n
426
446
 
427
447
  Install `hono` from the npm registry.
428
448
 
429
- ```sh
449
+ ```
430
450
  $ npm i hono
431
451
  ```
432
452
 
@@ -448,7 +468,7 @@ app.fire()
448
468
 
449
469
  Run the development server locally. Then, access `http://127.0.0.1:8787/` in your Web browser.
450
470
 
451
- ```sh
471
+ ```
452
472
  $ npx wrangler@beta dev index.js
453
473
  ```
454
474
 
@@ -456,7 +476,7 @@ $ npx wrangler@beta dev index.js
456
476
 
457
477
  Deploy to Cloudflare. That's all!
458
478
 
459
- ```sh
479
+ ```
460
480
  $ npx wrangler@beta publish index.js
461
481
  ```
462
482
 
package/dist/context.js CHANGED
@@ -35,8 +35,8 @@ class Context {
35
35
  this._statusText = (0, http_status_1.getStatusText)(number);
36
36
  }
37
37
  newResponse(data, init = {}) {
38
- init.status = init.status || this._status;
39
- init.statusText = init.statusText || this._statusText;
38
+ init.status = init.status || this._status || 200;
39
+ init.statusText = init.statusText || this._statusText || (0, http_status_1.getStatusText)(init.status);
40
40
  init.headers = Object.assign(Object.assign({}, this._headers), init.headers);
41
41
  // Content-Length
42
42
  let length = 0;
package/dist/hono.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
2
  import { Context } from './context';
3
3
  import type { Env } from './context';
4
- import type { Result, Router } from './router';
4
+ import type { Router } from './router';
5
5
  declare global {
6
6
  interface Request<ParamKeyType = string> {
7
7
  param: (key: ParamKeyType) => string;
@@ -26,8 +26,8 @@ export declare class Hono {
26
26
  middlewareRouters: Router<MiddlewareHandler>[];
27
27
  tempPath: string;
28
28
  constructor(init?: Partial<Pick<Hono, 'routerClass' | 'strict'>>);
29
- notFoundHandler: NotFoundHandler;
30
- errorHandler: ErrorHandler;
29
+ private notFoundHandler;
30
+ private errorHandler;
31
31
  get<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
32
32
  post<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
33
33
  put<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
@@ -40,11 +40,12 @@ export declare class Hono {
40
40
  use(path: string, middleware: MiddlewareHandler): void;
41
41
  onError(handler: ErrorHandler): Hono;
42
42
  notFound(handler: NotFoundHandler): Hono;
43
- addRoute(method: string, path: string, handler: Handler): Hono;
44
- matchRoute(method: string, path: string): Promise<Result<Handler>>;
43
+ private addRoute;
44
+ private matchRoute;
45
45
  dispatch(request: Request, env?: Env, event?: FetchEvent): Promise<Response>;
46
46
  handleEvent(event: FetchEvent): Promise<Response>;
47
47
  fetch(request: Request, env?: Env, event?: FetchEvent): Promise<Response>;
48
+ request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>;
48
49
  fire(): void;
49
50
  }
50
51
  export {};
package/dist/hono.js CHANGED
@@ -128,6 +128,10 @@ class Hono {
128
128
  async fetch(request, env, event) {
129
129
  return this.dispatch(request, env, event);
130
130
  }
131
+ request(input, requestInit) {
132
+ const req = new Request(input, requestInit);
133
+ return this.dispatch(req);
134
+ }
131
135
  fire() {
132
136
  addEventListener('fetch', (event) => {
133
137
  event.respondWith(this.handleEvent(event));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "[炎] Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -98,6 +98,7 @@
98
98
  "jest-environment-miniflare": "^2.0.0",
99
99
  "mustache": "^4.2.0",
100
100
  "prettier": "^2.5.1",
101
+ "prettier-plugin-md-nocjsp": "^1.2.0",
101
102
  "rimraf": "^3.0.2",
102
103
  "ts-jest": "^27.1.2",
103
104
  "typescript": "^4.5.5"