@eggjs/koa 3.0.1 → 3.1.0-beta.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
@@ -6,8 +6,6 @@
6
6
 
7
7
  [![NPM version](https://img.shields.io/npm/v/@eggjs/koa.svg?style=flat-square)](https://npmjs.org/package/@eggjs/koa)
8
8
  [![NPM download](https://img.shields.io/npm/dm/@eggjs/koa.svg?style=flat-square)](https://npmjs.org/package/@eggjs/koa)
9
- [![Node.js CI](https://github.com/eggjs/koa/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/eggjs/koa/actions/workflows/node.js.yml)
10
- [![Test coverage](https://img.shields.io/codecov/c/github/eggjs/koa.svg?style=flat-square)](https://codecov.io/gh/eggjs/koa)
11
9
  [![Known Vulnerabilities](https://snyk.io/test/npm/@eggjs/koa/badge.svg?style=flat-square)](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
- [![Contributors](https://contrib.rocks/image?repo=eggjs/koa)](https://github.com/eggjs/koa/graphs/contributors)
184
+ [![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)
187
185
 
188
186
  Made with [contributors-img](https://contrib.rocks).
@@ -1,127 +1,131 @@
1
- import util from 'node:util';
2
- import Emitter from 'node:events';
3
- import type { AsyncLocalStorage } from 'node:async_hooks';
4
- import http, { type IncomingMessage, type ServerResponse } from 'node:http';
5
- import { Context } from './context.ts';
6
- import { Request } from './request.ts';
7
- import { Response } from './response.ts';
8
- import type { CustomError, AnyProto } from './types.ts';
9
- export type ProtoImplClass<T = object> = new (...args: any[]) => T;
10
- export type Next = () => Promise<void>;
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
- export type MiddlewareFunc<T extends Context = Context> = _MiddlewareFunc<T> & {
13
- _name?: string;
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
- export declare class Application extends Emitter {
20
- [key: symbol]: unknown;
21
- /**
22
- * Make HttpError available to consumers of the library so that consumers don't
23
- * have a direct dependency upon `http-errors`
24
- */
25
- static HttpError: import("http-errors").HttpErrorConstructor<number>;
26
- protected _proxy: boolean;
27
- protected _env: string;
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
- proxyIpHeader: string;
30
- maxIpsCount: number;
31
- protected _keys?: string[];
32
- middleware: MiddlewareFunc<Context>[];
33
- ctxStorage: AsyncLocalStorage<Context>;
34
- silent: boolean;
35
- ContextClass: ProtoImplClass<Context>;
36
- context: AnyProto;
37
- RequestClass: ProtoImplClass<Request>;
38
- request: AnyProto;
39
- ResponseClass: ProtoImplClass<Response>;
40
- response: AnyProto;
41
- /**
42
- * Initialize a new `Application`.
43
- *
44
- * @param {object} [options] Application options
45
- * @param {string} [options.env] Environment, default is `development`
46
- * @param {string[]} [options.keys] Signed cookie keys
47
- * @param {boolean} [options.proxy] Trust proxy headers
48
- * @param {number} [options.subdomainOffset] Subdomain offset
49
- * @param {string} [options.proxyIpHeader] Proxy IP header, defaults to X-Forwarded-For
50
- * @param {number} [options.maxIpsCount] Max IPs read from proxy IP header, default to 0 (means infinity)
51
- */
52
- constructor(options?: {
53
- proxy?: boolean;
54
- subdomainOffset?: number;
55
- proxyIpHeader?: string;
56
- maxIpsCount?: number;
57
- env?: string;
58
- keys?: string[];
59
- });
60
- get keys(): string[] | undefined;
61
- set keys(value: string[] | undefined);
62
- get env(): string;
63
- set env(value: string);
64
- get proxy(): boolean;
65
- set proxy(value: boolean);
66
- /**
67
- * Shorthand for:
68
- *
69
- * http.createServer(app.callback()).listen(...)
70
- */
71
- listen(...args: any[]): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
72
- /**
73
- * Return JSON representation.
74
- * We only bother showing settings.
75
- */
76
- toJSON(): {
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
- export {};
130
+ //#endregion
131
+ export { Application, MiddlewareFunc, Next, ProtoImplClass };