@eggjs/koa 3.0.1 → 3.1.0-beta.2
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 +1 -3
- package/dist/application.d.ts +123 -119
- package/dist/application.js +229 -274
- package/dist/context.d.ts +225 -220
- package/dist/context.js +304 -350
- package/dist/index.d.ts +6 -7
- package/dist/index.js +9 -6
- package/dist/request.d.ts +341 -336
- package/dist/request.js +456 -518
- package/dist/response.d.ts +230 -224
- package/dist/response.js +387 -472
- package/dist/types.d.ts +12 -9
- package/package.json +25 -41
- package/dist/types.js +0 -2
- package/src/application.ts +0 -322
- package/src/context.ts +0 -534
- package/src/index.ts +0 -9
- package/src/request.ts +0 -670
- package/src/response.ts +0 -524
- package/src/types.ts +0 -13
package/Readme.md
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
[](https://npmjs.org/package/@eggjs/koa)
|
|
8
8
|
[](https://npmjs.org/package/@eggjs/koa)
|
|
9
|
-
[](https://github.com/eggjs/koa/actions/workflows/node.js.yml)
|
|
10
|
-
[](https://codecov.io/gh/eggjs/koa)
|
|
11
9
|
[](https://snyk.io/test/npm/@eggjs/koa)
|
|
12
10
|
|
|
13
11
|
Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.
|
|
@@ -183,6 +181,6 @@ To report a security vulnerability, please do not open an issue, as this notifie
|
|
|
183
181
|
|
|
184
182
|
## Contributors
|
|
185
183
|
|
|
186
|
-
[](https://github.com/eggjs/egg/graphs/contributors)
|
|
187
185
|
|
|
188
186
|
Made with [contributors-img](https://contrib.rocks).
|
package/dist/application.d.ts
CHANGED
|
@@ -1,127 +1,131 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Response } from "./response.js";
|
|
2
|
+
import { Request } from "./request.js";
|
|
3
|
+
import { AnyProto, CustomError } from "./types.js";
|
|
4
|
+
import { Context } from "./context.js";
|
|
5
|
+
import util from "node:util";
|
|
6
|
+
import Emitter from "node:events";
|
|
7
|
+
import http, { IncomingMessage, ServerResponse } from "node:http";
|
|
8
|
+
import * as http_errors0 from "http-errors";
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
+
|
|
11
|
+
//#region src/application.d.ts
|
|
12
|
+
type ProtoImplClass<T = object> = new (...args: any[]) => T;
|
|
13
|
+
type Next = () => Promise<void>;
|
|
11
14
|
type _MiddlewareFunc<T> = (ctx: T, next: Next) => Promise<void> | void;
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
type MiddlewareFunc<T extends Context = Context> = _MiddlewareFunc<T> & {
|
|
16
|
+
_name?: string;
|
|
14
17
|
};
|
|
15
18
|
/**
|
|
16
19
|
* Expose `Application` class.
|
|
17
20
|
* Inherits from `Emitter.prototype`.
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
declare class Application extends Emitter {
|
|
23
|
+
[key: symbol]: unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Make HttpError available to consumers of the library so that consumers don't
|
|
26
|
+
* have a direct dependency upon `http-errors`
|
|
27
|
+
*/
|
|
28
|
+
static HttpError: http_errors0.HttpErrorConstructor<number>;
|
|
29
|
+
protected _proxy: boolean;
|
|
30
|
+
protected _env: string;
|
|
31
|
+
subdomainOffset: number;
|
|
32
|
+
proxyIpHeader: string;
|
|
33
|
+
maxIpsCount: number;
|
|
34
|
+
protected _keys?: string[];
|
|
35
|
+
middleware: MiddlewareFunc<Context>[];
|
|
36
|
+
ctxStorage: AsyncLocalStorage<Context>;
|
|
37
|
+
silent: boolean;
|
|
38
|
+
ContextClass: ProtoImplClass<Context>;
|
|
39
|
+
context: AnyProto;
|
|
40
|
+
RequestClass: ProtoImplClass<Request>;
|
|
41
|
+
request: AnyProto;
|
|
42
|
+
ResponseClass: ProtoImplClass<Response>;
|
|
43
|
+
response: AnyProto;
|
|
44
|
+
/**
|
|
45
|
+
* Initialize a new `Application`.
|
|
46
|
+
*
|
|
47
|
+
* @param {object} [options] Application options
|
|
48
|
+
* @param {string} [options.env] Environment, default is `development`
|
|
49
|
+
* @param {string[]} [options.keys] Signed cookie keys
|
|
50
|
+
* @param {boolean} [options.proxy] Trust proxy headers
|
|
51
|
+
* @param {number} [options.subdomainOffset] Subdomain offset
|
|
52
|
+
* @param {string} [options.proxyIpHeader] Proxy IP header, defaults to X-Forwarded-For
|
|
53
|
+
* @param {number} [options.maxIpsCount] Max IPs read from proxy IP header, default to 0 (means infinity)
|
|
54
|
+
*/
|
|
55
|
+
constructor(options?: {
|
|
56
|
+
proxy?: boolean;
|
|
57
|
+
subdomainOffset?: number;
|
|
58
|
+
proxyIpHeader?: string;
|
|
59
|
+
maxIpsCount?: number;
|
|
60
|
+
env?: string;
|
|
61
|
+
keys?: string[];
|
|
62
|
+
});
|
|
63
|
+
get keys(): string[] | undefined;
|
|
64
|
+
set keys(value: string[] | undefined);
|
|
65
|
+
get env(): string;
|
|
66
|
+
set env(value: string);
|
|
67
|
+
get proxy(): boolean;
|
|
68
|
+
set proxy(value: boolean);
|
|
69
|
+
/**
|
|
70
|
+
* Shorthand for:
|
|
71
|
+
*
|
|
72
|
+
* http.createServer(app.callback()).listen(...)
|
|
73
|
+
*/
|
|
74
|
+
listen(...args: any[]): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Return JSON representation.
|
|
77
|
+
* We only bother showing settings.
|
|
78
|
+
*/
|
|
79
|
+
toJSON(): {
|
|
28
80
|
subdomainOffset: number;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
subdomainOffset: number;
|
|
78
|
-
proxy: boolean;
|
|
79
|
-
env: string;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Inspect implementation.
|
|
83
|
-
*/
|
|
84
|
-
inspect(): {
|
|
85
|
-
subdomainOffset: number;
|
|
86
|
-
proxy: boolean;
|
|
87
|
-
env: string;
|
|
88
|
-
};
|
|
89
|
-
[util.inspect.custom](): {
|
|
90
|
-
subdomainOffset: number;
|
|
91
|
-
proxy: boolean;
|
|
92
|
-
env: string;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Use the given middleware `fn`.
|
|
96
|
-
*/
|
|
97
|
-
use<T extends Context = Context>(fn: MiddlewareFunc<T>): this;
|
|
98
|
-
/**
|
|
99
|
-
* Return a request handler callback
|
|
100
|
-
* for node's native http server.
|
|
101
|
-
*/
|
|
102
|
-
callback(): (req: IncomingMessage, res: ServerResponse) => Promise<void | http.ServerResponse<http.IncomingMessage>>;
|
|
103
|
-
/**
|
|
104
|
-
* return current context from async local storage
|
|
105
|
-
*/
|
|
106
|
-
get currentContext(): Context | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* Handle request in callback.
|
|
109
|
-
* @private
|
|
110
|
-
*/
|
|
111
|
-
protected handleRequest(ctx: Context, fnMiddleware: (ctx: Context) => Promise<void>): Promise<void | http.ServerResponse<http.IncomingMessage>>;
|
|
112
|
-
/**
|
|
113
|
-
* Initialize a new context.
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
createContext(req: IncomingMessage, res: ServerResponse): Context;
|
|
117
|
-
/**
|
|
118
|
-
* Default error handler.
|
|
119
|
-
* @private
|
|
120
|
-
*/
|
|
121
|
-
protected onerror(err: CustomError): void;
|
|
122
|
-
/**
|
|
123
|
-
* Response helper.
|
|
124
|
-
*/
|
|
125
|
-
protected _respond(ctx: Context): http.ServerResponse<http.IncomingMessage> | undefined;
|
|
81
|
+
proxy: boolean;
|
|
82
|
+
env: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Inspect implementation.
|
|
86
|
+
*/
|
|
87
|
+
inspect(): {
|
|
88
|
+
subdomainOffset: number;
|
|
89
|
+
proxy: boolean;
|
|
90
|
+
env: string;
|
|
91
|
+
};
|
|
92
|
+
[util.inspect.custom](): {
|
|
93
|
+
subdomainOffset: number;
|
|
94
|
+
proxy: boolean;
|
|
95
|
+
env: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Use the given middleware `fn`.
|
|
99
|
+
*/
|
|
100
|
+
use<T extends Context = Context>(fn: MiddlewareFunc<T>): this;
|
|
101
|
+
/**
|
|
102
|
+
* Return a request handler callback
|
|
103
|
+
* for node's native http server.
|
|
104
|
+
*/
|
|
105
|
+
callback(): (req: IncomingMessage, res: ServerResponse) => Promise<void | http.ServerResponse<http.IncomingMessage>>;
|
|
106
|
+
/**
|
|
107
|
+
* return current context from async local storage
|
|
108
|
+
*/
|
|
109
|
+
get currentContext(): Context | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Handle request in callback.
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
protected handleRequest(ctx: Context, fnMiddleware: (ctx: Context) => Promise<void>): Promise<void | http.ServerResponse<http.IncomingMessage>>;
|
|
115
|
+
/**
|
|
116
|
+
* Initialize a new context.
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
createContext(req: IncomingMessage, res: ServerResponse): Context;
|
|
120
|
+
/**
|
|
121
|
+
* Default error handler.
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
protected onerror(err: CustomError): void;
|
|
125
|
+
/**
|
|
126
|
+
* Response helper.
|
|
127
|
+
*/
|
|
128
|
+
protected _respond(ctx: Context): http.ServerResponse<http.IncomingMessage> | undefined;
|
|
126
129
|
}
|
|
127
|
-
|
|
130
|
+
//#endregion
|
|
131
|
+
export { Application, MiddlewareFunc, Next, ProtoImplClass };
|