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
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { Request } from "@eggjs/core";
|
|
2
|
+
import querystring from "node:querystring";
|
|
3
|
+
|
|
4
|
+
//#region src/app/extend/request.ts
|
|
5
|
+
const QUERY_CACHE = Symbol("request query cache");
|
|
6
|
+
const QUERIES_CACHE = Symbol("request queries cache");
|
|
7
|
+
const PROTOCOL = Symbol("request protocol");
|
|
8
|
+
const HOST = Symbol("request host");
|
|
9
|
+
const IPS = Symbol("request ips");
|
|
10
|
+
const RE_ARRAY_KEY = /[^[\]]+\[\]$/;
|
|
11
|
+
var Request$1 = class extends Request {
|
|
12
|
+
/**
|
|
13
|
+
* Parse the "Host" header field host
|
|
14
|
+
* and support X-Forwarded-Host when a
|
|
15
|
+
* proxy is enabled.
|
|
16
|
+
* @member {String} Request#host
|
|
17
|
+
* @example
|
|
18
|
+
* ip + port
|
|
19
|
+
* ```js
|
|
20
|
+
* this.request.host
|
|
21
|
+
* => '127.0.0.1:7001'
|
|
22
|
+
* ```
|
|
23
|
+
* or domain
|
|
24
|
+
* ```js
|
|
25
|
+
* this.request.host
|
|
26
|
+
* => 'demo.eggjs.org'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
get host() {
|
|
30
|
+
let host = this[HOST];
|
|
31
|
+
if (host) return host;
|
|
32
|
+
if (this.app.config.proxy) host = getFromHeaders(this, this.app.config.hostHeaders);
|
|
33
|
+
host = host || this.get("host") || "";
|
|
34
|
+
this[HOST] = host = host.split(",")[0].trim();
|
|
35
|
+
return host;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @member {String} Request#protocol
|
|
39
|
+
* @example
|
|
40
|
+
* ```js
|
|
41
|
+
* this.request.protocol
|
|
42
|
+
* => 'https'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
get protocol() {
|
|
46
|
+
let protocol = this[PROTOCOL];
|
|
47
|
+
if (protocol) return protocol;
|
|
48
|
+
if (this.socket?.encrypted) {
|
|
49
|
+
this[PROTOCOL] = protocol = "https";
|
|
50
|
+
return protocol;
|
|
51
|
+
}
|
|
52
|
+
if (this.app.config.proxy) {
|
|
53
|
+
const proto = getFromHeaders(this, this.app.config.protocolHeaders);
|
|
54
|
+
if (proto) {
|
|
55
|
+
this[PROTOCOL] = protocol = proto.split(/\s*,\s*/)[0];
|
|
56
|
+
return protocol;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this[PROTOCOL] = protocol = this.app.config.protocol || "http";
|
|
60
|
+
return protocol;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get all pass through ip addresses from the request.
|
|
64
|
+
* Enable only on `app.config.proxy = true`
|
|
65
|
+
*
|
|
66
|
+
* @member {Array} Request#ips
|
|
67
|
+
* @example
|
|
68
|
+
* ```js
|
|
69
|
+
* this.request.ips
|
|
70
|
+
* => ['100.23.1.2', '201.10.10.2']
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
get ips() {
|
|
74
|
+
let ips = this[IPS];
|
|
75
|
+
if (ips) return ips;
|
|
76
|
+
if (!this.app.config.proxy) {
|
|
77
|
+
this[IPS] = ips = [];
|
|
78
|
+
return ips;
|
|
79
|
+
}
|
|
80
|
+
const val = getFromHeaders(this, this.app.config.ipHeaders);
|
|
81
|
+
this[IPS] = ips = val ? val.split(/\s*,\s*/) : [];
|
|
82
|
+
let maxIpsCount = this.app.config.maxIpsCount;
|
|
83
|
+
if (!maxIpsCount && this.app.config.maxProxyCount) maxIpsCount = this.app.config.maxProxyCount + 1;
|
|
84
|
+
if (maxIpsCount > 0) this[IPS] = ips = ips.slice(-maxIpsCount);
|
|
85
|
+
return ips;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the request remote IPv4 address
|
|
89
|
+
* @member {String} Request#ip
|
|
90
|
+
* @return {String} IPv4 address
|
|
91
|
+
* @example
|
|
92
|
+
* ```js
|
|
93
|
+
* this.request.ip
|
|
94
|
+
* => '127.0.0.1'
|
|
95
|
+
* => '111.10.2.1'
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
get ip() {
|
|
99
|
+
if (this._ip) return this._ip;
|
|
100
|
+
const ip = this.ips[0] ?? this.socket.remoteAddress;
|
|
101
|
+
this._ip = ip && ip.startsWith("::ffff:") ? ip.substring(7) : ip;
|
|
102
|
+
return this._ip;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Set the request remote IPv4 address
|
|
106
|
+
* @member {String} Request#ip
|
|
107
|
+
* @param {String} ip - IPv4 address
|
|
108
|
+
* @example
|
|
109
|
+
* ```js
|
|
110
|
+
* this.request.ip
|
|
111
|
+
* => '127.0.0.1'
|
|
112
|
+
* => '111.10.2.1'
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
set ip(ip) {
|
|
116
|
+
this._ip = ip;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* detect if response should be json
|
|
120
|
+
* 1. url path ends with `.json`
|
|
121
|
+
* 2. response type is set to json
|
|
122
|
+
* 3. detect by request accept header
|
|
123
|
+
*
|
|
124
|
+
* @member {Boolean} Request#acceptJSON
|
|
125
|
+
* @since 1.0.0
|
|
126
|
+
*/
|
|
127
|
+
get acceptJSON() {
|
|
128
|
+
if (this.path.endsWith(".json")) return true;
|
|
129
|
+
if (this.response.type && this.response.type.indexOf("json") >= 0) return true;
|
|
130
|
+
if (this.accepts("html", "text", "json") === "json") return true;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
_customQuery(cacheName, filter) {
|
|
134
|
+
const str = this.querystring || "";
|
|
135
|
+
let c = this[cacheName];
|
|
136
|
+
if (!c) c = this[cacheName] = {};
|
|
137
|
+
let cacheQuery = c[str];
|
|
138
|
+
if (!cacheQuery) {
|
|
139
|
+
cacheQuery = c[str] = {};
|
|
140
|
+
const isQueries = cacheName === QUERIES_CACHE;
|
|
141
|
+
const query = str ? querystring.parse(str) : {};
|
|
142
|
+
for (const key in query) {
|
|
143
|
+
if (!key) continue;
|
|
144
|
+
const value = filter(query[key]);
|
|
145
|
+
cacheQuery[key] = value;
|
|
146
|
+
if (isQueries && RE_ARRAY_KEY.test(key)) {
|
|
147
|
+
const subKey = key.substring(0, key.length - 2);
|
|
148
|
+
if (!cacheQuery[subKey]) cacheQuery[subKey] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return cacheQuery;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* get params pass by querystring, all values are of string type.
|
|
156
|
+
* @member {Object} Request#query
|
|
157
|
+
* @example
|
|
158
|
+
* ```js
|
|
159
|
+
* GET http://127.0.0.1:7001?name=Foo&age=20&age=21
|
|
160
|
+
* this.query
|
|
161
|
+
* => { 'name': 'Foo', 'age': '20' }
|
|
162
|
+
*
|
|
163
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
164
|
+
* this.query
|
|
165
|
+
* =>
|
|
166
|
+
* {
|
|
167
|
+
* "a": "b",
|
|
168
|
+
* "o[foo]": "bar",
|
|
169
|
+
* "b[]": "1",
|
|
170
|
+
* "e": "val"
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
get query() {
|
|
175
|
+
return this._customQuery(QUERY_CACHE, firstValue);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* get params pass by querystring, all value are Array type. {@link Request#query}
|
|
179
|
+
* @member {Array} Request#queries
|
|
180
|
+
* @example
|
|
181
|
+
* ```js
|
|
182
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
183
|
+
* this.queries
|
|
184
|
+
* =>
|
|
185
|
+
* {
|
|
186
|
+
* "a": ["b", "c"],
|
|
187
|
+
* "o[foo]": ["bar"],
|
|
188
|
+
* "b[]": ["1", "2"],
|
|
189
|
+
* "e": ["val"]
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
get queries() {
|
|
194
|
+
return this._customQuery(QUERIES_CACHE, arrayValue);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Set query-string as an object.
|
|
198
|
+
*
|
|
199
|
+
* @function Request#query
|
|
200
|
+
* @param {Object} obj set querystring and query object for request.
|
|
201
|
+
*/
|
|
202
|
+
set query(obj) {
|
|
203
|
+
this.querystring = querystring.stringify(obj);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
function firstValue(value) {
|
|
207
|
+
if (Array.isArray(value)) value = value[0];
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
function arrayValue(value) {
|
|
211
|
+
if (!Array.isArray(value)) value = [value];
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
function getFromHeaders(request, names) {
|
|
215
|
+
if (!names) return "";
|
|
216
|
+
const fields = names.split(/\s*,\s*/);
|
|
217
|
+
for (const name of fields) {
|
|
218
|
+
const value = request.get(name);
|
|
219
|
+
if (value) return value;
|
|
220
|
+
}
|
|
221
|
+
return "";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
export { Request$1 as Request };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Response } from "@eggjs/core";
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/response.ts
|
|
4
|
+
const REAL_STATUS = Symbol("response realStatus");
|
|
5
|
+
var Response$1 = class extends Response {
|
|
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
|
+
export { Response$1 as Response };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Response } from "@eggjs/core";
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/response.d.ts
|
|
4
|
+
declare class Response$1 extends Response {
|
|
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
|
|
29
|
+
export { Response$1 as Response };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Agent } from "./agent-BfFWeJj4.js";
|
|
2
|
+
import { Application } from "./application-DVwFQSa9.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readJSON } from "utility";
|
|
5
|
+
import { importModule } from "@eggjs/utils";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/start.ts
|
|
8
|
+
/**
|
|
9
|
+
* Start egg with single process
|
|
10
|
+
*/
|
|
11
|
+
async function startEgg(options = {}) {
|
|
12
|
+
options.baseDir = options.baseDir ?? process.cwd();
|
|
13
|
+
options.mode = "single";
|
|
14
|
+
if (!options.framework) try {
|
|
15
|
+
options.framework = (await readJSON(path.join(options.baseDir, "package.json"))).egg.framework;
|
|
16
|
+
} catch {}
|
|
17
|
+
let AgentClass = Agent;
|
|
18
|
+
let ApplicationClass = Application;
|
|
19
|
+
if (options.framework) {
|
|
20
|
+
const framework = await importModule(options.framework, { paths: [options.baseDir] });
|
|
21
|
+
AgentClass = framework.Agent;
|
|
22
|
+
ApplicationClass = framework.Application;
|
|
23
|
+
}
|
|
24
|
+
const agent = new AgentClass({ ...options });
|
|
25
|
+
await agent.ready();
|
|
26
|
+
const application = new ApplicationClass({ ...options });
|
|
27
|
+
application.agent = agent;
|
|
28
|
+
agent.application = application;
|
|
29
|
+
await application.ready();
|
|
30
|
+
application.messenger.broadcast("egg-ready");
|
|
31
|
+
return application;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { startEgg };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/lib/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define configuration with type safety
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { defineConfig } from 'egg';
|
|
7
|
+
*
|
|
8
|
+
* export default defineConfig({
|
|
9
|
+
* keys: 'my-keys',
|
|
10
|
+
* middleware: []
|
|
11
|
+
* });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function defineConfig(config) {
|
|
15
|
+
return config;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Define configuration factory function with type safety
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* export default defineConfigFactory((appInfo): PartialEggConfig => ({
|
|
22
|
+
* keys: appInfo.name + '_keys',
|
|
23
|
+
* middleware: []
|
|
24
|
+
* }));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function defineConfigFactory(configFactory) {
|
|
28
|
+
return configFactory;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { defineConfig, defineConfigFactory };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "@eggjs/development/types";
|
|
2
|
+
import "@eggjs/i18n/types";
|
|
3
|
+
import "@eggjs/jsonp/types";
|
|
4
|
+
import "@eggjs/logrotator/types";
|
|
5
|
+
import "@eggjs/multipart/types";
|
|
6
|
+
import "@eggjs/onerror/types";
|
|
7
|
+
import "@eggjs/schedule/types";
|
|
8
|
+
import "@eggjs/security/types";
|
|
9
|
+
import "@eggjs/session/types";
|
|
10
|
+
import "@eggjs/static/types";
|
|
11
|
+
import "@eggjs/view/types";
|
|
12
|
+
import "@eggjs/watcher/types";
|
|
13
|
+
|
|
14
|
+
export { };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "@eggjs/development/types";
|
|
2
|
+
import "@eggjs/i18n/types";
|
|
3
|
+
import "@eggjs/jsonp/types";
|
|
4
|
+
import "@eggjs/logrotator/types";
|
|
5
|
+
import "@eggjs/multipart/types";
|
|
6
|
+
import "@eggjs/onerror/types";
|
|
7
|
+
import "@eggjs/schedule/types";
|
|
8
|
+
import "@eggjs/security/types";
|
|
9
|
+
import "@eggjs/session/types";
|
|
10
|
+
import "@eggjs/static/types";
|
|
11
|
+
import "@eggjs/view/types";
|
|
12
|
+
import "@eggjs/watcher/types";
|
package/dist/urllib.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "urllib";
|
|
2
|
-
export {};
|
|
1
|
+
export * from "urllib";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import util from "node:util";
|
|
2
|
+
import { isAsyncFunction, isClass, isFunction, isGeneratorFunction, isPrimitive, isRegExp, isSymbol } from "is-type-of";
|
|
3
|
+
|
|
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
|
+
export { convertObject, safeParseURL };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/utils.ts
|
|
5
|
+
function getSourceDirname() {
|
|
6
|
+
if (typeof __dirname !== "undefined") return path.dirname(__dirname);
|
|
7
|
+
return path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
8
|
+
}
|
|
9
|
+
function getSourceFile(filename) {
|
|
10
|
+
return path.join(getSourceDirname(), filename);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { getSourceDirname, getSourceFile };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egg",
|
|
3
|
-
"version": "4.1.0-beta.
|
|
3
|
+
"version": "4.1.0-beta.20",
|
|
4
4
|
"engines": {
|
|
5
|
-
"node": ">=
|
|
5
|
+
"node": ">=22.18.0"
|
|
6
6
|
},
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"./lib/loader/EggApplicationLoader": "./dist/lib/loader/EggApplicationLoader.js",
|
|
53
53
|
"./lib/start": "./dist/lib/start.js",
|
|
54
54
|
"./lib/types": "./dist/lib/types.js",
|
|
55
|
+
"./lib/types.plugin": "./dist/lib/types.plugin.js",
|
|
55
56
|
"./lib/utils": "./dist/lib/utils.js",
|
|
56
57
|
"./urllib": "./dist/urllib.js",
|
|
57
58
|
"./package.json": "./package.json"
|
|
@@ -71,23 +72,8 @@
|
|
|
71
72
|
"egg"
|
|
72
73
|
],
|
|
73
74
|
"dependencies": {
|
|
74
|
-
"@eggjs/cluster": "",
|
|
75
|
-
"@eggjs/cookies": "^3.1.0",
|
|
76
|
-
"@eggjs/development": "^4.0.0",
|
|
77
|
-
"@eggjs/i18n": "^3.0.1",
|
|
78
|
-
"@eggjs/jsonp": "^3.0.0",
|
|
79
|
-
"@eggjs/logrotator": "^4.0.0",
|
|
80
|
-
"@eggjs/multipart": "^4.0.0",
|
|
81
|
-
"@eggjs/onerror": "^3.0.0",
|
|
82
|
-
"@eggjs/schedule": "^5.0.2",
|
|
83
|
-
"@eggjs/security": "^4.0.0",
|
|
84
|
-
"@eggjs/session": "^4.0.1",
|
|
85
|
-
"@eggjs/static": "^3.0.0",
|
|
86
|
-
"@eggjs/view": "^3.0.1",
|
|
87
|
-
"@eggjs/watcher": "^4.0.4",
|
|
88
75
|
"circular-json-for-egg": "^1.0.0",
|
|
89
76
|
"cluster-client": "^3.7.0",
|
|
90
|
-
"egg-errors": "^2.3.2",
|
|
91
77
|
"egg-logger": "^3.5.0",
|
|
92
78
|
"graceful": "^2.0.0",
|
|
93
79
|
"humanize-ms": "^2.0.0",
|
|
@@ -97,46 +83,60 @@
|
|
|
97
83
|
"onelogger": "^1.0.1",
|
|
98
84
|
"performance-ms": "^1.1.0",
|
|
99
85
|
"sendmessage": "^3.0.1",
|
|
100
|
-
"
|
|
86
|
+
"type-fest": "^5.0.1",
|
|
87
|
+
"urllib": "^4.8.2",
|
|
101
88
|
"utility": "^2.5.0",
|
|
102
|
-
"@eggjs/
|
|
103
|
-
"@eggjs/
|
|
104
|
-
"@eggjs/
|
|
89
|
+
"@eggjs/cluster": "4.0.0-beta.20",
|
|
90
|
+
"@eggjs/cookies": "4.0.0-beta.20",
|
|
91
|
+
"@eggjs/development": "5.0.0-beta.20",
|
|
92
|
+
"@eggjs/extend2": "5.0.0-beta.20",
|
|
93
|
+
"@eggjs/core": "7.0.0-beta.20",
|
|
94
|
+
"@eggjs/i18n": "4.0.0-beta.20",
|
|
95
|
+
"@eggjs/logrotator": "5.0.0-beta.20",
|
|
96
|
+
"@eggjs/jsonp": "4.0.0-beta.20",
|
|
97
|
+
"@eggjs/multipart": "5.0.0-beta.20",
|
|
98
|
+
"@eggjs/schedule": "6.0.0-beta.20",
|
|
99
|
+
"@eggjs/onerror": "4.0.0-beta.20",
|
|
100
|
+
"@eggjs/security": "5.0.0-beta.20",
|
|
101
|
+
"@eggjs/static": "4.0.0-beta.20",
|
|
102
|
+
"@eggjs/session": "5.0.0-beta.20",
|
|
103
|
+
"@eggjs/utils": "5.0.0-beta.20",
|
|
104
|
+
"@eggjs/view": "4.0.0-beta.20",
|
|
105
|
+
"@eggjs/watcher": "5.0.0-beta.20"
|
|
105
106
|
},
|
|
106
107
|
"devDependencies": {
|
|
107
|
-
"@eggjs/supertest": "",
|
|
108
108
|
"@types/koa-bodyparser": "^4.3.12",
|
|
109
|
-
"@types/node": "24",
|
|
110
109
|
"address": "2",
|
|
111
110
|
"assert-file": "1",
|
|
112
111
|
"coffee": "5",
|
|
113
112
|
"egg-plugin-puml": "^2.4.0",
|
|
114
|
-
"egg-tracer": "^2.1.0",
|
|
115
113
|
"egg-view-nunjucks": "^2.3.0",
|
|
116
114
|
"formstream": "^1.5.1",
|
|
117
115
|
"koa-static": "^5.0.0",
|
|
118
116
|
"mm": "^4.0.2",
|
|
119
|
-
"pedding": "^2.0.1",
|
|
120
117
|
"runscript": "^2.0.1",
|
|
121
118
|
"sdk-base": "^5.0.1",
|
|
122
119
|
"spy": "^1.0.0",
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"@eggjs/
|
|
127
|
-
"@eggjs/
|
|
120
|
+
"tsdown": "^0.15.4",
|
|
121
|
+
"typescript": "^5.9.3",
|
|
122
|
+
"@eggjs/koa": "3.1.0-beta.20",
|
|
123
|
+
"@eggjs/supertest": "9.0.0-beta.20",
|
|
124
|
+
"@eggjs/tracer": "4.0.0-beta.20",
|
|
125
|
+
"@eggjs/mock": "7.0.0-beta.20"
|
|
128
126
|
},
|
|
129
127
|
"repository": {
|
|
130
128
|
"type": "git",
|
|
131
129
|
"url": "git://github.com/eggjs/egg.git",
|
|
132
130
|
"directory": "packages/egg"
|
|
133
131
|
},
|
|
132
|
+
"homepage": "https://github.com/eggjs/egg/tree/next/packages/egg",
|
|
134
133
|
"license": "MIT",
|
|
135
134
|
"egg": {
|
|
136
135
|
"framework": true
|
|
137
136
|
},
|
|
138
137
|
"scripts": {
|
|
139
138
|
"lint": "oxlint",
|
|
139
|
+
"typecheck": "tsc --noEmit",
|
|
140
140
|
"build": "tsdown",
|
|
141
141
|
"test": "vitest run"
|
|
142
142
|
}
|