egg 4.1.0-beta.2 → 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.
- package/dist/AgentWorkerLoader-DG_hAClt.d.ts +17 -0
- package/dist/AgentWorkerLoader-D_hceBRW.js +24 -0
- package/dist/AppWorkerLoader-CAtxJvGl.js +37 -0
- package/dist/AppWorkerLoader-CT875rYM.d.ts +22 -0
- package/dist/CookieLimitExceedError-CAW0HYJw.d.ts +8 -0
- package/dist/CookieLimitExceedError-DLGakbeu.js +15 -0
- package/dist/EggApplicationLoader-CMe1VQt1.js +7 -0
- package/dist/EggApplicationLoader-PnIvd5oV.d.ts +8 -0
- package/dist/IMessenger-C9g6ypSI.d.ts +54 -0
- package/dist/MessageUnhandledRejectionError-Lq5fWw24.d.ts +8 -0
- package/dist/MessageUnhandledRejectionError-oD_E1Ewl.js +15 -0
- package/dist/agent-BfFWeJj4.js +55 -0
- package/dist/agent.d.ts +11 -1
- package/dist/agent.js +1 -1
- package/dist/app/extend/context.d.ts +11 -206
- package/dist/app/extend/context.js +1 -242
- package/dist/app/extend/helper.d.ts +11 -41
- package/dist/app/extend/helper.js +3 -45
- package/dist/app/extend/request.d.ts +11 -144
- package/dist/app/extend/request.js +2 -224
- package/dist/app/extend/response.d.ts +1 -34
- package/dist/app/extend/response.js +1 -34
- package/dist/app/middleware/meta.d.ts +11 -10
- package/dist/app/middleware/notfound.d.ts +11 -10
- package/dist/app/middleware/site_file.d.ts +11 -12
- package/dist/application-DVwFQSa9.js +208 -0
- package/dist/base-KLVtlzUD.d.ts +12 -0
- package/dist/base_context_class-Xc1OZql9.js +19 -0
- package/dist/base_context_logger-CZU59PGA.js +58 -0
- package/dist/base_hook_class-D0Gu2p8r.js +26 -0
- package/dist/base_hook_class-R8A8gm1s.d.ts +1109 -0
- package/dist/config/config.default.d.ts +12 -4
- package/dist/config/config.default.js +34 -7
- package/dist/config/favicon.png +0 -0
- package/dist/config/plugin.d.ts +1 -1
- package/dist/config/plugin.js +1 -1
- package/dist/context-D1Wg7CXs.js +244 -0
- package/dist/context_httpclient-BpRMdJhf.js +29 -0
- package/dist/egg-DVo5e_lr.js +800 -0
- package/dist/error-BYo_LRnd.js +1 -0
- package/dist/helper-B3PKMPXq.js +47 -0
- package/dist/httpclient-C1QPc_R7.js +36 -0
- package/dist/index-CUPkUUOR.d.ts +1 -0
- package/dist/index-CkgLZdB4.d.ts +1 -0
- package/dist/index.d.ts +12 -18
- package/dist/index.js +27 -18
- package/dist/lib/agent.d.ts +11 -21
- package/dist/lib/agent.js +20 -54
- package/dist/lib/application.d.ts +11 -70
- package/dist/lib/application.js +21 -207
- package/dist/lib/core/base_context_class.d.ts +11 -22
- package/dist/lib/core/base_context_class.js +2 -17
- package/dist/lib/core/base_context_logger.d.ts +11 -39
- package/dist/lib/core/base_context_logger.js +1 -56
- package/dist/lib/core/base_hook_class.d.ts +11 -17
- package/dist/lib/core/base_hook_class.js +1 -24
- package/dist/lib/core/context_httpclient.d.ts +11 -20
- package/dist/lib/core/context_httpclient.js +1 -27
- package/dist/lib/core/httpclient.d.ts +12 -17
- package/dist/lib/core/httpclient.js +1 -34
- package/dist/lib/core/logger.d.ts +11 -1
- package/dist/lib/core/logger.js +1 -29
- package/dist/lib/core/messenger/IMessenger.d.ts +1 -53
- package/dist/lib/core/messenger/base.d.ts +12 -11
- package/dist/lib/core/messenger/base.js +15 -27
- package/dist/lib/core/messenger/index.d.ts +12 -11
- package/dist/lib/core/messenger/index.js +15 -11
- package/dist/lib/core/messenger/ipc.d.ts +13 -4
- package/dist/lib/core/messenger/ipc.js +15 -120
- package/dist/lib/core/messenger/local.d.ts +12 -4
- package/dist/lib/core/messenger/local.js +15 -124
- package/dist/lib/core/utils.js +1 -46
- package/dist/lib/egg.d.ts +12 -306
- package/dist/lib/egg.js +15 -510
- package/dist/lib/error/CookieLimitExceedError.d.ts +1 -7
- package/dist/lib/error/CookieLimitExceedError.js +1 -13
- package/dist/lib/error/MessageUnhandledRejectionError.d.ts +1 -7
- package/dist/lib/error/MessageUnhandledRejectionError.js +1 -13
- package/dist/lib/error/index.d.ts +3 -2
- package/dist/lib/error/index.js +3 -2
- package/dist/lib/loader/AgentWorkerLoader.d.ts +2 -16
- package/dist/lib/loader/AgentWorkerLoader.js +2 -22
- package/dist/lib/loader/AppWorkerLoader.d.ts +2 -21
- package/dist/lib/loader/AppWorkerLoader.js +2 -35
- package/dist/lib/loader/EggApplicationLoader.d.ts +1 -7
- package/dist/lib/loader/EggApplicationLoader.js +1 -5
- package/dist/lib/loader/index.d.ts +4 -3
- package/dist/lib/loader/index.js +4 -3
- package/dist/lib/start.d.ts +11 -27
- package/dist/lib/start.js +25 -34
- package/dist/lib/types.d.ts +12 -259
- package/dist/lib/types.js +3 -13
- package/dist/lib/types.plugin.d.ts +1 -0
- package/dist/lib/types.plugin.js +3 -0
- package/dist/lib/utils.js +1 -12
- package/dist/loader-3myZ-rpm.js +1 -0
- package/dist/logger-C4tIcO3S.js +31 -0
- package/dist/request-Cy_1DlaX.js +225 -0
- package/dist/response-CDeQ9Sx2.js +36 -0
- package/dist/response-DlNYDj00.d.ts +29 -0
- package/dist/src-BuOjXSrB.js +3 -0
- package/dist/start-4E84z796.js +35 -0
- package/dist/types-dKSyDnVp.js +32 -0
- package/dist/types.plugin-B2v0K0I8.js +14 -0
- package/dist/types.plugin-C3D5I7VD.d.ts +12 -0
- package/dist/urllib.d.ts +1 -2
- package/dist/utils-B1Rjsoi9.js +48 -0
- package/dist/utils-BDoYg6z6.js +14 -0
- package/package.json +30 -30
|
@@ -1,122 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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 { Messenger } from "../../../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";
|
|
5
16
|
|
|
6
|
-
//#region src/lib/core/messenger/ipc.ts
|
|
7
|
-
const debug = debuglog("egg/lib/core/messenger/ipc");
|
|
8
|
-
/**
|
|
9
|
-
* Communication between app worker and agent worker by IPC channel
|
|
10
|
-
*/
|
|
11
|
-
var Messenger = class extends BaseMessenger {
|
|
12
|
-
pid;
|
|
13
|
-
opids = [];
|
|
14
|
-
constructor(egg) {
|
|
15
|
-
super(egg);
|
|
16
|
-
this.pid = String(process.pid);
|
|
17
|
-
this.on("egg-pids", (workerIds) => {
|
|
18
|
-
debug("[%s:%s] got egg-pids %j", this.egg.type, this.pid, workerIds);
|
|
19
|
-
this.opids = workerIds.map((workerId) => String(workerId));
|
|
20
|
-
});
|
|
21
|
-
this.onMessage = this.onMessage.bind(this);
|
|
22
|
-
process.on("message", this.onMessage);
|
|
23
|
-
if (!workerThreads.isMainThread) workerThreads.parentPort.on("message", this.onMessage);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Send message to all agent and app
|
|
27
|
-
* @param {String} action - message key
|
|
28
|
-
* @param {Object} data - message value
|
|
29
|
-
* @return {Messenger} this
|
|
30
|
-
*/
|
|
31
|
-
broadcast(action, data) {
|
|
32
|
-
debug("[%s:%s] broadcast %s with %j", this.egg.type, this.pid, action, data);
|
|
33
|
-
this.send(action, data, "app");
|
|
34
|
-
this.send(action, data, "agent");
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* send message to the specified process
|
|
39
|
-
* @param {String} workerId - the workerId of the receiver
|
|
40
|
-
* @param {String} action - message key
|
|
41
|
-
* @param {Object} data - message value
|
|
42
|
-
* @return {Messenger} this
|
|
43
|
-
*/
|
|
44
|
-
sendTo(workerId, action, data) {
|
|
45
|
-
debug("[%s:%s] send %s with %j to workerId:%s", this.egg.type, this.pid, action, data, workerId);
|
|
46
|
-
sendmessage(process, {
|
|
47
|
-
action,
|
|
48
|
-
data,
|
|
49
|
-
receiverPid: String(workerId),
|
|
50
|
-
receiverWorkerId: String(workerId)
|
|
51
|
-
});
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* send message to one app worker by random
|
|
56
|
-
* - if it's running in agent, it will send to one of app workers
|
|
57
|
-
* - if it's running in app, it will send to agent
|
|
58
|
-
* @param {String} action - message key
|
|
59
|
-
* @param {Object} data - message value
|
|
60
|
-
* @return {Messenger} this
|
|
61
|
-
*/
|
|
62
|
-
sendRandom(action, data) {
|
|
63
|
-
if (this.opids.length === 0) {
|
|
64
|
-
debug("[%s:%s] no pids, ignore sendRandom %s with %j", this.egg.type, this.pid, action, data);
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
const index = Math.floor(Math.random() * this.opids.length);
|
|
68
|
-
const workerId = this.opids[index];
|
|
69
|
-
this.sendTo(workerId, action, data);
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* send message to app
|
|
74
|
-
* @param {String} action - message key
|
|
75
|
-
* @param {Object} data - message value
|
|
76
|
-
* @return {Messenger} this
|
|
77
|
-
*/
|
|
78
|
-
sendToApp(action, data) {
|
|
79
|
-
debug("[%s:%s] send %s with %j to all app", this.egg.type, this.pid, action, data);
|
|
80
|
-
this.send(action, data, "app");
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* send message to agent
|
|
85
|
-
* @param {String} action - message key
|
|
86
|
-
* @param {Object} data - message value
|
|
87
|
-
* @return {Messenger} this
|
|
88
|
-
*/
|
|
89
|
-
sendToAgent(action, data) {
|
|
90
|
-
debug("[%s:%s] send %s with %j to all agent", this.egg.type, this.pid, action, data);
|
|
91
|
-
this.send(action, data, "agent");
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @param {String} action - message key
|
|
96
|
-
* @param {Object} data - message value
|
|
97
|
-
* @param {String} to - let master know how to send message
|
|
98
|
-
* @return {Messenger} this
|
|
99
|
-
*/
|
|
100
|
-
send(action, data, to) {
|
|
101
|
-
sendmessage(process, {
|
|
102
|
-
action,
|
|
103
|
-
data,
|
|
104
|
-
to
|
|
105
|
-
});
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
onMessage(message) {
|
|
109
|
-
if (typeof message?.action === "string") {
|
|
110
|
-
debug("[%s:%s] got message %s with %j, receiverWorkerId: %s", this.egg.type, this.pid, message.action, message.data, message.receiverWorkerId ?? message.receiverPid);
|
|
111
|
-
this.emit(message.action, message.data);
|
|
112
|
-
} else if (message?.type === "Buffer") debug("[%s:%s] got an invalid message: %s", this.egg.type, this.pid, Buffer.from(message.data));
|
|
113
|
-
else debug("[%s:%s] got an invalid message %j", this.egg.type, this.pid, message);
|
|
114
|
-
}
|
|
115
|
-
close() {
|
|
116
|
-
process.removeListener("message", this.onMessage);
|
|
117
|
-
this.removeAllListeners();
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
17
|
export { Messenger };
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import "../../../EggApplicationLoader-PnIvd5oV.js";
|
|
2
|
+
import "../../../AppWorkerLoader-CT875rYM.js";
|
|
3
|
+
import "../../../AgentWorkerLoader-DG_hAClt.js";
|
|
4
|
+
import "../../../index-CUPkUUOR.js";
|
|
5
|
+
import { EggApplicationCore } from "../../../base_hook_class-R8A8gm1s.js";
|
|
6
|
+
import "../../../response-DlNYDj00.js";
|
|
7
|
+
import "../../../types.plugin-C3D5I7VD.js";
|
|
8
|
+
import { IMessenger } from "../../../IMessenger-C9g6ypSI.js";
|
|
9
|
+
import "../../../CookieLimitExceedError-CAW0HYJw.js";
|
|
10
|
+
import "../../../MessageUnhandledRejectionError-Lq5fWw24.js";
|
|
11
|
+
import "../../../index-CkgLZdB4.js";
|
|
12
|
+
import { BaseMessenger } from "../../../base-KLVtlzUD.js";
|
|
4
13
|
|
|
5
14
|
//#region src/lib/core/messenger/local.d.ts
|
|
6
|
-
|
|
7
15
|
/**
|
|
8
16
|
* Communication between app worker and agent worker with EventEmitter
|
|
9
17
|
*/
|
|
@@ -1,126 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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 { Messenger$1 as Messenger } from "../../../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";
|
|
3
16
|
|
|
4
|
-
//#region src/lib/core/messenger/local.ts
|
|
5
|
-
const debug = debuglog("egg/lib/core/messenger/local");
|
|
6
|
-
/**
|
|
7
|
-
* Communication between app worker and agent worker with EventEmitter
|
|
8
|
-
*/
|
|
9
|
-
var Messenger = class extends BaseMessenger {
|
|
10
|
-
pid;
|
|
11
|
-
constructor(egg) {
|
|
12
|
-
super(egg);
|
|
13
|
-
this.pid = String(process.pid);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Send message to all agent and app
|
|
17
|
-
* @param {String} action - message key
|
|
18
|
-
* @param {Object} data - message value
|
|
19
|
-
* @return {Messenger} this
|
|
20
|
-
*/
|
|
21
|
-
broadcast(action, data) {
|
|
22
|
-
debug("[%s:%s] broadcast %s with %j", this.egg.type, this.pid, action, data);
|
|
23
|
-
this.send(action, data, "both");
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* send message to the specified process
|
|
28
|
-
* Notice: in single process mode, it only can send to self process,
|
|
29
|
-
* and it will send to both agent and app's messengers.
|
|
30
|
-
* @param {String} workerId - the workerId of the receiver
|
|
31
|
-
* @param {String} action - message key
|
|
32
|
-
* @param {Object} data - message value
|
|
33
|
-
* @return {Messenger} this
|
|
34
|
-
*/
|
|
35
|
-
sendTo(workerId, action, data) {
|
|
36
|
-
debug("[%s:%s] send %s with %j to %s", this.egg.type, this.pid, action, data, workerId);
|
|
37
|
-
if (String(workerId) !== this.pid) return this;
|
|
38
|
-
this.send(action, data, "both");
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* send message to one worker by random
|
|
43
|
-
* Notice: in single process mode, we only start one agent worker and one app worker
|
|
44
|
-
* - if it's running in agent, it will send to one of app workers
|
|
45
|
-
* - if it's running in app, it will send to agent
|
|
46
|
-
* @param {String} action - message key
|
|
47
|
-
* @param {Object} data - message value
|
|
48
|
-
* @return {Messenger} this
|
|
49
|
-
*/
|
|
50
|
-
sendRandom(action, data) {
|
|
51
|
-
debug("[%s:%s] send %s with %j to opposite", this.egg.type, this.pid, action, data);
|
|
52
|
-
this.send(action, data, "opposite");
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* send message to app
|
|
57
|
-
* @param {String} action - message key
|
|
58
|
-
* @param {Object} data - message value
|
|
59
|
-
* @return {Messenger} this
|
|
60
|
-
*/
|
|
61
|
-
sendToApp(action, data) {
|
|
62
|
-
debug("[%s:%s] send %s with %j to all app", this.egg.type, this.pid, action, data);
|
|
63
|
-
this.send(action, data, "application");
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* send message to agent
|
|
68
|
-
* @param {String} action - message key
|
|
69
|
-
* @param {Object} data - message value
|
|
70
|
-
* @return {Messenger} this
|
|
71
|
-
*/
|
|
72
|
-
sendToAgent(action, data) {
|
|
73
|
-
debug("[%s:%s] send %s with %j to all agent", this.egg.type, this.pid, action, data);
|
|
74
|
-
this.send(action, data, "agent");
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* @param {String} action - message key
|
|
79
|
-
* @param {Object} data - message value
|
|
80
|
-
* @param {String} to - let master know how to send message
|
|
81
|
-
* @return {Messenger} this
|
|
82
|
-
*/
|
|
83
|
-
send(action, data, to) {
|
|
84
|
-
process.nextTick(() => {
|
|
85
|
-
const { egg } = this;
|
|
86
|
-
let application;
|
|
87
|
-
let agent;
|
|
88
|
-
let opposite;
|
|
89
|
-
if (egg.type === "application") {
|
|
90
|
-
application = egg;
|
|
91
|
-
agent = egg.agent;
|
|
92
|
-
opposite = agent;
|
|
93
|
-
} else {
|
|
94
|
-
agent = egg;
|
|
95
|
-
application = egg.application;
|
|
96
|
-
opposite = application;
|
|
97
|
-
}
|
|
98
|
-
if (!to) to = egg.type === "application" ? "agent" : "application";
|
|
99
|
-
if (application && application.messenger && (to === "application" || to === "both")) application.messenger.onMessage({
|
|
100
|
-
action,
|
|
101
|
-
data
|
|
102
|
-
});
|
|
103
|
-
if (agent && agent.messenger && (to === "agent" || to === "both")) agent.messenger.onMessage({
|
|
104
|
-
action,
|
|
105
|
-
data
|
|
106
|
-
});
|
|
107
|
-
if (opposite && opposite.messenger && to === "opposite") opposite.messenger.onMessage({
|
|
108
|
-
action,
|
|
109
|
-
data
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
onMessage(message) {
|
|
115
|
-
if (typeof message?.action === "string") {
|
|
116
|
-
debug("[%s:%s] got message %s with %j", this.egg.type, this.pid, message.action, message.data);
|
|
117
|
-
this.emit(message.action, message.data);
|
|
118
|
-
} else debug("[%s:%s] got an invalid message %j", this.egg.type, this.pid, message);
|
|
119
|
-
}
|
|
120
|
-
close() {
|
|
121
|
-
this.removeAllListeners();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
//#endregion
|
|
126
17
|
export { Messenger };
|
package/dist/lib/core/utils.js
CHANGED
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isAsyncFunction, isClass, isFunction, isGeneratorFunction, isPrimitive, isRegExp, isSymbol } from "is-type-of";
|
|
1
|
+
import { convertObject, safeParseURL } from "../../utils-B1Rjsoi9.js";
|
|
3
2
|
|
|
4
|
-
//#region src/lib/core/utils.ts
|
|
5
|
-
function convertObject(obj, ignore = []) {
|
|
6
|
-
if (!Array.isArray(ignore)) ignore = [ignore];
|
|
7
|
-
for (const key of Object.keys(obj)) obj[key] = convertValue(key, obj[key], ignore);
|
|
8
|
-
return obj;
|
|
9
|
-
}
|
|
10
|
-
function convertValue(key, value, ignore) {
|
|
11
|
-
if (value === null || value === void 0) return value;
|
|
12
|
-
let hit = false;
|
|
13
|
-
for (const matchKey of ignore) if (typeof matchKey === "string" && matchKey === key) {
|
|
14
|
-
hit = true;
|
|
15
|
-
break;
|
|
16
|
-
} else if (isRegExp(matchKey) && matchKey.test(key)) {
|
|
17
|
-
hit = true;
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
if (!hit) {
|
|
21
|
-
if (isSymbol(value) || isRegExp(value) || value instanceof URL) return value.toString();
|
|
22
|
-
if (isPrimitive(value) || Array.isArray(value)) return value;
|
|
23
|
-
}
|
|
24
|
-
if (Object.getPrototypeOf(value) === Object.prototype) return convertObject(value, ignore);
|
|
25
|
-
const name = value.name || "anonymous";
|
|
26
|
-
if (isClass(value)) return `<Class ${name}>`;
|
|
27
|
-
if (isFunction(value)) {
|
|
28
|
-
if (isGeneratorFunction(value)) return `<GeneratorFunction ${name}>`;
|
|
29
|
-
if (isAsyncFunction(value)) return `<AsyncFunction ${name}>`;
|
|
30
|
-
return `<Function ${name}>`;
|
|
31
|
-
}
|
|
32
|
-
const typeName = value.constructor.name;
|
|
33
|
-
if (typeName) {
|
|
34
|
-
if (Buffer.isBuffer(value) || typeof value === "string") return `<${typeName} len: ${value.length}>`;
|
|
35
|
-
return `<${typeName}>`;
|
|
36
|
-
}
|
|
37
|
-
return util.format(value);
|
|
38
|
-
}
|
|
39
|
-
function safeParseURL(url) {
|
|
40
|
-
try {
|
|
41
|
-
return new URL(url);
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
3
|
export { convertObject, safeParseURL };
|
package/dist/lib/egg.d.ts
CHANGED
|
@@ -1,306 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import Context from "../
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
14
|
-
import { EggContextLogger, EggLogger, EggLoggers } from "egg-logger";
|
|
15
|
-
import { Cookies } from "@eggjs/cookies";
|
|
16
|
-
|
|
17
|
-
//#region src/lib/egg.d.ts
|
|
18
|
-
declare const EGG_PATH: unique symbol;
|
|
19
|
-
interface EggApplicationCoreOptions extends Omit<EggCoreOptions, 'baseDir'> {
|
|
20
|
-
mode?: 'cluster' | 'single';
|
|
21
|
-
clusterPort?: number;
|
|
22
|
-
baseDir?: string;
|
|
23
|
-
}
|
|
24
|
-
declare class Request extends Request$1 {
|
|
25
|
-
app: EggCore;
|
|
26
|
-
response: Response;
|
|
27
|
-
ctx: Context;
|
|
28
|
-
}
|
|
29
|
-
declare class Response extends Response$1 {
|
|
30
|
-
app: EggCore;
|
|
31
|
-
request: Request;
|
|
32
|
-
ctx: Context;
|
|
33
|
-
}
|
|
34
|
-
type EggContext = Context;
|
|
35
|
-
type MiddlewareFunc<T extends Context = Context> = MiddlewareFunc$1<T>;
|
|
36
|
-
/**
|
|
37
|
-
* Based on koa's Application
|
|
38
|
-
* @see https://github.com/eggjs/egg-core
|
|
39
|
-
* @see https://github.com/eggjs/koa/blob/master/src/application.ts
|
|
40
|
-
* @augments EggCore
|
|
41
|
-
*/
|
|
42
|
-
declare class EggApplicationCore extends EggCore {
|
|
43
|
-
#private;
|
|
44
|
-
ctxStorage: AsyncLocalStorage<Context>;
|
|
45
|
-
ContextCookies: typeof Cookies;
|
|
46
|
-
ContextLogger: typeof EggContextLogger;
|
|
47
|
-
ContextHttpClient: typeof ContextHttpClient;
|
|
48
|
-
HttpClient: typeof HttpClient;
|
|
49
|
-
HttpClientNext: typeof HttpClient;
|
|
50
|
-
/**
|
|
51
|
-
* Retrieve base context class
|
|
52
|
-
* @member {BaseContextClass} BaseContextClass
|
|
53
|
-
* @since 1.0.0
|
|
54
|
-
*/
|
|
55
|
-
BaseContextClass: typeof BaseContextClass$1;
|
|
56
|
-
/**
|
|
57
|
-
* Retrieve base controller
|
|
58
|
-
* @member {Controller} Controller
|
|
59
|
-
* @since 1.0.0
|
|
60
|
-
*/
|
|
61
|
-
Controller: typeof BaseContextClass$1;
|
|
62
|
-
/**
|
|
63
|
-
* Retrieve base service
|
|
64
|
-
* @member {Service} Service
|
|
65
|
-
* @since 1.0.0
|
|
66
|
-
*/
|
|
67
|
-
Service: typeof BaseContextClass$1;
|
|
68
|
-
/**
|
|
69
|
-
* Retrieve base subscription
|
|
70
|
-
* @member {Subscription} Subscription
|
|
71
|
-
* @since 2.12.0
|
|
72
|
-
*/
|
|
73
|
-
Subscription: typeof BaseContextClass$1;
|
|
74
|
-
/**
|
|
75
|
-
* Retrieve base context class
|
|
76
|
-
* @member {BaseHookClass} BaseHookClass
|
|
77
|
-
*/
|
|
78
|
-
BaseHookClass: typeof BaseHookClass;
|
|
79
|
-
/**
|
|
80
|
-
* Retrieve base boot
|
|
81
|
-
* @member {Boot}
|
|
82
|
-
* @alias BaseHookClass
|
|
83
|
-
*/
|
|
84
|
-
Boot: typeof BaseHookClass;
|
|
85
|
-
options: Required<EggApplicationCoreOptions>;
|
|
86
|
-
readonly messenger: IMessenger;
|
|
87
|
-
agent?: Agent;
|
|
88
|
-
application?: Application;
|
|
89
|
-
loader: EggApplicationLoader;
|
|
90
|
-
/**
|
|
91
|
-
* @class
|
|
92
|
-
* @param {Object} options
|
|
93
|
-
* - {Object} [type] - type of instance, Agent and Application both extend koa, type can determine what it is.
|
|
94
|
-
* - {String} [baseDir] - app root dir, default is `process.cwd()`
|
|
95
|
-
* - {Object} [plugins] - custom plugin config, use it in unittest
|
|
96
|
-
* - {String} [mode] - process mode, can be cluster / single, default is `cluster`
|
|
97
|
-
*/
|
|
98
|
-
constructor(options?: EggApplicationCoreOptions);
|
|
99
|
-
/**
|
|
100
|
-
* @deprecated please use `options` property instead
|
|
101
|
-
*/
|
|
102
|
-
get _options(): Required<EggApplicationCoreOptions>;
|
|
103
|
-
protected loadConfig(): Promise<void>;
|
|
104
|
-
protected load(): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Usage: new ApiClient({ cluster: app.cluster })
|
|
107
|
-
*/
|
|
108
|
-
get cluster(): (clientClass: unknown, options?: object) => any;
|
|
109
|
-
/**
|
|
110
|
-
* Wrap the Client with Leader/Follower Pattern
|
|
111
|
-
*
|
|
112
|
-
* @description almost the same as Agent.cluster API, the only different is that this method create Follower.
|
|
113
|
-
*
|
|
114
|
-
* @see https://github.com/node-modules/cluster-client
|
|
115
|
-
* @param {Function} clientClass - client class function
|
|
116
|
-
* @param {Object} [options]
|
|
117
|
-
* - {Boolean} [autoGenerate] - whether generate delegate rule automatically, default is true
|
|
118
|
-
* - {Function} [formatKey] - a method to transform the subscription info into a string,default is JSON.stringify
|
|
119
|
-
* - {Object} [transcode|JSON.stringify/parse]
|
|
120
|
-
* - {Function} encode - custom serialize method
|
|
121
|
-
* - {Function} decode - custom deserialize method
|
|
122
|
-
* - {Boolean} [isBroadcast] - whether broadcast subscription result to all followers or just one, default is true
|
|
123
|
-
* - {Number} [responseTimeout] - response timeout, default is 3 seconds
|
|
124
|
-
* - {Number} [maxWaitTime|30000] - leader startup max time, default is 30 seconds
|
|
125
|
-
* @return {ClientWrapper} wrapper
|
|
126
|
-
*/
|
|
127
|
-
clusterWrapper(clientClass: unknown, options?: object): any;
|
|
128
|
-
/**
|
|
129
|
-
* print the information when console.log(app)
|
|
130
|
-
* @return {Object} inspected app.
|
|
131
|
-
* @since 1.0.0
|
|
132
|
-
* @example
|
|
133
|
-
* ```js
|
|
134
|
-
* console.log(app);
|
|
135
|
-
* =>
|
|
136
|
-
* {
|
|
137
|
-
* name: 'mock-app',
|
|
138
|
-
* env: 'test',
|
|
139
|
-
* subdomainOffset: 2,
|
|
140
|
-
* config: '<egg config>',
|
|
141
|
-
* controller: '<egg controller>',
|
|
142
|
-
* service: '<egg service>',
|
|
143
|
-
* middlewares: '<egg middlewares>',
|
|
144
|
-
* urllib: '<egg urllib>',
|
|
145
|
-
* loggers: '<egg loggers>'
|
|
146
|
-
* }
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
inspect(): any;
|
|
150
|
-
toJSON(): any;
|
|
151
|
-
/**
|
|
152
|
-
* http request helper base on {@link httpclient}, it will auto save httpclient log.
|
|
153
|
-
* Keep the same api with `httpclient.request(url, args)`.
|
|
154
|
-
*
|
|
155
|
-
* See https://github.com/node-modules/urllib#api-doc for more details.
|
|
156
|
-
*
|
|
157
|
-
* @param {String} url request url address.
|
|
158
|
-
* @param {Object} options
|
|
159
|
-
* - method {String} - Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'.
|
|
160
|
-
* - data {Object} - Data to be sent. Will be stringify automatically.
|
|
161
|
-
* - dataType {String} - String - Type of response data. Could be `text` or `json`.
|
|
162
|
-
* If it's `text`, the callback data would be a String.
|
|
163
|
-
* If it's `json`, the data of callback would be a parsed JSON Object.
|
|
164
|
-
* Default callback data would be a Buffer.
|
|
165
|
-
* - headers {Object} - Request headers.
|
|
166
|
-
* - timeout {Number} - Request timeout in milliseconds. Defaults to exports.TIMEOUT.
|
|
167
|
-
* Include remote server connecting timeout and response timeout.
|
|
168
|
-
* When timeout happen, will return ConnectionTimeout or ResponseTimeout.
|
|
169
|
-
* - auth {String} - `username:password` used in HTTP Basic Authorization.
|
|
170
|
-
* - followRedirect {Boolean} - follow HTTP 3xx responses as redirects. defaults to false.
|
|
171
|
-
* - gzip {Boolean} - let you get the res object when request connected, default false. alias customResponse
|
|
172
|
-
* - nestedQuerystring {Boolean} - urllib default use querystring to stringify form data which don't
|
|
173
|
-
* support nested object, will use qs instead of querystring to support nested object by set this option to true.
|
|
174
|
-
* - more options see https://github.com/node-modules/urllib
|
|
175
|
-
* @return {Object}
|
|
176
|
-
* - status {Number} - HTTP response status
|
|
177
|
-
* - headers {Object} - HTTP response headers
|
|
178
|
-
* - res {Object} - HTTP response meta
|
|
179
|
-
* - data {Object} - HTTP response body
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```js
|
|
183
|
-
* const result = await app.curl('http://example.com/foo.json', {
|
|
184
|
-
* method: 'GET',
|
|
185
|
-
* dataType: 'json',
|
|
186
|
-
* });
|
|
187
|
-
* console.log(result.status, result.headers, result.data);
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<HttpClientResponse<T>>;
|
|
191
|
-
/**
|
|
192
|
-
* Create a new HttpClient instance with custom options
|
|
193
|
-
* @param {Object} [options] HttpClient init options
|
|
194
|
-
*/
|
|
195
|
-
createHttpClient(options?: HttpClientOptions): HttpClient;
|
|
196
|
-
/**
|
|
197
|
-
* HttpClient instance
|
|
198
|
-
* @see https://github.com/node-modules/urllib
|
|
199
|
-
* @member {HttpClient}
|
|
200
|
-
*/
|
|
201
|
-
get httpClient(): HttpClient;
|
|
202
|
-
/**
|
|
203
|
-
* @deprecated please use httpClient instead
|
|
204
|
-
* @alias httpClient
|
|
205
|
-
* @member {HttpClient}
|
|
206
|
-
*/
|
|
207
|
-
get httpclient(): HttpClient;
|
|
208
|
-
/**
|
|
209
|
-
* All loggers contain logger, coreLogger and customLogger
|
|
210
|
-
* @member {Object}
|
|
211
|
-
* @since 1.0.0
|
|
212
|
-
*/
|
|
213
|
-
get loggers(): EggLoggers;
|
|
214
|
-
/**
|
|
215
|
-
* Get logger by name, it's equal to app.loggers['name'],
|
|
216
|
-
* but you can extend it with your own logical.
|
|
217
|
-
* @param {String} name - logger name
|
|
218
|
-
* @return {Logger} logger
|
|
219
|
-
*/
|
|
220
|
-
getLogger(name: string): EggLogger;
|
|
221
|
-
/**
|
|
222
|
-
* application logger, log file is `$HOME/logs/{appname}/{appname}-web`
|
|
223
|
-
* @member {Logger}
|
|
224
|
-
* @since 1.0.0
|
|
225
|
-
*/
|
|
226
|
-
get logger(): EggLogger;
|
|
227
|
-
/**
|
|
228
|
-
* core logger for framework and plugins, log file is `$HOME/logs/{appname}/egg-web`
|
|
229
|
-
* @member {Logger}
|
|
230
|
-
* @since 1.0.0
|
|
231
|
-
*/
|
|
232
|
-
get coreLogger(): EggLogger;
|
|
233
|
-
_unhandledRejectionHandler(err: any): void;
|
|
234
|
-
/**
|
|
235
|
-
* dump out the config and meta object
|
|
236
|
-
* @private
|
|
237
|
-
*/
|
|
238
|
-
dumpConfigToObject(): {
|
|
239
|
-
config: Record<string, any>;
|
|
240
|
-
meta: Record<string, any>;
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* save app.config to `run/${type}_config.json`
|
|
244
|
-
* @private
|
|
245
|
-
*/
|
|
246
|
-
dumpConfig(): void;
|
|
247
|
-
dumpTiming(): void;
|
|
248
|
-
get [EGG_PATH](): string;
|
|
249
|
-
get config(): EggAppConfig$1;
|
|
250
|
-
/**
|
|
251
|
-
* app.env delegate app.config.env
|
|
252
|
-
* @deprecated
|
|
253
|
-
*/
|
|
254
|
-
get env(): string;
|
|
255
|
-
set env(_: string);
|
|
256
|
-
/**
|
|
257
|
-
* app.proxy delegate app.config.proxy
|
|
258
|
-
* @deprecated
|
|
259
|
-
*/
|
|
260
|
-
get proxy(): boolean;
|
|
261
|
-
set proxy(_: boolean);
|
|
262
|
-
/**
|
|
263
|
-
* Create an anonymous context, the context isn't request level, so the request is mocked.
|
|
264
|
-
* then you can use context level API like `ctx.service`
|
|
265
|
-
* @member {String} EggApplication#createAnonymousContext
|
|
266
|
-
* @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
|
|
267
|
-
* @return {Context} context
|
|
268
|
-
*/
|
|
269
|
-
createAnonymousContext(req?: any): EggContext;
|
|
270
|
-
/**
|
|
271
|
-
* Run async function in the anonymous context scope
|
|
272
|
-
* @see Context#runInAnonymousContextScope
|
|
273
|
-
* @param {Function} scope - the first args is an anonymous ctx, scope should be async function
|
|
274
|
-
* @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
|
|
275
|
-
*/
|
|
276
|
-
runInAnonymousContextScope(scope: (ctx: Context) => Promise<void>, req?: unknown): Promise<void>;
|
|
277
|
-
/**
|
|
278
|
-
* Create egg context
|
|
279
|
-
* @function EggApplication#createContext
|
|
280
|
-
* @param {Req} req - node native Request object
|
|
281
|
-
* @param {Res} res - node native Response object
|
|
282
|
-
* @return {Context} context object
|
|
283
|
-
*/
|
|
284
|
-
createContext(req: IncomingMessage, res: ServerResponse): Context;
|
|
285
|
-
}
|
|
286
|
-
declare module '@eggjs/core' {
|
|
287
|
-
interface EggCore {
|
|
288
|
-
inspect(): any;
|
|
289
|
-
get currentContext(): EggContext | undefined;
|
|
290
|
-
ctxStorage: AsyncLocalStorage<EggContext>;
|
|
291
|
-
getLogger(name: string): EggLogger;
|
|
292
|
-
get loggers(): EggLoggers;
|
|
293
|
-
createHttpClient(options?: HttpClientOptions): HttpClient;
|
|
294
|
-
HttpClient: typeof HttpClient;
|
|
295
|
-
get httpClient(): HttpClient;
|
|
296
|
-
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<HttpClientResponse<T>>;
|
|
297
|
-
createAnonymousContext(req?: any): EggContext;
|
|
298
|
-
runInAnonymousContextScope(scope: (ctx: Context) => Promise<void>, req?: unknown): Promise<void>;
|
|
299
|
-
readonly messenger: IMessenger;
|
|
300
|
-
Subscription: typeof BaseContextClass$1;
|
|
301
|
-
BaseHookClass: typeof BaseHookClass;
|
|
302
|
-
Boot: typeof BaseHookClass;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
//#endregion
|
|
306
|
-
export { Context, EggApplicationCore, EggApplicationCoreOptions, EggContext, type ILifecycleBoot as IBoot, type ILifecycleBoot, MiddlewareFunc, type Next, Request, Response, Router };
|
|
1
|
+
import "../EggApplicationLoader-PnIvd5oV.js";
|
|
2
|
+
import "../AppWorkerLoader-CT875rYM.js";
|
|
3
|
+
import "../AgentWorkerLoader-DG_hAClt.js";
|
|
4
|
+
import "../index-CUPkUUOR.js";
|
|
5
|
+
import { Context, EggApplicationCore, EggApplicationCoreOptions, EggContext, ILifecycleBoot, MiddlewareFunc, Next, Request, Router } 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-CAW0HYJw.js";
|
|
10
|
+
import "../MessageUnhandledRejectionError-Lq5fWw24.js";
|
|
11
|
+
import "../index-CkgLZdB4.js";
|
|
12
|
+
export { Context, EggApplicationCore, EggApplicationCoreOptions, EggContext, ILifecycleBoot as IBoot, ILifecycleBoot, MiddlewareFunc, Next, Request, Response, Router };
|