egg 4.1.0-beta.19 → 4.1.0-beta.20

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.
Files changed (105) hide show
  1. package/dist/AgentWorkerLoader-DG_hAClt.d.ts +17 -0
  2. package/dist/AgentWorkerLoader-D_hceBRW.js +24 -0
  3. package/dist/AppWorkerLoader-CAtxJvGl.js +37 -0
  4. package/dist/AppWorkerLoader-CT875rYM.d.ts +22 -0
  5. package/dist/CookieLimitExceedError-CAW0HYJw.d.ts +8 -0
  6. package/dist/CookieLimitExceedError-DLGakbeu.js +15 -0
  7. package/dist/EggApplicationLoader-CMe1VQt1.js +7 -0
  8. package/dist/EggApplicationLoader-PnIvd5oV.d.ts +8 -0
  9. package/dist/IMessenger-C9g6ypSI.d.ts +54 -0
  10. package/dist/MessageUnhandledRejectionError-Lq5fWw24.d.ts +8 -0
  11. package/dist/MessageUnhandledRejectionError-oD_E1Ewl.js +15 -0
  12. package/dist/agent-BfFWeJj4.js +55 -0
  13. package/dist/agent.d.ts +11 -1
  14. package/dist/agent.js +1 -1
  15. package/dist/app/extend/context.d.ts +11 -182
  16. package/dist/app/extend/context.js +1 -242
  17. package/dist/app/extend/helper.d.ts +11 -41
  18. package/dist/app/extend/helper.js +3 -45
  19. package/dist/app/extend/request.d.ts +11 -135
  20. package/dist/app/extend/request.js +2 -224
  21. package/dist/app/extend/response.d.ts +1 -28
  22. package/dist/app/extend/response.js +1 -34
  23. package/dist/app/middleware/meta.d.ts +11 -10
  24. package/dist/app/middleware/notfound.d.ts +11 -10
  25. package/dist/app/middleware/site_file.d.ts +11 -12
  26. package/dist/application-DVwFQSa9.js +208 -0
  27. package/dist/base-KLVtlzUD.d.ts +12 -0
  28. package/dist/base_context_class-Xc1OZql9.js +19 -0
  29. package/dist/base_context_logger-CZU59PGA.js +58 -0
  30. package/dist/base_hook_class-D0Gu2p8r.js +26 -0
  31. package/dist/base_hook_class-R8A8gm1s.d.ts +1109 -0
  32. package/dist/config/config.default.d.ts +11 -2
  33. package/dist/config/config.default.js +26 -2
  34. package/dist/context-D1Wg7CXs.js +244 -0
  35. package/dist/context_httpclient-BpRMdJhf.js +29 -0
  36. package/dist/egg-DVo5e_lr.js +800 -0
  37. package/dist/error-BYo_LRnd.js +1 -0
  38. package/dist/helper-B3PKMPXq.js +47 -0
  39. package/dist/httpclient-C1QPc_R7.js +36 -0
  40. package/dist/index-CUPkUUOR.d.ts +1 -0
  41. package/dist/index-CkgLZdB4.d.ts +1 -0
  42. package/dist/index.d.ts +12 -20
  43. package/dist/index.js +26 -19
  44. package/dist/lib/agent.d.ts +11 -21
  45. package/dist/lib/agent.js +20 -54
  46. package/dist/lib/application.d.ts +11 -59
  47. package/dist/lib/application.js +21 -207
  48. package/dist/lib/core/base_context_class.d.ts +11 -22
  49. package/dist/lib/core/base_context_class.js +2 -17
  50. package/dist/lib/core/base_context_logger.d.ts +11 -39
  51. package/dist/lib/core/base_context_logger.js +1 -56
  52. package/dist/lib/core/base_hook_class.d.ts +11 -17
  53. package/dist/lib/core/base_hook_class.js +1 -24
  54. package/dist/lib/core/context_httpclient.d.ts +11 -21
  55. package/dist/lib/core/context_httpclient.js +1 -27
  56. package/dist/lib/core/httpclient.d.ts +12 -17
  57. package/dist/lib/core/httpclient.js +1 -34
  58. package/dist/lib/core/logger.d.ts +11 -1
  59. package/dist/lib/core/logger.js +1 -29
  60. package/dist/lib/core/messenger/IMessenger.d.ts +1 -53
  61. package/dist/lib/core/messenger/base.d.ts +12 -11
  62. package/dist/lib/core/messenger/base.js +15 -27
  63. package/dist/lib/core/messenger/index.d.ts +12 -11
  64. package/dist/lib/core/messenger/index.js +15 -11
  65. package/dist/lib/core/messenger/ipc.d.ts +12 -4
  66. package/dist/lib/core/messenger/ipc.js +15 -128
  67. package/dist/lib/core/messenger/local.d.ts +12 -4
  68. package/dist/lib/core/messenger/local.js +15 -124
  69. package/dist/lib/core/utils.js +1 -46
  70. package/dist/lib/egg.d.ts +12 -285
  71. package/dist/lib/egg.js +15 -518
  72. package/dist/lib/error/CookieLimitExceedError.d.ts +1 -7
  73. package/dist/lib/error/CookieLimitExceedError.js +1 -13
  74. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +1 -7
  75. package/dist/lib/error/MessageUnhandledRejectionError.js +1 -13
  76. package/dist/lib/error/index.d.ts +3 -2
  77. package/dist/lib/error/index.js +3 -2
  78. package/dist/lib/loader/AgentWorkerLoader.d.ts +2 -16
  79. package/dist/lib/loader/AgentWorkerLoader.js +2 -22
  80. package/dist/lib/loader/AppWorkerLoader.d.ts +2 -21
  81. package/dist/lib/loader/AppWorkerLoader.js +2 -35
  82. package/dist/lib/loader/EggApplicationLoader.d.ts +1 -7
  83. package/dist/lib/loader/EggApplicationLoader.js +1 -5
  84. package/dist/lib/loader/index.d.ts +4 -3
  85. package/dist/lib/loader/index.js +4 -3
  86. package/dist/lib/start.d.ts +11 -27
  87. package/dist/lib/start.js +25 -34
  88. package/dist/lib/types.d.ts +12 -283
  89. package/dist/lib/types.js +2 -32
  90. package/dist/lib/types.plugin.d.ts +1 -12
  91. package/dist/lib/types.plugin.js +1 -12
  92. package/dist/lib/utils.js +1 -12
  93. package/dist/loader-3myZ-rpm.js +1 -0
  94. package/dist/logger-C4tIcO3S.js +31 -0
  95. package/dist/request-Cy_1DlaX.js +225 -0
  96. package/dist/response-CDeQ9Sx2.js +36 -0
  97. package/dist/response-DlNYDj00.d.ts +29 -0
  98. package/dist/src-BuOjXSrB.js +3 -0
  99. package/dist/start-4E84z796.js +35 -0
  100. package/dist/types-dKSyDnVp.js +32 -0
  101. package/dist/types.plugin-B2v0K0I8.js +14 -0
  102. package/dist/types.plugin-C3D5I7VD.d.ts +12 -0
  103. package/dist/utils-B1Rjsoi9.js +48 -0
  104. package/dist/utils-BDoYg6z6.js +14 -0
  105. package/package.json +22 -22
@@ -1,226 +1,4 @@
1
- import "./response.js";
2
- import { Request as Request$1 } from "@eggjs/core";
3
- import querystring from "node:querystring";
1
+ import "../../response-CDeQ9Sx2.js";
2
+ import { Request } from "../../request-Cy_1DlaX.js";
4
3
 
5
- //#region src/app/extend/request.ts
6
- const QUERY_CACHE = Symbol("request query cache");
7
- const QUERIES_CACHE = Symbol("request queries cache");
8
- const PROTOCOL = Symbol("request protocol");
9
- const HOST = Symbol("request host");
10
- const IPS = Symbol("request ips");
11
- const RE_ARRAY_KEY = /[^[\]]+\[\]$/;
12
- var Request = class extends Request$1 {
13
- /**
14
- * Parse the "Host" header field host
15
- * and support X-Forwarded-Host when a
16
- * proxy is enabled.
17
- * @member {String} Request#host
18
- * @example
19
- * ip + port
20
- * ```js
21
- * this.request.host
22
- * => '127.0.0.1:7001'
23
- * ```
24
- * or domain
25
- * ```js
26
- * this.request.host
27
- * => 'demo.eggjs.org'
28
- * ```
29
- */
30
- get host() {
31
- let host = this[HOST];
32
- if (host) return host;
33
- if (this.app.config.proxy) host = getFromHeaders(this, this.app.config.hostHeaders);
34
- host = host || this.get("host") || "";
35
- this[HOST] = host = host.split(",")[0].trim();
36
- return host;
37
- }
38
- /**
39
- * @member {String} Request#protocol
40
- * @example
41
- * ```js
42
- * this.request.protocol
43
- * => 'https'
44
- * ```
45
- */
46
- get protocol() {
47
- let protocol = this[PROTOCOL];
48
- if (protocol) return protocol;
49
- if (this.socket?.encrypted) {
50
- this[PROTOCOL] = protocol = "https";
51
- return protocol;
52
- }
53
- if (this.app.config.proxy) {
54
- const proto = getFromHeaders(this, this.app.config.protocolHeaders);
55
- if (proto) {
56
- this[PROTOCOL] = protocol = proto.split(/\s*,\s*/)[0];
57
- return protocol;
58
- }
59
- }
60
- this[PROTOCOL] = protocol = this.app.config.protocol || "http";
61
- return protocol;
62
- }
63
- /**
64
- * Get all pass through ip addresses from the request.
65
- * Enable only on `app.config.proxy = true`
66
- *
67
- * @member {Array} Request#ips
68
- * @example
69
- * ```js
70
- * this.request.ips
71
- * => ['100.23.1.2', '201.10.10.2']
72
- * ```
73
- */
74
- get ips() {
75
- let ips = this[IPS];
76
- if (ips) return ips;
77
- if (!this.app.config.proxy) {
78
- this[IPS] = ips = [];
79
- return ips;
80
- }
81
- const val = getFromHeaders(this, this.app.config.ipHeaders);
82
- this[IPS] = ips = val ? val.split(/\s*,\s*/) : [];
83
- let maxIpsCount = this.app.config.maxIpsCount;
84
- if (!maxIpsCount && this.app.config.maxProxyCount) maxIpsCount = this.app.config.maxProxyCount + 1;
85
- if (maxIpsCount > 0) this[IPS] = ips = ips.slice(-maxIpsCount);
86
- return ips;
87
- }
88
- /**
89
- * Get the request remote IPv4 address
90
- * @member {String} Request#ip
91
- * @return {String} IPv4 address
92
- * @example
93
- * ```js
94
- * this.request.ip
95
- * => '127.0.0.1'
96
- * => '111.10.2.1'
97
- * ```
98
- */
99
- get ip() {
100
- if (this._ip) return this._ip;
101
- const ip = this.ips[0] ?? this.socket.remoteAddress;
102
- this._ip = ip && ip.startsWith("::ffff:") ? ip.substring(7) : ip;
103
- return this._ip;
104
- }
105
- /**
106
- * Set the request remote IPv4 address
107
- * @member {String} Request#ip
108
- * @param {String} ip - IPv4 address
109
- * @example
110
- * ```js
111
- * this.request.ip
112
- * => '127.0.0.1'
113
- * => '111.10.2.1'
114
- * ```
115
- */
116
- set ip(ip) {
117
- this._ip = ip;
118
- }
119
- /**
120
- * detect if response should be json
121
- * 1. url path ends with `.json`
122
- * 2. response type is set to json
123
- * 3. detect by request accept header
124
- *
125
- * @member {Boolean} Request#acceptJSON
126
- * @since 1.0.0
127
- */
128
- get acceptJSON() {
129
- if (this.path.endsWith(".json")) return true;
130
- if (this.response.type && this.response.type.indexOf("json") >= 0) return true;
131
- if (this.accepts("html", "text", "json") === "json") return true;
132
- return false;
133
- }
134
- _customQuery(cacheName, filter) {
135
- const str = this.querystring || "";
136
- let c = this[cacheName];
137
- if (!c) c = this[cacheName] = {};
138
- let cacheQuery = c[str];
139
- if (!cacheQuery) {
140
- cacheQuery = c[str] = {};
141
- const isQueries = cacheName === QUERIES_CACHE;
142
- const query = str ? querystring.parse(str) : {};
143
- for (const key in query) {
144
- if (!key) continue;
145
- const value = filter(query[key]);
146
- cacheQuery[key] = value;
147
- if (isQueries && RE_ARRAY_KEY.test(key)) {
148
- const subKey = key.substring(0, key.length - 2);
149
- if (!cacheQuery[subKey]) cacheQuery[subKey] = value;
150
- }
151
- }
152
- }
153
- return cacheQuery;
154
- }
155
- /**
156
- * get params pass by querystring, all values are of string type.
157
- * @member {Object} Request#query
158
- * @example
159
- * ```js
160
- * GET http://127.0.0.1:7001?name=Foo&age=20&age=21
161
- * this.query
162
- * => { 'name': 'Foo', 'age': '20' }
163
- *
164
- * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
165
- * this.query
166
- * =>
167
- * {
168
- * "a": "b",
169
- * "o[foo]": "bar",
170
- * "b[]": "1",
171
- * "e": "val"
172
- * }
173
- * ```
174
- */
175
- get query() {
176
- return this._customQuery(QUERY_CACHE, firstValue);
177
- }
178
- /**
179
- * get params pass by querystring, all value are Array type. {@link Request#query}
180
- * @member {Array} Request#queries
181
- * @example
182
- * ```js
183
- * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
184
- * this.queries
185
- * =>
186
- * {
187
- * "a": ["b", "c"],
188
- * "o[foo]": ["bar"],
189
- * "b[]": ["1", "2"],
190
- * "e": ["val"]
191
- * }
192
- * ```
193
- */
194
- get queries() {
195
- return this._customQuery(QUERIES_CACHE, arrayValue);
196
- }
197
- /**
198
- * Set query-string as an object.
199
- *
200
- * @function Request#query
201
- * @param {Object} obj set querystring and query object for request.
202
- */
203
- set query(obj) {
204
- this.querystring = querystring.stringify(obj);
205
- }
206
- };
207
- function firstValue(value) {
208
- if (Array.isArray(value)) value = value[0];
209
- return value;
210
- }
211
- function arrayValue(value) {
212
- if (!Array.isArray(value)) value = [value];
213
- return value;
214
- }
215
- function getFromHeaders(request, names) {
216
- if (!names) return "";
217
- const fields = names.split(/\s*,\s*/);
218
- for (const name of fields) {
219
- const value = request.get(name);
220
- if (value) return value;
221
- }
222
- return "";
223
- }
224
-
225
- //#endregion
226
4
  export { Request as default };
@@ -1,29 +1,2 @@
1
- import { Response as Response$1 } from "@eggjs/core";
2
-
3
- //#region src/app/extend/response.d.ts
4
- declare class Response extends Response$1 {
5
- /**
6
- * Get or set a real status code.
7
- *
8
- * e.g.: Using 302 status redirect to the global error page
9
- * instead of show current 500 status page.
10
- * And access log should save 500 not 302,
11
- * then the `realStatus` can help us find out the real status code.
12
- * @member {Number} Response#realStatus
13
- * @return {Number} The status code to be set.
14
- */
15
- get realStatus(): number;
16
- /**
17
- * Set a real status code.
18
- *
19
- * e.g.: Using 302 status redirect to the global error page
20
- * instead of show current 500 status page.
21
- * And access log should save 500 not 302,
22
- * then the `realStatus` can help us find out the real status code.
23
- * @member {Number} Response#realStatus
24
- * @param {Number} status The status code to be set.
25
- */
26
- set realStatus(status: number);
27
- }
28
- //#endregion
1
+ import { Response } from "../../response-DlNYDj00.js";
29
2
  export { Response as default };
@@ -1,36 +1,3 @@
1
- import { Response as Response$1 } from "@eggjs/core";
1
+ import { Response } from "../../response-CDeQ9Sx2.js";
2
2
 
3
- //#region src/app/extend/response.ts
4
- const REAL_STATUS = Symbol("response realStatus");
5
- var Response = class extends Response$1 {
6
- /**
7
- * Get or set a real status code.
8
- *
9
- * e.g.: Using 302 status redirect to the global error page
10
- * instead of show current 500 status page.
11
- * And access log should save 500 not 302,
12
- * then the `realStatus` can help us find out the real status code.
13
- * @member {Number} Response#realStatus
14
- * @return {Number} The status code to be set.
15
- */
16
- get realStatus() {
17
- if (this[REAL_STATUS]) return this[REAL_STATUS];
18
- return this.status;
19
- }
20
- /**
21
- * Set a real status code.
22
- *
23
- * e.g.: Using 302 status redirect to the global error page
24
- * instead of show current 500 status page.
25
- * And access log should save 500 not 302,
26
- * then the `realStatus` can help us find out the real status code.
27
- * @member {Number} Response#realStatus
28
- * @param {Number} status The status code to be set.
29
- */
30
- set realStatus(status) {
31
- this[REAL_STATUS] = status;
32
- }
33
- };
34
-
35
- //#endregion
36
3
  export { Response as default };
@@ -1,11 +1,12 @@
1
- import Context from "../extend/context.js";
2
- import { Next } from "../../lib/egg.js";
3
-
4
- //#region src/app/middleware/meta.d.ts
5
- interface MetaMiddlewareOptions {
6
- enable: boolean;
7
- logging: boolean;
8
- }
9
- declare const _default: (options: MetaMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
10
- //#endregion
1
+ import "../../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../../AppWorkerLoader-CT875rYM.js";
3
+ import "../../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../../index-CUPkUUOR.js";
5
+ import { MetaMiddlewareOptions, _default$2 as _default } from "../../base_hook_class-R8A8gm1s.js";
6
+ import "../../response-DlNYDj00.js";
7
+ import "../../types.plugin-C3D5I7VD.js";
8
+ import "../../IMessenger-C9g6ypSI.js";
9
+ import "../../CookieLimitExceedError-CAW0HYJw.js";
10
+ import "../../MessageUnhandledRejectionError-Lq5fWw24.js";
11
+ import "../../index-CkgLZdB4.js";
11
12
  export { MetaMiddlewareOptions, _default as default };
@@ -1,11 +1,12 @@
1
- import Context from "../extend/context.js";
2
- import { Next } from "../../lib/egg.js";
3
-
4
- //#region src/app/middleware/notfound.d.ts
5
- interface NotFoundMiddlewareOptions {
6
- enable: boolean;
7
- pageUrl: string;
8
- }
9
- declare const _default: (options: NotFoundMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
10
- //#endregion
1
+ import "../../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../../AppWorkerLoader-CT875rYM.js";
3
+ import "../../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../../index-CUPkUUOR.js";
5
+ import { NotFoundMiddlewareOptions, _default$1 as _default } from "../../base_hook_class-R8A8gm1s.js";
6
+ import "../../response-DlNYDj00.js";
7
+ import "../../types.plugin-C3D5I7VD.js";
8
+ import "../../IMessenger-C9g6ypSI.js";
9
+ import "../../CookieLimitExceedError-CAW0HYJw.js";
10
+ import "../../MessageUnhandledRejectionError-Lq5fWw24.js";
11
+ import "../../index-CkgLZdB4.js";
11
12
  export { NotFoundMiddlewareOptions, _default as default };
@@ -1,13 +1,12 @@
1
- import Context from "../extend/context.js";
2
- import { Next } from "../../lib/egg.js";
3
-
4
- //#region src/app/middleware/site_file.d.ts
5
- type SiteFileContentFun = (ctx: Context) => Promise<Buffer | string>;
6
- interface SiteFileMiddlewareOptions {
7
- enable: boolean;
8
- cacheControl: string;
9
- [key: string]: string | Buffer | boolean | SiteFileContentFun | URL;
10
- }
11
- declare const _default: (options: SiteFileMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
12
- //#endregion
1
+ import "../../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../../AppWorkerLoader-CT875rYM.js";
3
+ import "../../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../../index-CUPkUUOR.js";
5
+ import { SiteFileContentFun, SiteFileMiddlewareOptions, _default } from "../../base_hook_class-R8A8gm1s.js";
6
+ import "../../response-DlNYDj00.js";
7
+ import "../../types.plugin-C3D5I7VD.js";
8
+ import "../../IMessenger-C9g6ypSI.js";
9
+ import "../../CookieLimitExceedError-CAW0HYJw.js";
10
+ import "../../MessageUnhandledRejectionError-Lq5fWw24.js";
11
+ import "../../index-CkgLZdB4.js";
13
12
  export { SiteFileContentFun, SiteFileMiddlewareOptions, _default as default };
@@ -0,0 +1,208 @@
1
+ import { CookieLimitExceedError } from "./CookieLimitExceedError-DLGakbeu.js";
2
+ import { EggApplicationCore } from "./egg-DVo5e_lr.js";
3
+ import { AppWorkerLoader } from "./AppWorkerLoader-CAtxJvGl.js";
4
+ import { Helper } from "./helper-B3PKMPXq.js";
5
+ import { utils } from "@eggjs/core";
6
+ import path from "node:path";
7
+ import { assign } from "utility";
8
+ import fs from "node:fs";
9
+ import http from "node:http";
10
+ import { isGeneratorFunction } from "is-type-of";
11
+ import { Socket } from "node:net";
12
+ import { graceful } from "graceful";
13
+
14
+ //#region src/lib/application.ts
15
+ const EGG_LOADER = Symbol.for("egg#loader");
16
+ const DEFAULT_BAD_REQUEST_HTML = `<html>
17
+ <head><title>400 Bad Request</title></head>
18
+ <body bgcolor="white">
19
+ <center><h1>400 Bad Request</h1></center>
20
+ <hr><center>❤</center>
21
+ </body>
22
+ </html>`;
23
+ const DEFAULT_BAD_REQUEST_RESPONSE = `HTTP/1.1 400 Bad Request\r\nContent-Length: ${Buffer.byteLength(DEFAULT_BAD_REQUEST_HTML)}\r\n\r\n${DEFAULT_BAD_REQUEST_HTML}`;
24
+ function escapeHeaderValue(value) {
25
+ return /[\r\n]/.test(value) ? value.replace(/[\r\n]+[ \t]*/g, "") : value;
26
+ }
27
+ /**
28
+ * Singleton instance in App Worker, extend {@link EggApplicationCore}
29
+ * @augments EggApplicationCore
30
+ */
31
+ var Application = class extends EggApplicationCore {
32
+ server;
33
+ #locals = {};
34
+ /**
35
+ * reference to {@link Helper}
36
+ * @member {Helper} Application#Helper
37
+ */
38
+ Helper = Helper;
39
+ /**
40
+ * @class
41
+ * @param {Object} options - see {@link EggApplicationCore}
42
+ */
43
+ constructor(options) {
44
+ super({
45
+ ...options,
46
+ type: "application"
47
+ });
48
+ }
49
+ async load() {
50
+ await super.load();
51
+ this.#warnConfusedConfig();
52
+ this.#bindEvents();
53
+ }
54
+ get [EGG_LOADER]() {
55
+ return AppWorkerLoader;
56
+ }
57
+ #responseRaw(socket, raw) {
58
+ if (!socket?.writable) return;
59
+ if (!raw) return socket.end(DEFAULT_BAD_REQUEST_RESPONSE);
60
+ const body = raw.body == null ? DEFAULT_BAD_REQUEST_HTML : raw.body;
61
+ const headers = raw.headers || {};
62
+ const status = raw.status || 400;
63
+ let responseHeaderLines = "";
64
+ const firstLine = `HTTP/1.1 ${status} ${http.STATUS_CODES[status] || "Unknown"}`;
65
+ for (const key of Object.keys(headers)) {
66
+ if (key.toLowerCase() === "content-length") {
67
+ delete headers[key];
68
+ continue;
69
+ }
70
+ responseHeaderLines += `${key}: ${escapeHeaderValue(headers[key])}\r\n`;
71
+ }
72
+ responseHeaderLines += `Content-Length: ${Buffer.byteLength(body)}\r\n`;
73
+ socket.end(`${firstLine}\r\n${responseHeaderLines}\r\n${body.toString()}`);
74
+ }
75
+ onClientError(err, socket) {
76
+ if (err.rawPacket) this.logger.warn("[egg:application] A client (%s:%d) error [%s] occurred: %s", socket.remoteAddress, socket.remotePort, err.code, err.message);
77
+ if (typeof this.config.onClientError === "function") utils.callFn(this.config.onClientError, [
78
+ err,
79
+ socket,
80
+ this
81
+ ]).then((ret) => {
82
+ this.#responseRaw(socket, ret || {});
83
+ }).catch((err$1) => {
84
+ this.logger.error(err$1);
85
+ this.#responseRaw(socket);
86
+ });
87
+ else this.#responseRaw(socket);
88
+ }
89
+ onServer(server) {
90
+ this.server = server;
91
+ const serverGracefulIgnoreCode = this.config.serverGracefulIgnoreCode || [];
92
+ graceful({
93
+ server: [server],
94
+ error: (err, throwErrorCount) => {
95
+ const originMessage = err.message;
96
+ if (originMessage) Object.defineProperty(err, "message", {
97
+ get() {
98
+ return `${originMessage} (uncaughtException throw ${throwErrorCount} times on pid: ${process.pid})`;
99
+ },
100
+ configurable: true,
101
+ enumerable: false
102
+ });
103
+ this.coreLogger.error(err);
104
+ },
105
+ ignoreCode: serverGracefulIgnoreCode
106
+ });
107
+ server.on("clientError", (err, socket) => this.onClientError(err, socket));
108
+ if (typeof this.config.serverTimeout === "number") server.setTimeout(this.config.serverTimeout);
109
+ }
110
+ /**
111
+ * global locals for view
112
+ * @member {Object} Application#locals
113
+ * @see Context#locals
114
+ */
115
+ get locals() {
116
+ return this.#locals;
117
+ }
118
+ set locals(val) {
119
+ assign(this.#locals, val);
120
+ }
121
+ /**
122
+ * save routers to `run/router.json`
123
+ * @private
124
+ */
125
+ dumpConfig() {
126
+ super.dumpConfig();
127
+ const rundir = this.config.rundir;
128
+ const FULLPATH = this.loader.FileLoader.FULLPATH;
129
+ try {
130
+ const dumpRouterFile = path.join(rundir, "router.json");
131
+ const routers = [];
132
+ for (const layer of this.router.stack) routers.push({
133
+ name: layer.name,
134
+ methods: layer.methods,
135
+ paramNames: layer.paramNames,
136
+ path: layer.path,
137
+ regexp: layer.regexp.toString(),
138
+ stack: layer.stack.map((stack) => stack[FULLPATH] || stack._name || stack.name || "anonymous")
139
+ });
140
+ fs.writeFileSync(dumpRouterFile, JSON.stringify(routers, null, 2));
141
+ } catch (err) {
142
+ this.coreLogger.warn(`dumpConfig router.json error: ${err.message}`);
143
+ }
144
+ }
145
+ /**
146
+ * Run async function in the background
147
+ * @see Context#runInBackground
148
+ * @param {Function} scope - the first args is an anonymous ctx
149
+ */
150
+ runInBackground(scope, req) {
151
+ const ctx = this.createAnonymousContext(req);
152
+ if (!scope.name) Reflect.set(scope, "_name", utils.getCalleeFromStack(true));
153
+ this.ctxStorage.run(ctx, () => {
154
+ return ctx.runInBackground(scope);
155
+ });
156
+ }
157
+ /**
158
+ * secret key for Application
159
+ * @member {String} Application#keys
160
+ */
161
+ get keys() {
162
+ if (!this._keys) {
163
+ if (!this.config.keys) {
164
+ if (this.config.env === "local" || this.config.env === "unittest") {
165
+ const configPath = path.join(this.config.baseDir, "config/config.default.js");
166
+ console.error("Cookie need secret key to sign and encrypt.");
167
+ console.error("Please add `config.keys` in %s", configPath);
168
+ }
169
+ throw new Error("Please set config.keys first");
170
+ }
171
+ this._keys = this.config.keys.split(",").map((s) => s.trim());
172
+ }
173
+ return this._keys;
174
+ }
175
+ /**
176
+ * @deprecated keep compatible with egg 3.x
177
+ */
178
+ toAsyncFunction(fn) {
179
+ if (isGeneratorFunction(fn)) throw new Error("Generator function is not supported");
180
+ return fn;
181
+ }
182
+ /**
183
+ * bind app's events
184
+ *
185
+ * @private
186
+ */
187
+ #bindEvents() {
188
+ this.on("cookieLimitExceed", ({ name, value, ctx }) => {
189
+ const err = new CookieLimitExceedError(name, value);
190
+ ctx.coreLogger.error(err);
191
+ });
192
+ this.once("server", (server) => this.onServer(server));
193
+ }
194
+ /**
195
+ * warn when confused configurations are present
196
+ *
197
+ * @private
198
+ */
199
+ #warnConfusedConfig() {
200
+ const confusedConfigurations = this.config.confusedConfigurations;
201
+ Object.keys(confusedConfigurations).forEach((key) => {
202
+ if (this.config[key] !== void 0) this.logger.warn("[egg:application] Unexpected config key `%o` exists, Please use `%o` instead.", key, confusedConfigurations[key]);
203
+ });
204
+ }
205
+ };
206
+
207
+ //#endregion
208
+ export { Application };
@@ -0,0 +1,12 @@
1
+ import { EggApplicationCore } from "./base_hook_class-R8A8gm1s.js";
2
+ import { EventEmitter, captureRejectionSymbol } from "node:events";
3
+
4
+ //#region src/lib/core/messenger/base.d.ts
5
+ declare class BaseMessenger extends EventEmitter {
6
+ protected readonly egg: EggApplicationCore;
7
+ constructor(egg: EggApplicationCore);
8
+ [captureRejectionSymbol](err: Error, event: string | symbol, ...args: any[]): void;
9
+ emit(eventName: string | symbol, ...args: any[]): boolean;
10
+ }
11
+ //#endregion
12
+ export { BaseMessenger };
@@ -0,0 +1,19 @@
1
+ import { BaseContextLogger } from "./base_context_logger-CZU59PGA.js";
2
+ import { BaseContextClass } from "@eggjs/core";
3
+
4
+ //#region src/lib/core/base_context_class.ts
5
+ /**
6
+ * BaseContextClass is a base class that can be extended,
7
+ * it's instantiated in context level,
8
+ * {@link Helper}, {@link Service} is extending it.
9
+ */
10
+ var BaseContextClass$1 = class extends BaseContextClass {
11
+ #logger;
12
+ get logger() {
13
+ if (!this.#logger) this.#logger = new BaseContextLogger(this.ctx, this.pathName);
14
+ return this.#logger;
15
+ }
16
+ };
17
+
18
+ //#endregion
19
+ export { BaseContextClass$1 as BaseContextClass };
@@ -0,0 +1,58 @@
1
+ //#region src/lib/core/base_context_logger.ts
2
+ var BaseContextLogger = class {
3
+ #ctx;
4
+ #pathName;
5
+ /**
6
+ * @class
7
+ * @param {Context} ctx - context instance
8
+ * @param {String} pathName - class path name
9
+ * @since 1.0.0
10
+ */
11
+ constructor(ctx, pathName) {
12
+ /**
13
+ * @member {Context} BaseContextLogger#ctx
14
+ * @since 1.2.0
15
+ */
16
+ this.#ctx = ctx;
17
+ this.#pathName = pathName;
18
+ }
19
+ _log(method, args) {
20
+ if (this.#pathName && typeof args[0] === "string") args[0] = `[${this.#pathName}] ${args[0]}`;
21
+ this.#ctx.app.logger[method](...args);
22
+ }
23
+ /**
24
+ * @member {Function} BaseContextLogger#debug
25
+ * @param {...any} args - log msg
26
+ * @since 1.2.0
27
+ */
28
+ debug(...args) {
29
+ this._log("debug", args);
30
+ }
31
+ /**
32
+ * @member {Function} BaseContextLogger#info
33
+ * @param {...any} args - log msg
34
+ * @since 1.2.0
35
+ */
36
+ info(...args) {
37
+ this._log("info", args);
38
+ }
39
+ /**
40
+ * @member {Function} BaseContextLogger#warn
41
+ * @param {...any} args - log msg
42
+ * @since 1.2.0
43
+ */
44
+ warn(...args) {
45
+ this._log("warn", args);
46
+ }
47
+ /**
48
+ * @member {Function} BaseContextLogger#error
49
+ * @param {...any} args - log msg
50
+ * @since 1.2.0
51
+ */
52
+ error(...args) {
53
+ this._log("error", args);
54
+ }
55
+ };
56
+
57
+ //#endregion
58
+ export { BaseContextLogger };