@eggjs/koa 3.1.0-beta.35 → 3.1.0-beta.36

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