@eggjs/koa 3.1.0-beta.3 → 3.1.0-beta.31

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.
@@ -1,131 +1,114 @@
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>;
1
+ import Emitter from 'node:events';
2
+ import type { AsyncLocalStorage } from 'node:async_hooks';
3
+ import http, { type IncomingMessage, type ServerResponse } from 'node:http';
4
+ import { HttpError } from 'http-errors';
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 { Context, Request, Response };
10
+ export type ProtoImplClass<T = object> = new (...args: any[]) => T;
11
+ export type Next = () => Promise<void>;
14
12
  type _MiddlewareFunc<T> = (ctx: T, next: Next) => Promise<void> | void;
15
- type MiddlewareFunc<T extends Context = Context> = _MiddlewareFunc<T> & {
16
- _name?: string;
13
+ export type MiddlewareFunc<T extends Context = Context> = _MiddlewareFunc<T> & {
14
+ _name?: string;
17
15
  };
18
16
  /**
19
17
  * Expose `Application` class.
20
18
  * Inherits from `Emitter.prototype`.
21
19
  */
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(): {
20
+ export declare class Application extends Emitter {
21
+ [key: symbol]: unknown;
22
+ /**
23
+ * Make HttpError available to consumers of the library so that consumers don't
24
+ * have a direct dependency upon `http-errors`
25
+ */
26
+ static HttpError: typeof HttpError;
27
+ protected _proxy: boolean;
28
+ protected _env: string;
80
29
  subdomainOffset: number;
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;
30
+ proxyIpHeader: string;
31
+ maxIpsCount: number;
32
+ protected _keys?: string[];
33
+ middleware: MiddlewareFunc<Context>[];
34
+ ctxStorage: AsyncLocalStorage<Context>;
35
+ silent: boolean;
36
+ ContextClass: ProtoImplClass<Context>;
37
+ context: AnyProto;
38
+ RequestClass: ProtoImplClass<Request>;
39
+ request: AnyProto;
40
+ ResponseClass: ProtoImplClass<Response>;
41
+ response: AnyProto;
42
+ /**
43
+ * Initialize a new `Application`.
44
+ *
45
+ * @param {object} [options] Application options
46
+ * @param {string} [options.env] Environment, default is `development`
47
+ * @param {string[]} [options.keys] Signed cookie keys
48
+ * @param {boolean} [options.proxy] Trust proxy headers
49
+ * @param {number} [options.subdomainOffset] Subdomain offset
50
+ * @param {string} [options.proxyIpHeader] Proxy IP header, defaults to X-Forwarded-For
51
+ * @param {number} [options.maxIpsCount] Max IPs read from proxy IP header, default to 0 (means infinity)
52
+ */
53
+ constructor(options?: {
54
+ proxy?: boolean;
55
+ subdomainOffset?: number;
56
+ proxyIpHeader?: string;
57
+ maxIpsCount?: number;
58
+ env?: string;
59
+ keys?: string[];
60
+ });
61
+ get keys(): string[] | undefined;
62
+ set keys(value: string[] | undefined);
63
+ get env(): string;
64
+ set env(value: string);
65
+ get proxy(): boolean;
66
+ set proxy(value: boolean);
67
+ /**
68
+ * Shorthand for:
69
+ *
70
+ * http.createServer(app.callback()).listen(...)
71
+ */
72
+ listen(...args: any[]): http.Server;
73
+ /**
74
+ * Return JSON representation.
75
+ * We only bother showing settings.
76
+ */
77
+ toJSON(): object;
78
+ /**
79
+ * Inspect implementation.
80
+ */
81
+ inspect(): object;
82
+ /**
83
+ * Use the given middleware `fn`.
84
+ */
85
+ use<T extends Context = Context>(fn: MiddlewareFunc<T>): this;
86
+ /**
87
+ * Return a request handler callback
88
+ * for node's native http server.
89
+ */
90
+ callback(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
91
+ /**
92
+ * return current context from async local storage
93
+ */
94
+ get currentContext(): Context | undefined;
95
+ /**
96
+ * Handle request in callback.
97
+ * @private
98
+ */
99
+ protected handleRequest(ctx: Context, fnMiddleware: (ctx: Context) => Promise<void>): Promise<void>;
100
+ /**
101
+ * Initialize a new context.
102
+ * @private
103
+ */
104
+ createContext(req: IncomingMessage, res: ServerResponse): Context;
105
+ /**
106
+ * Default error handler.
107
+ * @private
108
+ */
109
+ protected onerror(err: CustomError): void;
110
+ /**
111
+ * Response helper.
112
+ */
113
+ protected _respond(ctx: Context): void;
129
114
  }
130
- //#endregion
131
- export { Application, MiddlewareFunc, Next, ProtoImplClass };