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
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,47 @@
1
+ import { BaseContextClass } from "./base_context_class-Xc1OZql9.js";
2
+ import url from "node:url";
3
+
4
+ //#region src/app/extend/helper.ts
5
+ /**
6
+ * The Helper class which can be used as utility function.
7
+ * We support developers to extend Helper through ${baseDir}/app/extend/helper.js ,
8
+ * then you can use all method on `ctx.helper` that is a instance of Helper.
9
+ */
10
+ var Helper = class extends BaseContextClass {
11
+ /**
12
+ * Generate URL path(without host) for route. Takes the route name and a map of named params.
13
+ * @function Helper#pathFor
14
+ * @param {String} name - Router Name
15
+ * @param {Object} params - Other params
16
+ *
17
+ * @example
18
+ * ```js
19
+ * app.get('home', '/index.htm', 'home.index');
20
+ * ctx.helper.pathFor('home', { by: 'recent', limit: 20 })
21
+ * => /index.htm?by=recent&limit=20
22
+ * ```
23
+ * @return {String} url path(without host)
24
+ */
25
+ pathFor(name, params) {
26
+ return this.app.router.url(name, params);
27
+ }
28
+ /**
29
+ * Generate full URL(with host) for route. Takes the route name and a map of named params.
30
+ * @function Helper#urlFor
31
+ * @param {String} name - Router name
32
+ * @param {Object} params - Other params
33
+ * @example
34
+ * ```js
35
+ * app.get('home', '/index.htm', 'home.index');
36
+ * ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
37
+ * => http://127.0.0.1:7001/index.htm?by=recent&limit=20
38
+ * ```
39
+ * @return {String} full url(with host)
40
+ */
41
+ urlFor(name, params) {
42
+ return this.ctx.protocol + "://" + this.ctx.host + url.resolve("/", this.pathFor(name, params));
43
+ }
44
+ };
45
+
46
+ //#endregion
47
+ export { Helper };
@@ -0,0 +1,36 @@
1
+ import { HttpClient } from "urllib";
2
+ import { ms } from "humanize-ms";
3
+
4
+ //#region src/lib/core/httpclient.ts
5
+ var HttpClient$1 = class extends HttpClient {
6
+ #app;
7
+ constructor(app, options = {}) {
8
+ normalizeConfig(app);
9
+ const config = app.config.httpclient;
10
+ const initOptions = {
11
+ ...options,
12
+ defaultArgs: {
13
+ ...config.request,
14
+ ...options.defaultArgs
15
+ }
16
+ };
17
+ super(initOptions);
18
+ this.#app = app;
19
+ }
20
+ async request(url, options) {
21
+ options = options ?? {};
22
+ if (options.ctx?.tracer) options.tracer = options.ctx.tracer;
23
+ else options.tracer = options.tracer ?? this.#app.tracer;
24
+ return await super.request(url, options);
25
+ }
26
+ async curl(url, options) {
27
+ return await this.request(url, options);
28
+ }
29
+ };
30
+ function normalizeConfig(app) {
31
+ const config = app.config.httpclient;
32
+ if (typeof config.request?.timeout === "string") config.request.timeout = ms(config.request.timeout);
33
+ }
34
+
35
+ //#endregion
36
+ export { HttpClient$1 as HttpClient };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.d.ts CHANGED
@@ -1,21 +1,13 @@
1
- import { AppWorkerLoader } from "./lib/loader/AppWorkerLoader.js";
2
- import { AgentWorkerLoader } from "./lib/loader/AgentWorkerLoader.js";
3
- import { Agent } from "./lib/agent.js";
4
- import Helper from "./app/extend/helper.js";
5
- import { Application } from "./lib/application.js";
6
- import { EggContextHttpClient as HttpClient, HttpClientOptions, HttpClientRequestOptions, HttpClientRequestURL, HttpClientResponse } from "./lib/core/httpclient.js";
7
- import Response from "./app/extend/response.js";
8
- import Request from "./app/extend/request.js";
9
- import Context from "./app/extend/context.js";
10
- import { ClientErrorResponse, CustomLoaderConfig, EggAppConfig, EggAppInfo, EggConfigFactory, EggEnvType, EggLoggerConfig, EggPlugin, EggPluginItem, HttpClientConfig, IEggPluginItem, PartialDeep, PartialEggConfig, PowerPartial, RequestObjectBody, defineConfig, defineConfigFactory } from "./lib/types.js";
11
- import { ContextHttpClient } from "./lib/core/context_httpclient.js";
12
- import { EggApplicationCore, EggApplicationCoreOptions, EggContext, IBoot as ILifecycleBoot, MiddlewareFunc, Next, Router } from "./lib/egg.js";
13
- import { BaseContextClass } from "./lib/core/base_context_class.js";
14
- import { SingleModeAgent, SingleModeApplication, StartEggOptions, startEgg } from "./lib/start.js";
15
- import { CookieLimitExceedError } from "./lib/error/CookieLimitExceedError.js";
16
- import { MessageUnhandledRejectionError } from "./lib/error/MessageUnhandledRejectionError.js";
17
- import { BaseHookClass } from "./lib/core/base_hook_class.js";
18
- import { Singleton, SingletonCreateMethod, SingletonOptions } from "@eggjs/core";
19
- import { EggLogger, LoggerLevel } from "egg-logger";
1
+ import "./EggApplicationLoader-PnIvd5oV.js";
2
+ import { AppWorkerLoader } from "./AppWorkerLoader-CT875rYM.js";
3
+ import { AgentWorkerLoader } from "./AgentWorkerLoader-DG_hAClt.js";
4
+ import "./index-CUPkUUOR.js";
5
+ import { Agent, Application, BaseContextClass, BaseHookClass, ClientErrorResponse, Context, ContextHttpClient, CustomLoaderConfig, EggAppConfig, EggAppInfo, EggApplicationCore, EggApplicationCoreOptions, EggConfigFactory, EggContext, EggEnvType, EggLogger, EggLoggerConfig, EggPlugin, EggPluginItem, Helper, HttpClient, HttpClientConfig, HttpClientOptions, HttpClientRequestOptions, HttpClientRequestURL, HttpClientResponse, IEggPluginItem, ILifecycleBoot, LoggerLevel, MiddlewareFunc, Next, PartialDeep, PartialEggConfig, PowerPartial, Request, RequestObjectBody, Router, SingleModeAgent, SingleModeApplication, Singleton, SingletonCreateMethod, SingletonOptions, StartEggOptions, defineConfig, defineConfigFactory, startEgg } from "./base_hook_class-R8A8gm1s.js";
6
+ import { Response } from "./response-DlNYDj00.js";
7
+ import "./types.plugin-C3D5I7VD.js";
8
+ import "./IMessenger-C9g6ypSI.js";
9
+ import { CookieLimitExceedError } from "./CookieLimitExceedError-CAW0HYJw.js";
10
+ import { MessageUnhandledRejectionError } from "./MessageUnhandledRejectionError-Lq5fWw24.js";
11
+ import "./index-CkgLZdB4.js";
20
12
  export * from "@eggjs/cluster";
21
- export { Agent, AgentWorkerLoader, AppWorkerLoader, Application, BaseContextClass, BaseHookClass as Boot, ClientErrorResponse, Context, ContextHttpClient, BaseContextClass as Controller, BaseContextClass as Service, BaseContextClass as Subscription, CookieLimitExceedError, CustomLoaderConfig, EggAppConfig, EggAppInfo, EggApplicationCore, EggApplicationCoreOptions, EggConfigFactory, EggContext, HttpClient as EggContextHttpClient, HttpClient as EggHttpClient, HttpClient, EggEnvType, type EggLogger, EggLoggerConfig, EggPlugin, EggPluginItem, Helper, type Helper as IHelper, HttpClientConfig, HttpClientOptions, HttpClientRequestOptions, HttpClientRequestURL, HttpClientResponse, ILifecycleBoot as IBoot, ILifecycleBoot, IEggPluginItem, type LoggerLevel, MessageUnhandledRejectionError, MiddlewareFunc, Next, PartialDeep, PartialEggConfig, PowerPartial, Request, RequestObjectBody, Response, Router, type SingleModeAgent, type SingleModeApplication, Singleton, type SingletonCreateMethod, type SingletonOptions, StartEggOptions, defineConfig, defineConfigFactory, startEgg as start, startEgg };
13
+ export { Agent, AgentWorkerLoader, AppWorkerLoader, Application, BaseContextClass, BaseHookClass as Boot, ClientErrorResponse, Context, ContextHttpClient, BaseContextClass as Controller, BaseContextClass as Service, BaseContextClass as Subscription, CookieLimitExceedError, CustomLoaderConfig, EggAppConfig, EggAppInfo, EggApplicationCore, EggApplicationCoreOptions, EggConfigFactory, EggContext, HttpClient as EggContextHttpClient, HttpClient as EggHttpClient, HttpClient, EggEnvType, EggLogger, EggLoggerConfig, EggPlugin, EggPluginItem, Helper, Helper as IHelper, HttpClientConfig, HttpClientOptions, HttpClientRequestOptions, HttpClientRequestURL, HttpClientResponse, ILifecycleBoot as IBoot, ILifecycleBoot, IEggPluginItem, LoggerLevel, MessageUnhandledRejectionError, MiddlewareFunc, Next, PartialDeep, PartialEggConfig, PowerPartial, Request, RequestObjectBody, Response, Router, SingleModeAgent, SingleModeApplication, Singleton, SingletonCreateMethod, SingletonOptions, StartEggOptions, defineConfig, defineConfigFactory, startEgg as start, startEgg };
package/dist/index.js CHANGED
@@ -1,22 +1,29 @@
1
- import { BaseHookClass } from "./lib/core/base_hook_class.js";
2
- import { BaseContextClass } from "./lib/core/base_context_class.js";
3
- import Context from "./app/extend/context.js";
4
- import Response from "./app/extend/response.js";
5
- import Request from "./app/extend/request.js";
6
- import { CookieLimitExceedError } from "./lib/error/CookieLimitExceedError.js";
7
- import { MessageUnhandledRejectionError } from "./lib/error/MessageUnhandledRejectionError.js";
8
- import { ContextHttpClient } from "./lib/core/context_httpclient.js";
9
- import { HttpClient } from "./lib/core/httpclient.js";
10
- import { EggApplicationCore, Router } from "./lib/egg.js";
11
- import { AppWorkerLoader } from "./lib/loader/AppWorkerLoader.js";
12
- import { AgentWorkerLoader } from "./lib/loader/AgentWorkerLoader.js";
13
- import "./lib/loader/index.js";
14
- import { Agent } from "./lib/agent.js";
15
- import Helper from "./app/extend/helper.js";
16
- import { Application } from "./lib/application.js";
17
- import { defineConfig, defineConfigFactory } from "./lib/types.js";
18
- import { startEgg } from "./lib/start.js";
19
- import { Singleton } from "@eggjs/core";
1
+ import { BaseHookClass } from "./base_hook_class-D0Gu2p8r.js";
2
+ import "./base_context_logger-CZU59PGA.js";
3
+ import { BaseContextClass } from "./base_context_class-Xc1OZql9.js";
4
+ import { Context } from "./context-D1Wg7CXs.js";
5
+ import { Response } from "./response-CDeQ9Sx2.js";
6
+ import { Request } from "./request-Cy_1DlaX.js";
7
+ import { CookieLimitExceedError } from "./CookieLimitExceedError-DLGakbeu.js";
8
+ import { MessageUnhandledRejectionError } from "./MessageUnhandledRejectionError-oD_E1Ewl.js";
9
+ import "./error-BYo_LRnd.js";
10
+ import { EggApplicationCore, Router } from "./egg-DVo5e_lr.js";
11
+ import { ContextHttpClient } from "./context_httpclient-BpRMdJhf.js";
12
+ import { HttpClient } from "./httpclient-C1QPc_R7.js";
13
+ import "./logger-C4tIcO3S.js";
14
+ import "./utils-B1Rjsoi9.js";
15
+ import "./utils-BDoYg6z6.js";
16
+ import "./EggApplicationLoader-CMe1VQt1.js";
17
+ import { AppWorkerLoader } from "./AppWorkerLoader-CAtxJvGl.js";
18
+ import { AgentWorkerLoader } from "./AgentWorkerLoader-D_hceBRW.js";
19
+ import "./loader-3myZ-rpm.js";
20
+ import { Agent } from "./agent-BfFWeJj4.js";
21
+ import { Helper } from "./helper-B3PKMPXq.js";
22
+ import { Application } from "./application-DVwFQSa9.js";
23
+ import "./types.plugin-B2v0K0I8.js";
24
+ import { defineConfig, defineConfigFactory } from "./types-dKSyDnVp.js";
25
+ import { startEgg } from "./start-4E84z796.js";
26
+ import { Singleton } from "./src-BuOjXSrB.js";
20
27
 
21
28
  export * from "@eggjs/cluster"
22
29
 
@@ -1,22 +1,12 @@
1
- import { AgentWorkerLoader } from "./loader/AgentWorkerLoader.js";
2
- import { EggApplicationCore, EggApplicationCoreOptions } from "./egg.js";
3
-
4
- //#region src/lib/agent.d.ts
5
- declare const EGG_LOADER: unique symbol;
6
- /**
7
- * Singleton instance in Agent Worker, extend {@link EggApplicationCore}
8
- * @augments EggApplicationCore
9
- */
10
- declare class Agent extends EggApplicationCore {
11
- #private;
12
- /**
13
- * @class
14
- * @param {Object} options - see {@link EggApplicationCore}
15
- */
16
- constructor(options?: Omit<EggApplicationCoreOptions, 'type'>);
17
- get [EGG_LOADER](): typeof AgentWorkerLoader;
18
- _wrapMessenger(): void;
19
- close(): Promise<void>;
20
- }
21
- //#endregion
1
+ import "../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../AppWorkerLoader-CT875rYM.js";
3
+ import "../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../index-CUPkUUOR.js";
5
+ import { Agent } 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";
22
12
  export { Agent };
package/dist/lib/agent.js CHANGED
@@ -1,56 +1,22 @@
1
- import { EggApplicationCore } from "./egg.js";
2
- import { AgentWorkerLoader } from "./loader/AgentWorkerLoader.js";
3
- import "./loader/index.js";
1
+ import "../base_hook_class-D0Gu2p8r.js";
2
+ import "../base_context_logger-CZU59PGA.js";
3
+ import "../base_context_class-Xc1OZql9.js";
4
+ import "../context-D1Wg7CXs.js";
5
+ import "../response-CDeQ9Sx2.js";
6
+ import "../request-Cy_1DlaX.js";
7
+ import "../CookieLimitExceedError-DLGakbeu.js";
8
+ import "../MessageUnhandledRejectionError-oD_E1Ewl.js";
9
+ import "../error-BYo_LRnd.js";
10
+ import "../egg-DVo5e_lr.js";
11
+ import "../context_httpclient-BpRMdJhf.js";
12
+ import "../httpclient-C1QPc_R7.js";
13
+ import "../logger-C4tIcO3S.js";
14
+ import "../utils-B1Rjsoi9.js";
15
+ import "../utils-BDoYg6z6.js";
16
+ import "../EggApplicationLoader-CMe1VQt1.js";
17
+ import "../AppWorkerLoader-CAtxJvGl.js";
18
+ import "../AgentWorkerLoader-D_hceBRW.js";
19
+ import "../loader-3myZ-rpm.js";
20
+ import { Agent } from "../agent-BfFWeJj4.js";
4
21
 
5
- //#region src/lib/agent.ts
6
- const EGG_LOADER = Symbol.for("egg#loader");
7
- /**
8
- * Singleton instance in Agent Worker, extend {@link EggApplicationCore}
9
- * @augments EggApplicationCore
10
- */
11
- var Agent = class extends EggApplicationCore {
12
- #agentAliveHandler;
13
- /**
14
- * @class
15
- * @param {Object} options - see {@link EggApplicationCore}
16
- */
17
- constructor(options) {
18
- super({
19
- ...options,
20
- type: "agent"
21
- });
22
- this.#agentAliveHandler = setInterval(() => {
23
- this.coreLogger.info("[]");
24
- }, 1440 * 60 * 1e3);
25
- }
26
- get [EGG_LOADER]() {
27
- return AgentWorkerLoader;
28
- }
29
- _wrapMessenger() {
30
- for (const methodName of [
31
- "broadcast",
32
- "sendTo",
33
- "sendToApp",
34
- "sendToAgent",
35
- "sendRandom"
36
- ]) wrapMethod(methodName, this.messenger, this.coreLogger);
37
- function wrapMethod(methodName, messenger, logger) {
38
- const originMethod = messenger[methodName];
39
- messenger[methodName] = function(...args) {
40
- const stack = (/* @__PURE__ */ new Error()).stack.split("\n").slice(1).join("\n");
41
- logger.warn("agent can't call %s before server started\n%s", methodName, stack);
42
- originMethod.apply(this, args);
43
- };
44
- messenger.prependOnceListener("egg-ready", () => {
45
- messenger[methodName] = originMethod;
46
- });
47
- }
48
- }
49
- async close() {
50
- clearInterval(this.#agentAliveHandler);
51
- await super.close();
52
- }
53
- };
54
-
55
- //#endregion
56
22
  export { Agent };
@@ -1,60 +1,12 @@
1
- import { AppWorkerLoader } from "./loader/AppWorkerLoader.js";
2
- import Helper from "../app/extend/helper.js";
3
- import Context from "../app/extend/context.js";
4
- import { EggApplicationCore, EggApplicationCoreOptions } from "./egg.js";
5
- import http from "node:http";
6
- import { Socket } from "node:net";
7
-
8
- //#region src/lib/application.d.ts
9
- declare const EGG_LOADER: unique symbol;
10
- /**
11
- * Singleton instance in App Worker, extend {@link EggApplicationCore}
12
- * @augments EggApplicationCore
13
- */
14
- declare class Application extends EggApplicationCore {
15
- #private;
16
- server?: http.Server;
17
- /**
18
- * reference to {@link Helper}
19
- * @member {Helper} Application#Helper
20
- */
21
- Helper: typeof Helper;
22
- /**
23
- * @class
24
- * @param {Object} options - see {@link EggApplicationCore}
25
- */
26
- constructor(options?: Omit<EggApplicationCoreOptions, 'type'>);
27
- protected load(): Promise<void>;
28
- get [EGG_LOADER](): typeof AppWorkerLoader;
29
- onClientError(err: any, socket: Socket): void;
30
- onServer(server: http.Server): void;
31
- /**
32
- * global locals for view
33
- * @member {Object} Application#locals
34
- * @see Context#locals
35
- */
36
- get locals(): Record<string, any>;
37
- set locals(val: Record<string, any>);
38
- /**
39
- * save routers to `run/router.json`
40
- * @private
41
- */
42
- dumpConfig(): void;
43
- /**
44
- * Run async function in the background
45
- * @see Context#runInBackground
46
- * @param {Function} scope - the first args is an anonymous ctx
47
- */
48
- runInBackground(scope: (ctx: Context) => Promise<void>, req?: unknown): void;
49
- /**
50
- * secret key for Application
51
- * @member {String} Application#keys
52
- */
53
- get keys(): string[];
54
- /**
55
- * @deprecated keep compatible with egg 3.x
56
- */
57
- toAsyncFunction(fn: (...args: any[]) => any): (...args: any[]) => any;
58
- }
59
- //#endregion
1
+ import "../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../AppWorkerLoader-CT875rYM.js";
3
+ import "../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../index-CUPkUUOR.js";
5
+ import { Application } 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";
60
12
  export { Application };
@@ -1,209 +1,23 @@
1
- import { CookieLimitExceedError } from "./error/CookieLimitExceedError.js";
2
- import { EggApplicationCore } from "./egg.js";
3
- import { AppWorkerLoader } from "./loader/AppWorkerLoader.js";
4
- import "./loader/index.js";
5
- import Helper from "../app/extend/helper.js";
6
- import { utils } from "@eggjs/core";
7
- import path from "node:path";
8
- import { assign } from "utility";
9
- import fs from "node:fs";
10
- import http from "node:http";
11
- import { isGeneratorFunction } from "is-type-of";
12
- import { Socket } from "node:net";
13
- import { graceful } from "graceful";
1
+ import "../base_hook_class-D0Gu2p8r.js";
2
+ import "../base_context_logger-CZU59PGA.js";
3
+ import "../base_context_class-Xc1OZql9.js";
4
+ import "../context-D1Wg7CXs.js";
5
+ import "../response-CDeQ9Sx2.js";
6
+ import "../request-Cy_1DlaX.js";
7
+ import "../CookieLimitExceedError-DLGakbeu.js";
8
+ import "../MessageUnhandledRejectionError-oD_E1Ewl.js";
9
+ import "../error-BYo_LRnd.js";
10
+ import "../egg-DVo5e_lr.js";
11
+ import "../context_httpclient-BpRMdJhf.js";
12
+ import "../httpclient-C1QPc_R7.js";
13
+ import "../logger-C4tIcO3S.js";
14
+ import "../utils-B1Rjsoi9.js";
15
+ import "../utils-BDoYg6z6.js";
16
+ import "../EggApplicationLoader-CMe1VQt1.js";
17
+ import "../AppWorkerLoader-CAtxJvGl.js";
18
+ import "../AgentWorkerLoader-D_hceBRW.js";
19
+ import "../loader-3myZ-rpm.js";
20
+ import "../helper-B3PKMPXq.js";
21
+ import { Application } from "../application-DVwFQSa9.js";
14
22
 
15
- //#region src/lib/application.ts
16
- const EGG_LOADER = Symbol.for("egg#loader");
17
- const DEFAULT_BAD_REQUEST_HTML = `<html>
18
- <head><title>400 Bad Request</title></head>
19
- <body bgcolor="white">
20
- <center><h1>400 Bad Request</h1></center>
21
- <hr><center>❤</center>
22
- </body>
23
- </html>`;
24
- 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}`;
25
- function escapeHeaderValue(value) {
26
- return /[\r\n]/.test(value) ? value.replace(/[\r\n]+[ \t]*/g, "") : value;
27
- }
28
- /**
29
- * Singleton instance in App Worker, extend {@link EggApplicationCore}
30
- * @augments EggApplicationCore
31
- */
32
- var Application = class extends EggApplicationCore {
33
- server;
34
- #locals = {};
35
- /**
36
- * reference to {@link Helper}
37
- * @member {Helper} Application#Helper
38
- */
39
- Helper = Helper;
40
- /**
41
- * @class
42
- * @param {Object} options - see {@link EggApplicationCore}
43
- */
44
- constructor(options) {
45
- super({
46
- ...options,
47
- type: "application"
48
- });
49
- }
50
- async load() {
51
- await super.load();
52
- this.#warnConfusedConfig();
53
- this.#bindEvents();
54
- }
55
- get [EGG_LOADER]() {
56
- return AppWorkerLoader;
57
- }
58
- #responseRaw(socket, raw) {
59
- if (!socket?.writable) return;
60
- if (!raw) return socket.end(DEFAULT_BAD_REQUEST_RESPONSE);
61
- const body = raw.body == null ? DEFAULT_BAD_REQUEST_HTML : raw.body;
62
- const headers = raw.headers || {};
63
- const status = raw.status || 400;
64
- let responseHeaderLines = "";
65
- const firstLine = `HTTP/1.1 ${status} ${http.STATUS_CODES[status] || "Unknown"}`;
66
- for (const key of Object.keys(headers)) {
67
- if (key.toLowerCase() === "content-length") {
68
- delete headers[key];
69
- continue;
70
- }
71
- responseHeaderLines += `${key}: ${escapeHeaderValue(headers[key])}\r\n`;
72
- }
73
- responseHeaderLines += `Content-Length: ${Buffer.byteLength(body)}\r\n`;
74
- socket.end(`${firstLine}\r\n${responseHeaderLines}\r\n${body.toString()}`);
75
- }
76
- onClientError(err, socket) {
77
- if (err.rawPacket) this.logger.warn("[egg:application] A client (%s:%d) error [%s] occurred: %s", socket.remoteAddress, socket.remotePort, err.code, err.message);
78
- if (typeof this.config.onClientError === "function") utils.callFn(this.config.onClientError, [
79
- err,
80
- socket,
81
- this
82
- ]).then((ret) => {
83
- this.#responseRaw(socket, ret || {});
84
- }).catch((err$1) => {
85
- this.logger.error(err$1);
86
- this.#responseRaw(socket);
87
- });
88
- else this.#responseRaw(socket);
89
- }
90
- onServer(server) {
91
- this.server = server;
92
- const serverGracefulIgnoreCode = this.config.serverGracefulIgnoreCode || [];
93
- graceful({
94
- server: [server],
95
- error: (err, throwErrorCount) => {
96
- const originMessage = err.message;
97
- if (originMessage) Object.defineProperty(err, "message", {
98
- get() {
99
- return `${originMessage} (uncaughtException throw ${throwErrorCount} times on pid: ${process.pid})`;
100
- },
101
- configurable: true,
102
- enumerable: false
103
- });
104
- this.coreLogger.error(err);
105
- },
106
- ignoreCode: serverGracefulIgnoreCode
107
- });
108
- server.on("clientError", (err, socket) => this.onClientError(err, socket));
109
- if (typeof this.config.serverTimeout === "number") server.setTimeout(this.config.serverTimeout);
110
- }
111
- /**
112
- * global locals for view
113
- * @member {Object} Application#locals
114
- * @see Context#locals
115
- */
116
- get locals() {
117
- return this.#locals;
118
- }
119
- set locals(val) {
120
- assign(this.#locals, val);
121
- }
122
- /**
123
- * save routers to `run/router.json`
124
- * @private
125
- */
126
- dumpConfig() {
127
- super.dumpConfig();
128
- const rundir = this.config.rundir;
129
- const FULLPATH = this.loader.FileLoader.FULLPATH;
130
- try {
131
- const dumpRouterFile = path.join(rundir, "router.json");
132
- const routers = [];
133
- for (const layer of this.router.stack) routers.push({
134
- name: layer.name,
135
- methods: layer.methods,
136
- paramNames: layer.paramNames,
137
- path: layer.path,
138
- regexp: layer.regexp.toString(),
139
- stack: layer.stack.map((stack) => stack[FULLPATH] || stack._name || stack.name || "anonymous")
140
- });
141
- fs.writeFileSync(dumpRouterFile, JSON.stringify(routers, null, 2));
142
- } catch (err) {
143
- this.coreLogger.warn(`dumpConfig router.json error: ${err.message}`);
144
- }
145
- }
146
- /**
147
- * Run async function in the background
148
- * @see Context#runInBackground
149
- * @param {Function} scope - the first args is an anonymous ctx
150
- */
151
- runInBackground(scope, req) {
152
- const ctx = this.createAnonymousContext(req);
153
- if (!scope.name) Reflect.set(scope, "_name", utils.getCalleeFromStack(true));
154
- this.ctxStorage.run(ctx, () => {
155
- return ctx.runInBackground(scope);
156
- });
157
- }
158
- /**
159
- * secret key for Application
160
- * @member {String} Application#keys
161
- */
162
- get keys() {
163
- if (!this._keys) {
164
- if (!this.config.keys) {
165
- if (this.config.env === "local" || this.config.env === "unittest") {
166
- const configPath = path.join(this.config.baseDir, "config/config.default.js");
167
- console.error("Cookie need secret key to sign and encrypt.");
168
- console.error("Please add `config.keys` in %s", configPath);
169
- }
170
- throw new Error("Please set config.keys first");
171
- }
172
- this._keys = this.config.keys.split(",").map((s) => s.trim());
173
- }
174
- return this._keys;
175
- }
176
- /**
177
- * @deprecated keep compatible with egg 3.x
178
- */
179
- toAsyncFunction(fn) {
180
- if (isGeneratorFunction(fn)) throw new Error("Generator function is not supported");
181
- return fn;
182
- }
183
- /**
184
- * bind app's events
185
- *
186
- * @private
187
- */
188
- #bindEvents() {
189
- this.on("cookieLimitExceed", ({ name, value, ctx }) => {
190
- const err = new CookieLimitExceedError(name, value);
191
- ctx.coreLogger.error(err);
192
- });
193
- this.once("server", (server) => this.onServer(server));
194
- }
195
- /**
196
- * warn when confused configurations are present
197
- *
198
- * @private
199
- */
200
- #warnConfusedConfig() {
201
- const confusedConfigurations = this.config.confusedConfigurations;
202
- Object.keys(confusedConfigurations).forEach((key) => {
203
- if (this.config[key] !== void 0) this.logger.warn("[egg:application] Unexpected config key `%o` exists, Please use `%o` instead.", key, confusedConfigurations[key]);
204
- });
205
- }
206
- };
207
-
208
- //#endregion
209
23
  export { Application };
@@ -1,23 +1,12 @@
1
- import { Application } from "../application.js";
2
- import Context$1 from "../../app/extend/context.js";
3
- import { BaseContextLogger } from "./base_context_logger.js";
4
- import { BaseContextClass as BaseContextClass$1 } from "@eggjs/core";
5
-
6
- //#region src/lib/core/base_context_class.d.ts
7
-
8
- /**
9
- * BaseContextClass is a base class that can be extended,
10
- * it's instantiated in context level,
11
- * {@link Helper}, {@link Service} is extending it.
12
- */
13
- declare class BaseContextClass extends BaseContextClass$1 {
14
- #private;
15
- [key: string | symbol]: any;
16
- ctx: Context$1;
17
- pathName?: string;
18
- app: Application;
19
- service: BaseContextClass;
20
- get logger(): BaseContextLogger;
21
- }
22
- //#endregion
1
+ import "../../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../../AppWorkerLoader-CT875rYM.js";
3
+ import "../../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../../index-CUPkUUOR.js";
5
+ import { BaseContextClass } 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";
23
12
  export { BaseContextClass };
@@ -1,19 +1,4 @@
1
- import { BaseContextLogger } from "./base_context_logger.js";
2
- import { BaseContextClass as BaseContextClass$1 } from "@eggjs/core";
1
+ import "../../base_context_logger-CZU59PGA.js";
2
+ import { BaseContextClass } from "../../base_context_class-Xc1OZql9.js";
3
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 = class extends BaseContextClass$1 {
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
4
  export { BaseContextClass };