hono 0.5.8 → 1.0.0
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 +27 -20
- package/dist/context.d.ts +11 -6
- package/dist/context.js +27 -20
- package/dist/hono.d.ts +22 -25
- package/dist/hono.js +20 -40
- package/dist/index.d.ts +1 -1
- package/dist/middleware/basic-auth/{basic-auth.d.ts → index.d.ts} +2 -1
- package/dist/middleware/basic-auth/{basic-auth.js → index.js} +0 -0
- package/dist/middleware/body-parse/index.d.ts +3 -0
- package/dist/middleware/body-parse/{body-parse.js → index.js} +0 -0
- package/dist/middleware/cookie/{cookie.d.ts → index.d.ts} +3 -2
- package/dist/middleware/cookie/{cookie.js → index.js} +1 -1
- package/dist/middleware/cors/{cors.d.ts → index.d.ts} +2 -1
- package/dist/middleware/cors/{cors.js → index.js} +0 -0
- package/dist/middleware/etag/{etag.d.ts → index.d.ts} +2 -1
- package/dist/middleware/etag/{etag.js → index.js} +1 -1
- package/dist/middleware/graphql-server/{graphql-server.d.ts → index.d.ts} +7 -4
- package/dist/middleware/graphql-server/{graphql-server.js → index.js} +34 -17
- package/dist/middleware/graphql-server/parse-body.js +3 -0
- package/dist/middleware/logger/{logger.d.ts → index.d.ts} +2 -1
- package/dist/middleware/logger/{logger.js → index.js} +2 -2
- package/dist/middleware/mustache/{mustache.d.ts → index.d.ts} +2 -1
- package/dist/middleware/mustache/{mustache.js → index.js} +0 -0
- package/dist/middleware/powered-by/index.d.ts +3 -0
- package/dist/middleware/powered-by/{powered-by.js → index.js} +0 -1
- package/dist/middleware/pretty-json/index.d.ts +7 -0
- package/dist/middleware/pretty-json/index.js +11 -0
- package/dist/middleware/serve-static/{serve-static.d.ts → index.d.ts} +2 -1
- package/dist/middleware/serve-static/{serve-static.js → index.js} +1 -1
- package/dist/router/reg-exp-router/index.d.ts +1 -1
- package/dist/router/reg-exp-router/index.js +1 -1
- package/dist/router/reg-exp-router/router.js +1 -1
- package/dist/router/reg-exp-router/trie.d.ts +3 -3
- package/dist/router/reg-exp-router/trie.js +1 -1
- package/dist/router/trie-router/index.d.ts +1 -1
- package/dist/router/trie-router/index.js +1 -1
- package/dist/router/trie-router/node.d.ts +1 -1
- package/dist/router/trie-router/node.js +1 -1
- package/dist/router/trie-router/router.d.ts +1 -1
- package/dist/router/trie-router/router.js +1 -1
- package/dist/utils/buffer.js +1 -1
- package/dist/utils/crypto.d.ts +2 -2
- package/dist/utils/crypto.js +6 -0
- package/dist/utils/http-status.d.ts +2 -1
- package/dist/utils/http-status.js +6 -2
- package/package.json +35 -37
- package/dist/middleware/body-parse/body-parse.d.ts +0 -2
- package/dist/middleware/powered-by/powered-by.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/yusukebe/hono">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/yusukebe/hono/master/docs/images/hono-title.png" width="500" height="auto" alt="Hono"/>
|
|
4
|
+
</a>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<hr />
|
|
2
8
|
|
|
3
9
|
<p>
|
|
4
10
|
<a href="https://github.com/yusukebe/hono/blob/master/README.md">English</a>
|
|
@@ -14,7 +20,7 @@
|
|
|
14
20
|
[](https://github.com/yusukebe/hono/pulse)
|
|
15
21
|
[](https://github.com/yusukebe/hono/commits/master)
|
|
16
22
|
|
|
17
|
-
Hono
|
|
23
|
+
Hono - _**[炎] means flame🔥 in Japanese**_ - is small, simple, and ultrafast web framework for Cloudflare Workers and Fastly Compute@Edge.
|
|
18
24
|
|
|
19
25
|
```js
|
|
20
26
|
import { Hono } from 'hono'
|
|
@@ -30,6 +36,7 @@ app.fire()
|
|
|
30
36
|
- **Ultrafast** - the router does not use linear loops.
|
|
31
37
|
- **Zero-dependencies** - using only Service Worker and Web standard API.
|
|
32
38
|
- **Middleware** - built-in middleware and ability to extend with your own middleware.
|
|
39
|
+
- **TypeScript** - first-class TypeScript support.
|
|
33
40
|
- **Optimized** - for Cloudflare Workers.
|
|
34
41
|
|
|
35
42
|
## Benchmark
|
|
@@ -59,14 +66,14 @@ Now, the named path parameter has types.
|
|
|
59
66
|
|
|
60
67
|
You can install Hono from the npm registry.
|
|
61
68
|
|
|
62
|
-
```
|
|
63
|
-
|
|
69
|
+
```sh
|
|
70
|
+
yarn add hono
|
|
64
71
|
```
|
|
65
72
|
|
|
66
73
|
or
|
|
67
74
|
|
|
68
|
-
```
|
|
69
|
-
|
|
75
|
+
```sh
|
|
76
|
+
npm install hono
|
|
70
77
|
```
|
|
71
78
|
|
|
72
79
|
## Methods
|
|
@@ -420,18 +427,18 @@ Let's write your first code for Cloudflare Workers with Hono.
|
|
|
420
427
|
|
|
421
428
|
Make a npm skeleton directory.
|
|
422
429
|
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
430
|
+
```sh
|
|
431
|
+
mkdir hono-example
|
|
432
|
+
cd hono-example
|
|
433
|
+
npm init -y
|
|
427
434
|
```
|
|
428
435
|
|
|
429
436
|
### 2. `wrangler init`
|
|
430
437
|
|
|
431
438
|
Initialize as a wrangler project.
|
|
432
439
|
|
|
433
|
-
```
|
|
434
|
-
|
|
440
|
+
```sh
|
|
441
|
+
npx wrangler@beta init
|
|
435
442
|
```
|
|
436
443
|
|
|
437
444
|
Answer the questions. If you want, you can answer `y`.
|
|
@@ -446,8 +453,8 @@ Would you like to create a Worker at src/index.js? (y/n) <--- n
|
|
|
446
453
|
|
|
447
454
|
Install `hono` from the npm registry.
|
|
448
455
|
|
|
449
|
-
```
|
|
450
|
-
|
|
456
|
+
```sh
|
|
457
|
+
npm i hono
|
|
451
458
|
```
|
|
452
459
|
|
|
453
460
|
### 4. Write your app
|
|
@@ -468,16 +475,16 @@ app.fire()
|
|
|
468
475
|
|
|
469
476
|
Run the development server locally. Then, access `http://127.0.0.1:8787/` in your Web browser.
|
|
470
477
|
|
|
471
|
-
```
|
|
472
|
-
|
|
478
|
+
```sh
|
|
479
|
+
npx wrangler@beta dev index.js
|
|
473
480
|
```
|
|
474
481
|
|
|
475
482
|
### 6. Publish
|
|
476
483
|
|
|
477
484
|
Deploy to Cloudflare. That's all!
|
|
478
485
|
|
|
479
|
-
```
|
|
480
|
-
|
|
486
|
+
```sh
|
|
487
|
+
npx wrangler@beta publish index.js
|
|
481
488
|
```
|
|
482
489
|
|
|
483
490
|
## Starter template
|
|
@@ -486,8 +493,8 @@ You can start making your Cloudflare Workers application with [the starter templ
|
|
|
486
493
|
|
|
487
494
|
To generate a project skelton, run this command.
|
|
488
495
|
|
|
489
|
-
```
|
|
490
|
-
|
|
496
|
+
```sh
|
|
497
|
+
wrangler generate my-app https://github.com/yusukebe/hono-minimal
|
|
491
498
|
```
|
|
492
499
|
|
|
493
500
|
## Related projects
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import type { StatusCode } from './utils/http-status';
|
|
2
3
|
declare type Headers = Record<string, string>;
|
|
3
4
|
declare type Data = string | ArrayBuffer | ReadableStream;
|
|
4
5
|
export interface Env {
|
|
@@ -11,6 +12,8 @@ export declare class Context<RequestParamKeyType = string> {
|
|
|
11
12
|
private _headers;
|
|
12
13
|
private _status;
|
|
13
14
|
private _statusText;
|
|
15
|
+
private _pretty;
|
|
16
|
+
private _prettySpace;
|
|
14
17
|
render: (template: string, params?: object, options?: object) => Promise<Response>;
|
|
15
18
|
notFound: () => Response | Promise<Response>;
|
|
16
19
|
constructor(req: Request<RequestParamKeyType>, opts?: {
|
|
@@ -18,13 +21,15 @@ export declare class Context<RequestParamKeyType = string> {
|
|
|
18
21
|
env: Env;
|
|
19
22
|
event: FetchEvent;
|
|
20
23
|
});
|
|
24
|
+
private initRequest;
|
|
21
25
|
header(name: string, value: string): void;
|
|
22
|
-
status(
|
|
26
|
+
status(status: StatusCode): void;
|
|
27
|
+
pretty(prettyJSON: boolean, space?: number): void;
|
|
23
28
|
newResponse(data: Data, init?: ResponseInit): Response;
|
|
24
|
-
body(data: Data, status?:
|
|
25
|
-
text(text: string, status?:
|
|
26
|
-
json(object: object, status?:
|
|
27
|
-
html(html: string, status?:
|
|
28
|
-
redirect(location: string, status?:
|
|
29
|
+
body(data: Data, status?: StatusCode, headers?: Headers): Response;
|
|
30
|
+
text(text: string, status?: StatusCode, headers?: Headers): Response;
|
|
31
|
+
json(object: object, status?: StatusCode, headers?: Headers): Response;
|
|
32
|
+
html(html: string, status?: StatusCode, headers?: Headers): Response;
|
|
33
|
+
redirect(location: string, status?: StatusCode): Response;
|
|
29
34
|
}
|
|
30
35
|
export {};
|
package/dist/context.js
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Context = void 0;
|
|
4
|
-
const url_1 = require("./utils/url");
|
|
5
4
|
const http_status_1 = require("./utils/http-status");
|
|
5
|
+
const url_1 = require("./utils/url");
|
|
6
6
|
class Context {
|
|
7
7
|
constructor(req, opts) {
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.env = opts.env;
|
|
12
|
-
this.event = opts.event;
|
|
13
|
-
}
|
|
8
|
+
this._prettySpace = 2;
|
|
9
|
+
this.req = this.initRequest(req);
|
|
10
|
+
Object.assign(this, opts);
|
|
14
11
|
this._headers = {};
|
|
15
12
|
}
|
|
13
|
+
initRequest(req) {
|
|
14
|
+
req.header = (name) => {
|
|
15
|
+
return req.headers.get(name);
|
|
16
|
+
};
|
|
17
|
+
req.query = (key) => {
|
|
18
|
+
const url = new URL(req.url);
|
|
19
|
+
return url.searchParams.get(key);
|
|
20
|
+
};
|
|
21
|
+
return req;
|
|
22
|
+
}
|
|
16
23
|
header(name, value) {
|
|
17
|
-
/*
|
|
18
|
-
XXX:
|
|
19
|
-
app.use('*', (c, next) => {
|
|
20
|
-
next()
|
|
21
|
-
c.header('foo', 'bar') // => c.res.headers.set(...)
|
|
22
|
-
})
|
|
23
|
-
*/
|
|
24
24
|
if (this.res) {
|
|
25
25
|
this.res.headers.set(name, value);
|
|
26
26
|
}
|
|
27
27
|
this._headers[name] = value;
|
|
28
28
|
}
|
|
29
|
-
status(
|
|
29
|
+
status(status) {
|
|
30
30
|
if (this.res) {
|
|
31
31
|
console.warn('c.res.status is already set.');
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
this._status =
|
|
35
|
-
this._statusText = (0, http_status_1.getStatusText)(
|
|
34
|
+
this._status = status;
|
|
35
|
+
this._statusText = (0, http_status_1.getStatusText)(status);
|
|
36
|
+
}
|
|
37
|
+
pretty(prettyJSON, space = 2) {
|
|
38
|
+
this._pretty = prettyJSON;
|
|
39
|
+
this._prettySpace = space;
|
|
36
40
|
}
|
|
37
41
|
newResponse(data, init = {}) {
|
|
38
42
|
init.status = init.status || this._status || 200;
|
|
39
|
-
init.statusText =
|
|
43
|
+
init.statusText =
|
|
44
|
+
init.statusText || this._statusText || (0, http_status_1.getStatusText)(init.status);
|
|
40
45
|
init.headers = Object.assign(Object.assign({}, this._headers), init.headers);
|
|
41
46
|
// Content-Length
|
|
42
47
|
let length = 0;
|
|
@@ -67,9 +72,11 @@ class Context {
|
|
|
67
72
|
}
|
|
68
73
|
json(object, status = this._status, headers = {}) {
|
|
69
74
|
if (typeof object !== 'object') {
|
|
70
|
-
throw new TypeError('json method arg must be
|
|
75
|
+
throw new TypeError('json method arg must be an object!');
|
|
71
76
|
}
|
|
72
|
-
const body =
|
|
77
|
+
const body = this._pretty
|
|
78
|
+
? JSON.stringify(object, null, this._prettySpace)
|
|
79
|
+
: JSON.stringify(object);
|
|
73
80
|
headers['Content-Type'] || (headers['Content-Type'] = 'application/json; charset=UTF-8');
|
|
74
81
|
return this.body(body, status, headers);
|
|
75
82
|
}
|
package/dist/hono.d.ts
CHANGED
|
@@ -10,47 +10,44 @@ declare global {
|
|
|
10
10
|
parsedBody: any;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export declare type Handler<RequestParamKeyType = string> = (c: Context<RequestParamKeyType>, next?:
|
|
14
|
-
export declare type MiddlewareHandler = (c: Context, next:
|
|
13
|
+
export declare type Handler<RequestParamKeyType = string> = (c: Context<RequestParamKeyType | string>, next?: Next) => Response | Promise<Response>;
|
|
14
|
+
export declare type MiddlewareHandler = (c: Context, next: Next) => Promise<void>;
|
|
15
15
|
export declare type NotFoundHandler = (c: Context) => Response | Promise<Response>;
|
|
16
16
|
export declare type ErrorHandler = (err: Error, c: Context) => Response;
|
|
17
|
+
export declare type Next = () => Promise<void>;
|
|
17
18
|
declare type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer _Pattern}` ? Name : NameWithPattern;
|
|
18
19
|
declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
|
|
19
20
|
declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
declare const Hono_base: new () => {
|
|
22
|
+
delete: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
23
|
+
get: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
24
|
+
post: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
25
|
+
put: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
26
|
+
head: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
27
|
+
options: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
28
|
+
patch: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
29
|
+
all: <Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>) => Hono;
|
|
30
|
+
} & {
|
|
31
|
+
methods: ["get", "post", "put", "delete", "head", "options", "patch", "all"];
|
|
32
|
+
};
|
|
33
|
+
export declare class Hono extends Hono_base {
|
|
34
|
+
readonly routerClass: {
|
|
22
35
|
new (): Router<any>;
|
|
23
36
|
};
|
|
24
|
-
strict: boolean;
|
|
25
|
-
router
|
|
26
|
-
middlewareRouters
|
|
27
|
-
tempPath
|
|
37
|
+
readonly strict: boolean;
|
|
38
|
+
private router;
|
|
39
|
+
private middlewareRouters;
|
|
40
|
+
private tempPath;
|
|
28
41
|
constructor(init?: Partial<Pick<Hono, 'routerClass' | 'strict'>>);
|
|
29
42
|
private notFoundHandler;
|
|
30
43
|
private errorHandler;
|
|
31
|
-
get<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
32
|
-
get(path: string, handler: Handler<string>): Hono;
|
|
33
|
-
post<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
34
|
-
post(path: string, handler: Handler<string>): Hono;
|
|
35
|
-
put<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
36
|
-
put(path: string, handler: Handler<string>): Hono;
|
|
37
|
-
head<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
38
|
-
head(path: string, handler: Handler<string>): Hono;
|
|
39
|
-
delete<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
40
|
-
delete(path: string, handler: Handler<string>): Hono;
|
|
41
|
-
options<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
42
|
-
options(path: string, handler: Handler<string>): Hono;
|
|
43
|
-
patch<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
44
|
-
patch(path: string, handler: Handler<string>): Hono;
|
|
45
|
-
all<Path extends string>(path: Path, handler: Handler<ParamKeys<Path>>): Hono;
|
|
46
|
-
all(path: string, handler: Handler<string>): Hono;
|
|
47
44
|
route(path: string): Hono;
|
|
48
45
|
use(path: string, middleware: MiddlewareHandler): void;
|
|
49
46
|
onError(handler: ErrorHandler): Hono;
|
|
50
47
|
notFound(handler: NotFoundHandler): Hono;
|
|
51
48
|
private addRoute;
|
|
52
49
|
private matchRoute;
|
|
53
|
-
dispatch
|
|
50
|
+
private dispatch;
|
|
54
51
|
handleEvent(event: FetchEvent): Promise<Response>;
|
|
55
52
|
fetch(request: Request, env?: Env, event?: FetchEvent): Promise<Response>;
|
|
56
53
|
request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>;
|
package/dist/hono.js
CHANGED
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Hono = void 0;
|
|
4
4
|
const compose_1 = require("./compose");
|
|
5
|
-
const url_1 = require("./utils/url");
|
|
6
5
|
const context_1 = require("./context");
|
|
7
6
|
const router_1 = require("./router");
|
|
8
7
|
const trie_router_1 = require("./router/trie-router"); // Default Router
|
|
9
|
-
|
|
8
|
+
const url_1 = require("./utils/url");
|
|
9
|
+
function defineDynamicClass(...methods) {
|
|
10
|
+
return class {
|
|
11
|
+
get methods() {
|
|
12
|
+
return methods;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
class Hono extends defineDynamicClass('get', 'post', 'put', 'delete', 'head', 'options', 'patch', 'all') {
|
|
10
17
|
constructor(init = {}) {
|
|
18
|
+
super();
|
|
11
19
|
this.routerClass = trie_router_1.TrieRouter;
|
|
12
20
|
this.strict = true; // strict routing - default is true
|
|
13
21
|
this.notFoundHandler = (c) => {
|
|
@@ -15,39 +23,20 @@ class Hono {
|
|
|
15
23
|
return c.text(message, 404);
|
|
16
24
|
};
|
|
17
25
|
this.errorHandler = (err, c) => {
|
|
18
|
-
console.error(`${err.message}`);
|
|
26
|
+
console.error(`${err.stack || err.message}`);
|
|
19
27
|
const message = 'Internal Server Error';
|
|
20
28
|
return c.text(message, 500);
|
|
21
29
|
};
|
|
30
|
+
this.methods.map((method) => {
|
|
31
|
+
this[method] = (path, handler) => {
|
|
32
|
+
return this.addRoute(method, path, handler);
|
|
33
|
+
};
|
|
34
|
+
});
|
|
22
35
|
Object.assign(this, init);
|
|
23
36
|
this.router = new this.routerClass();
|
|
24
37
|
this.middlewareRouters = [];
|
|
25
38
|
this.tempPath = null;
|
|
26
39
|
}
|
|
27
|
-
get(path, handler) {
|
|
28
|
-
return this.addRoute('get', path, handler);
|
|
29
|
-
}
|
|
30
|
-
post(path, handler) {
|
|
31
|
-
return this.addRoute('post', path, handler);
|
|
32
|
-
}
|
|
33
|
-
put(path, handler) {
|
|
34
|
-
return this.addRoute('put', path, handler);
|
|
35
|
-
}
|
|
36
|
-
head(path, handler) {
|
|
37
|
-
return this.addRoute('head', path, handler);
|
|
38
|
-
}
|
|
39
|
-
delete(path, handler) {
|
|
40
|
-
return this.addRoute('delete', path, handler);
|
|
41
|
-
}
|
|
42
|
-
options(path, handler) {
|
|
43
|
-
return this.addRoute('options', path, handler);
|
|
44
|
-
}
|
|
45
|
-
patch(path, handler) {
|
|
46
|
-
return this.addRoute('patch', path, handler);
|
|
47
|
-
}
|
|
48
|
-
all(path, handler) {
|
|
49
|
-
return this.addRoute('all', path, handler);
|
|
50
|
-
}
|
|
51
40
|
route(path) {
|
|
52
41
|
const newHono = new Hono();
|
|
53
42
|
newHono.tempPath = path;
|
|
@@ -88,29 +77,20 @@ class Hono {
|
|
|
88
77
|
const result = await this.matchRoute(method, path);
|
|
89
78
|
// Methods for Request object
|
|
90
79
|
request.param = (key) => {
|
|
91
|
-
if (result)
|
|
80
|
+
if (result)
|
|
92
81
|
return result.params[key];
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
request.header = (name) => {
|
|
96
|
-
return request.headers.get(name);
|
|
97
|
-
};
|
|
98
|
-
request.query = (key) => {
|
|
99
|
-
const url = new URL(c.req.url);
|
|
100
|
-
return url.searchParams.get(key);
|
|
101
82
|
};
|
|
102
83
|
const handler = result ? result.handler : this.notFoundHandler;
|
|
103
84
|
const middleware = [];
|
|
104
85
|
for (const mr of this.middlewareRouters) {
|
|
105
86
|
const mwResult = mr.match(router_1.METHOD_NAME_OF_ALL, path);
|
|
106
|
-
if (mwResult)
|
|
87
|
+
if (mwResult)
|
|
107
88
|
middleware.push(mwResult.handler);
|
|
108
|
-
}
|
|
109
89
|
}
|
|
110
90
|
const wrappedHandler = async (context, next) => {
|
|
111
91
|
const res = await handler(context);
|
|
112
92
|
if (!(res instanceof Response)) {
|
|
113
|
-
throw new TypeError('response must be a
|
|
93
|
+
throw new TypeError('response must be a instance of Response');
|
|
114
94
|
}
|
|
115
95
|
context.res = res;
|
|
116
96
|
await next();
|
|
@@ -129,7 +109,7 @@ class Hono {
|
|
|
129
109
|
return this.dispatch(request, env, event);
|
|
130
110
|
}
|
|
131
111
|
request(input, requestInit) {
|
|
132
|
-
const req = new Request(input, requestInit);
|
|
112
|
+
const req = input instanceof Request ? input : new Request(input, requestInit);
|
|
133
113
|
return this.dispatch(req);
|
|
134
114
|
}
|
|
135
115
|
fire() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
export declare const basicAuth: (options: {
|
|
3
4
|
username: string;
|
|
4
5
|
password: string;
|
|
@@ -7,4 +8,4 @@ export declare const basicAuth: (options: {
|
|
|
7
8
|
}, ...users: {
|
|
8
9
|
username: string;
|
|
9
10
|
password: string;
|
|
10
|
-
}[]) => (ctx: Context, next:
|
|
11
|
+
}[]) => (ctx: Context, next: Next) => Promise<void>;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
declare global {
|
|
3
4
|
interface Request {
|
|
4
5
|
cookie: (name: string) => string;
|
|
5
6
|
}
|
|
6
7
|
}
|
|
7
|
-
declare module '
|
|
8
|
+
declare module '@/context' {
|
|
8
9
|
interface Context {
|
|
9
10
|
cookie: (name: string, value: string, options?: CookieOptions) => void;
|
|
10
11
|
}
|
|
@@ -22,4 +23,4 @@ export declare type CookieOptions = {
|
|
|
22
23
|
signed?: boolean;
|
|
23
24
|
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
24
25
|
};
|
|
25
|
-
export declare const cookie: () => (c: Context, next:
|
|
26
|
+
export declare const cookie: () => (c: Context, next: Next) => Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
declare type CORSOptions = {
|
|
3
4
|
origin: string;
|
|
4
5
|
allowMethods?: string[];
|
|
@@ -7,5 +8,5 @@ declare type CORSOptions = {
|
|
|
7
8
|
credentials?: boolean;
|
|
8
9
|
exposeHeaders?: string[];
|
|
9
10
|
};
|
|
10
|
-
export declare const cors: (options?: CORSOptions) => (c: Context, next:
|
|
11
|
+
export declare const cors: (options?: CORSOptions) => (c: Context, next: Next) => Promise<void>;
|
|
11
12
|
export {};
|
|
File without changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
declare type ETagOptions = {
|
|
3
4
|
weak: boolean;
|
|
4
5
|
};
|
|
5
|
-
export declare const etag: (options?: ETagOptions) => (c: Context, next:
|
|
6
|
+
export declare const etag: (options?: ETagOptions) => (c: Context, next: Next) => Promise<void>;
|
|
6
7
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.etag = void 0;
|
|
4
|
-
const crypto_1 = require("../../utils/crypto");
|
|
5
4
|
const body_1 = require("../../utils/body");
|
|
5
|
+
const crypto_1 = require("../../utils/crypto");
|
|
6
6
|
const etag = (options = { weak: false }) => {
|
|
7
7
|
return async (c, next) => {
|
|
8
8
|
const ifNoneMatch = c.req.header('If-None-Match') || c.req.header('if-none-match');
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import type { GraphQLSchema, ValidationRule, GraphQLFormattedError } from 'graphql';
|
|
1
3
|
import type { Context } from '../../context';
|
|
2
|
-
import type {
|
|
4
|
+
import type { Next } from '../../hono';
|
|
3
5
|
declare type Options = {
|
|
4
6
|
schema: GraphQLSchema;
|
|
5
7
|
rootValue?: unknown;
|
|
6
8
|
pretty?: boolean;
|
|
7
9
|
validationRules?: ReadonlyArray<ValidationRule>;
|
|
8
10
|
};
|
|
9
|
-
export declare const graphqlServer: (options: Options) => (c: Context, next:
|
|
11
|
+
export declare const graphqlServer: (options: Options) => (c: Context, next: Next) => Promise<void>;
|
|
10
12
|
export interface GraphQLParams {
|
|
11
13
|
query: string | null;
|
|
12
14
|
variables: {
|
|
@@ -16,10 +18,11 @@ export interface GraphQLParams {
|
|
|
16
18
|
raw: boolean;
|
|
17
19
|
}
|
|
18
20
|
export declare const getGraphQLParams: (request: Request) => Promise<GraphQLParams>;
|
|
19
|
-
export declare const errorMessages: (messages: string[]) => {
|
|
21
|
+
export declare const errorMessages: (messages: string[], graphqlErrors?: readonly GraphQLError[] | readonly GraphQLFormattedError[]) => {
|
|
22
|
+
errors: readonly GraphQLError[] | readonly GraphQLFormattedError[];
|
|
23
|
+
} | {
|
|
20
24
|
errors: {
|
|
21
25
|
message: string;
|
|
22
26
|
}[];
|
|
23
27
|
};
|
|
24
|
-
export declare const graphiQLResponse: () => void;
|
|
25
28
|
export {};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Based on the code in the `express-graphql` package.
|
|
3
3
|
// https://github.com/graphql/express-graphql/blob/main/src/index.ts
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
6
|
-
const parse_body_1 = require("./parse-body");
|
|
5
|
+
exports.errorMessages = exports.getGraphQLParams = exports.graphqlServer = void 0;
|
|
7
6
|
const graphql_1 = require("graphql");
|
|
7
|
+
const parse_body_1 = require("../../middleware/graphql-server/parse-body");
|
|
8
8
|
const graphqlServer = (options) => {
|
|
9
9
|
var _a, _b;
|
|
10
10
|
const schema = options.schema;
|
|
@@ -27,7 +27,8 @@ const graphqlServer = (options) => {
|
|
|
27
27
|
}
|
|
28
28
|
catch (e) {
|
|
29
29
|
if (e instanceof Error) {
|
|
30
|
-
|
|
30
|
+
console.error(`${e.stack || e.message}`);
|
|
31
|
+
c.res = c.json((0, exports.errorMessages)([e.message], [e]), 400);
|
|
31
32
|
}
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
@@ -39,7 +40,7 @@ const graphqlServer = (options) => {
|
|
|
39
40
|
const schemaValidationErrors = (0, graphql_1.validateSchema)(schema);
|
|
40
41
|
if (schemaValidationErrors.length > 0) {
|
|
41
42
|
// Return 500: Internal Server Error if invalid schema.
|
|
42
|
-
c.res = c.json((0, exports.errorMessages)(['GraphQL schema validation error.']), 500);
|
|
43
|
+
c.res = c.json((0, exports.errorMessages)(['GraphQL schema validation error.'], schemaValidationErrors), 500);
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
46
|
let documentAST;
|
|
@@ -48,14 +49,20 @@ const graphqlServer = (options) => {
|
|
|
48
49
|
}
|
|
49
50
|
catch (syntaxError) {
|
|
50
51
|
// Return 400: Bad Request if any syntax errors errors exist.
|
|
51
|
-
|
|
52
|
+
if (syntaxError instanceof Error) {
|
|
53
|
+
console.error(`${syntaxError.stack || syntaxError.message}`);
|
|
54
|
+
const e = new graphql_1.GraphQLError(syntaxError.message, {
|
|
55
|
+
originalError: syntaxError,
|
|
56
|
+
});
|
|
57
|
+
c.res = c.json((0, exports.errorMessages)(['GraphQL syntax error.'], [e]), 400);
|
|
58
|
+
}
|
|
52
59
|
return;
|
|
53
60
|
}
|
|
54
61
|
// Validate AST, reporting any errors.
|
|
55
62
|
const validationErrors = (0, graphql_1.validate)(schema, documentAST, [...graphql_1.specifiedRules, ...validationRules]);
|
|
56
63
|
if (validationErrors.length > 0) {
|
|
57
64
|
// Return 400: Bad Request if any validation errors exist.
|
|
58
|
-
c.res = c.json((0, exports.errorMessages)(['GraphQL validation error.']), 400);
|
|
65
|
+
c.res = c.json((0, exports.errorMessages)(['GraphQL validation error.'], validationErrors), 400);
|
|
59
66
|
return;
|
|
60
67
|
}
|
|
61
68
|
if (c.req.method === 'GET') {
|
|
@@ -85,13 +92,20 @@ const graphqlServer = (options) => {
|
|
|
85
92
|
operationName: operationName,
|
|
86
93
|
});
|
|
87
94
|
}
|
|
88
|
-
catch (
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
catch (contextError) {
|
|
96
|
+
if (contextError instanceof Error) {
|
|
97
|
+
console.error(`${contextError.stack || contextError.message}`);
|
|
98
|
+
const e = new graphql_1.GraphQLError(contextError.message, {
|
|
99
|
+
originalError: contextError,
|
|
100
|
+
nodes: documentAST,
|
|
101
|
+
});
|
|
102
|
+
// Return 400: Bad Request if any execution context errors exist.
|
|
103
|
+
c.res = c.json((0, exports.errorMessages)(['GraphQL execution context error.'], [e]), 400);
|
|
104
|
+
}
|
|
91
105
|
return;
|
|
92
106
|
}
|
|
93
107
|
if (result.data == null) {
|
|
94
|
-
c.res = c.json((0, exports.errorMessages)([result.errors.toString()]), 500);
|
|
108
|
+
c.res = c.json((0, exports.errorMessages)([result.errors.toString()], result.errors), 500);
|
|
95
109
|
return;
|
|
96
110
|
}
|
|
97
111
|
/*
|
|
@@ -149,16 +163,19 @@ const getGraphQLParams = async (request) => {
|
|
|
149
163
|
return params;
|
|
150
164
|
};
|
|
151
165
|
exports.getGraphQLParams = getGraphQLParams;
|
|
152
|
-
const errorMessages = (messages) => {
|
|
153
|
-
|
|
166
|
+
const errorMessages = (messages, graphqlErrors) => {
|
|
167
|
+
if (graphqlErrors) {
|
|
154
168
|
return {
|
|
155
|
-
|
|
169
|
+
errors: graphqlErrors,
|
|
156
170
|
};
|
|
157
|
-
}
|
|
171
|
+
}
|
|
158
172
|
return {
|
|
159
|
-
errors:
|
|
173
|
+
errors: messages.map((message) => {
|
|
174
|
+
return {
|
|
175
|
+
message: message,
|
|
176
|
+
};
|
|
177
|
+
}),
|
|
160
178
|
};
|
|
161
179
|
};
|
|
162
180
|
exports.errorMessages = errorMessages;
|
|
163
|
-
const graphiQLResponse = () => {
|
|
164
|
-
exports.graphiQLResponse = graphiQLResponse;
|
|
181
|
+
// export const graphiQLResponse = () => {}
|
|
@@ -11,6 +11,9 @@ async function parseBody(req) {
|
|
|
11
11
|
return await req.json();
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
|
+
if (e instanceof Error) {
|
|
15
|
+
console.error(`${e.stack || e.message}`);
|
|
16
|
+
}
|
|
14
17
|
throw Error(`POST body sent invalid JSON: ${e}`);
|
|
15
18
|
}
|
|
16
19
|
case 'application/x-www-form-urlencoded':
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
export declare const logger: (fn?: {
|
|
3
4
|
(...data: any[]): void;
|
|
4
5
|
(...data: any[]): void;
|
|
5
6
|
(message?: any, ...optionalParams: any[]): void;
|
|
6
|
-
}) => (c: Context, next:
|
|
7
|
+
}) => (c: Context, next: Next) => Promise<void>;
|
|
@@ -31,10 +31,10 @@ const colorStatus = (status = 0) => {
|
|
|
31
31
|
};
|
|
32
32
|
return out[(status / 100) | 0];
|
|
33
33
|
};
|
|
34
|
-
function log(fn, prefix, method, path, status,
|
|
34
|
+
function log(fn, prefix, method, path, status, elapsed, contentLength) {
|
|
35
35
|
const out = prefix === LogPrefix.Incoming
|
|
36
36
|
? ` ${prefix} ${method} ${path}`
|
|
37
|
-
: ` ${prefix} ${method} ${path} ${colorStatus(status)} ${
|
|
37
|
+
: ` ${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed} ${contentLength}`;
|
|
38
38
|
fn(out);
|
|
39
39
|
}
|
|
40
40
|
const logger = (fn = console.log) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
declare type Init = {
|
|
3
4
|
root: string;
|
|
4
5
|
};
|
|
5
|
-
export declare const mustache: (init?: Init) => (c: Context, next:
|
|
6
|
+
export declare const mustache: (init?: Init) => (c: Context, next: Next) => Promise<void>;
|
|
6
7
|
export {};
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prettyJSON = void 0;
|
|
4
|
+
const prettyJSON = (options = { space: 2 }) => {
|
|
5
|
+
return async (c, next) => {
|
|
6
|
+
const pretty = c.req.query('pretty') || c.req.query('pretty') === '' ? true : false;
|
|
7
|
+
c.pretty(pretty, options.space);
|
|
8
|
+
await next();
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.prettyJSON = prettyJSON;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
+
import type { Next } from '../../hono';
|
|
2
3
|
declare type Options = {
|
|
3
4
|
root: string;
|
|
4
5
|
};
|
|
5
|
-
export declare const serveStatic: (opt?: Options) => (c: Context, next:
|
|
6
|
+
export declare const serveStatic: (opt?: Options) => (c: Context, next: Next) => Promise<void>;
|
|
6
7
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RegExpRouter } from '
|
|
1
|
+
export { RegExpRouter } from '../../router/reg-exp-router/router';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RegExpRouter = void 0;
|
|
4
|
-
var router_1 = require("
|
|
4
|
+
var router_1 = require("../../router/reg-exp-router/router");
|
|
5
5
|
Object.defineProperty(exports, "RegExpRouter", { enumerable: true, get: function () { return router_1.RegExpRouter; } });
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RegExpRouter = void 0;
|
|
4
4
|
const router_1 = require("../../router");
|
|
5
|
-
const trie_1 = require("
|
|
5
|
+
const trie_1 = require("../../router/reg-exp-router/trie");
|
|
6
6
|
const regExpMatchAll = new RegExp('');
|
|
7
7
|
const emptyParam = {};
|
|
8
8
|
class RegExpRouter extends router_1.Router {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ParamMap, Context } from '
|
|
2
|
-
import { Node } from '
|
|
3
|
-
export type { ParamMap } from '
|
|
1
|
+
import type { ParamMap, Context } from '../../router/reg-exp-router/node';
|
|
2
|
+
import { Node } from '../../router/reg-exp-router/node';
|
|
3
|
+
export type { ParamMap } from '../../router/reg-exp-router/node';
|
|
4
4
|
export declare type ReplacementMap = number[];
|
|
5
5
|
export declare class Trie {
|
|
6
6
|
context: Context;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Trie = void 0;
|
|
4
|
-
const node_1 = require("
|
|
4
|
+
const node_1 = require("../../router/reg-exp-router/node");
|
|
5
5
|
class Trie {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.context = { varIndex: 0 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { TrieRouter } from '
|
|
1
|
+
export { TrieRouter } from '../../router/trie-router/router';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TrieRouter = void 0;
|
|
4
|
-
var router_1 = require("
|
|
4
|
+
var router_1 = require("../../router/trie-router/router");
|
|
5
5
|
Object.defineProperty(exports, "TrieRouter", { enumerable: true, get: function () { return router_1.TrieRouter; } });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Node = void 0;
|
|
4
|
-
const url_1 = require("../../utils/url");
|
|
5
4
|
const router_1 = require("../../router");
|
|
5
|
+
const url_1 = require("../../utils/url");
|
|
6
6
|
const noRoute = () => {
|
|
7
7
|
return null;
|
|
8
8
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TrieRouter = void 0;
|
|
4
4
|
const router_1 = require("../../router");
|
|
5
|
-
const node_1 = require("
|
|
5
|
+
const node_1 = require("../../router/trie-router/node");
|
|
6
6
|
class TrieRouter extends router_1.Router {
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
package/dist/utils/buffer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.timingSafeEqual = exports.equal = void 0;
|
|
4
|
-
const crypto_1 = require("
|
|
4
|
+
const crypto_1 = require("../utils/crypto");
|
|
5
5
|
const equal = (a, b) => {
|
|
6
6
|
if (a === b) {
|
|
7
7
|
return true;
|
package/dist/utils/crypto.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ declare type Data = string | object | boolean;
|
|
|
6
6
|
export declare const sha256: (data: Data) => Promise<string>;
|
|
7
7
|
export declare const sha1: (data: Data) => Promise<string>;
|
|
8
8
|
export declare const createHash: (data: Data, algorithm: Algorithm) => Promise<string>;
|
|
9
|
-
export declare const encodeBase64: (str: string) =>
|
|
10
|
-
export declare const decodeBase64: (str: string) =>
|
|
9
|
+
export declare const encodeBase64: (str: string) => string;
|
|
10
|
+
export declare const decodeBase64: (str: string) => string;
|
|
11
11
|
export {};
|
package/dist/utils/crypto.js
CHANGED
|
@@ -35,6 +35,9 @@ const createHash = async (data, algorithm) => {
|
|
|
35
35
|
};
|
|
36
36
|
exports.createHash = createHash;
|
|
37
37
|
const encodeBase64 = (str) => {
|
|
38
|
+
if (str === null) {
|
|
39
|
+
throw new TypeError('1st argument of "encodeBase64" should not be null.');
|
|
40
|
+
}
|
|
38
41
|
try {
|
|
39
42
|
const encoder = new TextEncoder();
|
|
40
43
|
const bytes = encoder.encode(str);
|
|
@@ -57,6 +60,9 @@ const encodeBase64 = (str) => {
|
|
|
57
60
|
};
|
|
58
61
|
exports.encodeBase64 = encodeBase64;
|
|
59
62
|
const decodeBase64 = (str) => {
|
|
63
|
+
if (str === null) {
|
|
64
|
+
throw new TypeError('1st argument of "decodeBase64" should not be null.');
|
|
65
|
+
}
|
|
60
66
|
try {
|
|
61
67
|
const text = atob(str);
|
|
62
68
|
const length = text.length;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const getStatusText: (
|
|
1
|
+
export declare const getStatusText: (statusCode: StatusCode) => string;
|
|
2
|
+
export declare type StatusCode = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 444 | 449 | 450 | 451 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 598 | 599;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getStatusText = void 0;
|
|
4
|
-
const getStatusText = (
|
|
5
|
-
const text = statuses[
|
|
4
|
+
const getStatusText = (statusCode) => {
|
|
5
|
+
const text = statuses[statusCode];
|
|
6
6
|
return text;
|
|
7
7
|
};
|
|
8
8
|
exports.getStatusText = getStatusText;
|
|
9
9
|
const statuses = {
|
|
10
|
+
100: 'Continue',
|
|
11
|
+
101: 'Switching Protocols',
|
|
12
|
+
102: 'Processing',
|
|
13
|
+
103: 'Early Hints',
|
|
10
14
|
200: 'OK',
|
|
11
15
|
201: 'Created',
|
|
12
16
|
202: 'Accepted',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Ultrafast web framework for Cloudflare Workers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -9,60 +9,63 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "jest",
|
|
12
|
-
"lint": "eslint --ext js,ts src .eslintrc.js
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"lint": "eslint --ext js,ts src .eslintrc.js",
|
|
13
|
+
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",
|
|
14
|
+
"build": "rimraf dist && tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
15
|
+
"watch": "tsc -w --project tsconfig.build.json & tsc-alias -w -p tsconfig.build.json",
|
|
15
16
|
"prepublishOnly": "yarn build"
|
|
16
17
|
},
|
|
17
18
|
"exports": {
|
|
18
19
|
".": "./dist/index.js",
|
|
19
|
-
"./basic-auth": "./dist/middleware/basic-auth/
|
|
20
|
-
"./body-parse": "./dist/middleware/body-parse/
|
|
21
|
-
"./cookie": "./dist/middleware/cookie/
|
|
22
|
-
"./cors": "./dist/middleware/cors/
|
|
23
|
-
"./etag": "./dist/middleware/etag/
|
|
24
|
-
"./graphql-server": "./dist/middleware/graphql-server/
|
|
25
|
-
"./logger": "./dist/middleware/logger/
|
|
26
|
-
"./mustache": "./dist/middleware/mustache/
|
|
27
|
-
"./powered-by": "./dist/middleware/powered-by/
|
|
28
|
-
"./
|
|
29
|
-
"./
|
|
20
|
+
"./basic-auth": "./dist/middleware/basic-auth/index.js",
|
|
21
|
+
"./body-parse": "./dist/middleware/body-parse/index.js",
|
|
22
|
+
"./cookie": "./dist/middleware/cookie/index.js",
|
|
23
|
+
"./cors": "./dist/middleware/cors/index.js",
|
|
24
|
+
"./etag": "./dist/middleware/etag/index.js",
|
|
25
|
+
"./graphql-server": "./dist/middleware/graphql-server/index.js",
|
|
26
|
+
"./logger": "./dist/middleware/logger/index.js",
|
|
27
|
+
"./mustache": "./dist/middleware/mustache/index.js",
|
|
28
|
+
"./powered-by": "./dist/middleware/powered-by/index.js",
|
|
29
|
+
"./pretty-json": "./dist/middleware/pretty-json/index.js",
|
|
30
|
+
"./serve-static": "./dist/middleware/serve-static/index.js",
|
|
31
|
+
"./router/trie-router": "./dist/router/trie-router/index.js",
|
|
30
32
|
"./router/reg-exp-router": "./dist/router/reg-exp-router/index.js",
|
|
31
|
-
"./utils
|
|
32
|
-
"./utils/crypto": "./dist/utils/crypto.js",
|
|
33
|
-
"./utils/mime": "./dist/utils/mime.js"
|
|
33
|
+
"./utils/*": "./dist/utils/*.js"
|
|
34
34
|
},
|
|
35
35
|
"typesVersions": {
|
|
36
36
|
"*": {
|
|
37
37
|
"basic-auth": [
|
|
38
|
-
"./dist/middleware/basic-auth
|
|
38
|
+
"./dist/middleware/basic-auth"
|
|
39
39
|
],
|
|
40
40
|
"body-parse": [
|
|
41
|
-
"./dist/middleware/body-parse
|
|
41
|
+
"./dist/middleware/body-parse"
|
|
42
42
|
],
|
|
43
43
|
"cookie": [
|
|
44
|
-
"./dist/middleware/cookie
|
|
44
|
+
"./dist/middleware/cookie"
|
|
45
45
|
],
|
|
46
46
|
"cors": [
|
|
47
|
-
"./dist/middleware/cors
|
|
47
|
+
"./dist/middleware/cors"
|
|
48
48
|
],
|
|
49
49
|
"etag": [
|
|
50
|
-
"./dist/middleware/etag
|
|
50
|
+
"./dist/middleware/etag"
|
|
51
51
|
],
|
|
52
52
|
"graphql-server": [
|
|
53
|
-
"./dist/middleware/graphql-server
|
|
53
|
+
"./dist/middleware/graphql-server"
|
|
54
54
|
],
|
|
55
55
|
"logger": [
|
|
56
|
-
"./dist/middleware/logger
|
|
56
|
+
"./dist/middleware/logger"
|
|
57
57
|
],
|
|
58
58
|
"mustache": [
|
|
59
|
-
"./dist/middleware/mustache
|
|
59
|
+
"./dist/middleware/mustache"
|
|
60
60
|
],
|
|
61
61
|
"powered-by": [
|
|
62
|
-
"./dist/middleware/powered-by
|
|
62
|
+
"./dist/middleware/powered-by"
|
|
63
|
+
],
|
|
64
|
+
"pretty-json": [
|
|
65
|
+
"./dist/middleware/pretty-json"
|
|
63
66
|
],
|
|
64
67
|
"serve-static": [
|
|
65
|
-
"./dist/middleware/serve-static
|
|
68
|
+
"./dist/middleware/serve-static"
|
|
66
69
|
],
|
|
67
70
|
"router/trie-router": [
|
|
68
71
|
"./dist/router/trie-router/router.d.ts"
|
|
@@ -70,14 +73,8 @@
|
|
|
70
73
|
"router/reg-exp-router": [
|
|
71
74
|
"./dist/router/reg-exp-router/router.d.ts"
|
|
72
75
|
],
|
|
73
|
-
"utils
|
|
74
|
-
"./dist/utils
|
|
75
|
-
],
|
|
76
|
-
"utils/crypto": [
|
|
77
|
-
"./dist/utils/crypto.d.ts"
|
|
78
|
-
],
|
|
79
|
-
"utils/mime": [
|
|
80
|
-
"./dist/utils/mime.d.ts"
|
|
76
|
+
"utils/*": [
|
|
77
|
+
"./dist/utils/*"
|
|
81
78
|
]
|
|
82
79
|
}
|
|
83
80
|
},
|
|
@@ -126,6 +123,7 @@
|
|
|
126
123
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
127
124
|
"rimraf": "^3.0.2",
|
|
128
125
|
"ts-jest": "^27.1.2",
|
|
126
|
+
"tsc-alias": "^1.6.6",
|
|
129
127
|
"typescript": "^4.5.5"
|
|
130
128
|
},
|
|
131
129
|
"engines": {
|