egg 4.0.0-beta.8 → 4.0.0
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/commonjs/app/extend/context.d.ts +38 -11
- package/dist/commonjs/app/extend/context.js +25 -23
- package/dist/commonjs/app/extend/context.types.d.ts +6 -4
- package/dist/commonjs/app/extend/request.d.ts +7 -2
- package/dist/commonjs/app/extend/request.js +2 -1
- package/dist/commonjs/app/extend/request.types.d.ts +10 -0
- package/dist/commonjs/app/extend/request.types.js +3 -0
- package/dist/commonjs/app/extend/response.d.ts +1 -0
- package/dist/commonjs/app/extend/response.js +2 -1
- package/dist/commonjs/app/extend/response.types.d.ts +7 -0
- package/dist/commonjs/app/extend/response.types.js +3 -0
- package/dist/commonjs/app/middleware/meta.d.ts +2 -2
- package/dist/commonjs/app/middleware/meta.js +1 -1
- package/dist/commonjs/app/middleware/notfound.d.ts +2 -2
- package/dist/commonjs/app/middleware/notfound.js +1 -1
- package/dist/commonjs/app/middleware/site_file.d.ts +3 -3
- package/dist/commonjs/app/middleware/site_file.js +1 -1
- package/dist/commonjs/config/config.default.d.ts +1 -1
- package/dist/commonjs/config/plugin.js +2 -2
- package/dist/commonjs/index.d.ts +12 -7
- package/dist/commonjs/index.js +11 -22
- package/dist/commonjs/lib/application.d.ts +7 -3
- package/dist/commonjs/lib/application.js +15 -4
- package/dist/commonjs/lib/core/base_context_class.d.ts +6 -3
- package/dist/commonjs/lib/core/base_context_class.js +1 -2
- package/dist/commonjs/lib/core/base_hook_class.d.ts +2 -2
- package/dist/commonjs/lib/core/base_hook_class.js +1 -2
- package/dist/commonjs/lib/core/context_httpclient.d.ts +3 -3
- package/dist/commonjs/lib/core/context_httpclient.js +1 -1
- package/dist/commonjs/lib/core/httpclient.d.ts +4 -3
- package/dist/commonjs/lib/core/httpclient.js +1 -1
- package/dist/commonjs/lib/core/messenger/base.d.ts +8 -0
- package/dist/commonjs/lib/core/messenger/base.js +31 -0
- package/dist/commonjs/lib/core/messenger/index.js +3 -2
- package/dist/commonjs/lib/core/messenger/ipc.d.ts +2 -3
- package/dist/commonjs/lib/core/messenger/ipc.js +4 -6
- package/dist/commonjs/lib/core/messenger/local.d.ts +2 -3
- package/dist/commonjs/lib/core/messenger/local.js +4 -9
- package/dist/commonjs/lib/core/utils.d.ts +1 -1
- package/dist/commonjs/lib/core/utils.js +3 -3
- package/dist/commonjs/lib/egg.d.ts +17 -11
- package/dist/commonjs/lib/egg.js +13 -4
- package/dist/commonjs/lib/egg.types.d.ts +8 -1
- package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +5 -0
- package/dist/commonjs/lib/error/CookieLimitExceedError.js +16 -0
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +5 -0
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +16 -0
- package/dist/commonjs/lib/error/index.d.ts +2 -0
- package/dist/commonjs/lib/error/index.js +19 -0
- package/dist/commonjs/lib/start.d.ts +10 -1
- package/dist/commonjs/lib/start.js +1 -1
- package/dist/commonjs/lib/{type.d.ts → types.d.ts} +39 -38
- package/dist/commonjs/lib/types.js +6 -0
- package/dist/commonjs/lib/utils.js +1 -1
- package/dist/commonjs/urllib.d.ts +1 -0
- package/dist/commonjs/urllib.js +18 -0
- package/dist/esm/app/extend/context.d.ts +38 -11
- package/dist/esm/app/extend/context.js +24 -19
- package/dist/esm/app/extend/context.types.d.ts +6 -4
- package/dist/esm/app/extend/request.d.ts +7 -2
- package/dist/esm/app/extend/request.js +2 -1
- package/dist/esm/app/extend/request.types.d.ts +10 -0
- package/dist/esm/app/extend/request.types.js +2 -0
- package/dist/esm/app/extend/response.d.ts +1 -0
- package/dist/esm/app/extend/response.js +2 -1
- package/dist/esm/app/extend/response.types.d.ts +7 -0
- package/dist/esm/app/extend/response.types.js +2 -0
- package/dist/esm/app/middleware/meta.d.ts +2 -2
- package/dist/esm/app/middleware/meta.js +1 -1
- package/dist/esm/app/middleware/notfound.d.ts +2 -2
- package/dist/esm/app/middleware/notfound.js +1 -1
- package/dist/esm/app/middleware/site_file.d.ts +3 -3
- package/dist/esm/app/middleware/site_file.js +1 -1
- package/dist/esm/config/config.default.d.ts +1 -1
- package/dist/esm/config/plugin.js +2 -2
- package/dist/esm/index.d.ts +12 -7
- package/dist/esm/index.js +13 -8
- package/dist/esm/lib/application.d.ts +7 -3
- package/dist/esm/lib/application.js +15 -4
- package/dist/esm/lib/core/base_context_class.d.ts +6 -3
- package/dist/esm/lib/core/base_context_class.js +1 -2
- package/dist/esm/lib/core/base_hook_class.d.ts +2 -2
- package/dist/esm/lib/core/base_hook_class.js +1 -2
- package/dist/esm/lib/core/context_httpclient.d.ts +3 -3
- package/dist/esm/lib/core/context_httpclient.js +1 -1
- package/dist/esm/lib/core/httpclient.d.ts +4 -3
- package/dist/esm/lib/core/httpclient.js +1 -1
- package/dist/esm/lib/core/messenger/base.d.ts +8 -0
- package/dist/esm/lib/core/messenger/base.js +27 -0
- package/dist/esm/lib/core/messenger/index.js +3 -2
- package/dist/esm/lib/core/messenger/ipc.d.ts +2 -3
- package/dist/esm/lib/core/messenger/ipc.js +4 -6
- package/dist/esm/lib/core/messenger/local.d.ts +2 -3
- package/dist/esm/lib/core/messenger/local.js +4 -6
- package/dist/esm/lib/core/utils.d.ts +1 -1
- package/dist/esm/lib/core/utils.js +3 -3
- package/dist/esm/lib/egg.d.ts +17 -11
- package/dist/esm/lib/egg.js +15 -5
- package/dist/esm/lib/egg.types.d.ts +8 -1
- package/dist/esm/lib/error/CookieLimitExceedError.d.ts +5 -0
- package/dist/esm/lib/error/CookieLimitExceedError.js +12 -0
- package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +5 -0
- package/dist/esm/lib/error/MessageUnhandledRejectionError.js +12 -0
- package/dist/esm/lib/error/index.d.ts +2 -0
- package/dist/esm/lib/error/index.js +3 -0
- package/dist/esm/lib/start.d.ts +10 -1
- package/dist/esm/lib/start.js +1 -1
- package/dist/esm/lib/{type.d.ts → types.d.ts} +39 -38
- package/dist/esm/lib/types.js +4 -0
- package/dist/esm/lib/utils.js +1 -1
- package/dist/esm/urllib.d.ts +1 -0
- package/dist/esm/urllib.js +2 -0
- package/dist/package.json +1 -1
- package/package.json +27 -19
- package/src/app/extend/context.ts +37 -32
- package/src/app/extend/context.types.ts +6 -6
- package/src/app/extend/request.ts +9 -2
- package/src/app/extend/request.types.ts +10 -0
- package/src/app/extend/response.ts +2 -0
- package/src/app/extend/response.types.ts +7 -0
- package/src/app/middleware/meta.ts +2 -2
- package/src/app/middleware/notfound.ts +2 -2
- package/src/app/middleware/site_file.ts +3 -3
- package/src/config/config.default.ts +1 -1
- package/src/config/config.local.ts +1 -1
- package/src/config/config.unittest.ts +1 -1
- package/src/config/plugin.ts +1 -1
- package/src/index.ts +40 -7
- package/src/lib/agent.ts +1 -1
- package/src/lib/application.ts +18 -6
- package/src/lib/core/base_context_class.ts +6 -3
- package/src/lib/core/base_hook_class.ts +2 -2
- package/src/lib/core/context_httpclient.ts +3 -3
- package/src/lib/core/httpclient.ts +10 -4
- package/src/lib/core/messenger/base.ts +30 -0
- package/src/lib/core/messenger/index.ts +2 -1
- package/src/lib/core/messenger/ipc.ts +3 -5
- package/src/lib/core/messenger/local.ts +3 -5
- package/src/lib/core/utils.ts +2 -2
- package/src/lib/egg.ts +29 -18
- package/src/lib/egg.types.ts +9 -0
- package/src/lib/error/CookieLimitExceedError.ts +12 -0
- package/src/lib/error/MessageUnhandledRejectionError.ts +12 -0
- package/src/lib/error/index.ts +2 -0
- package/src/lib/start.ts +12 -2
- package/src/lib/{type.ts → types.ts} +83 -40
- package/src/lib/utils.ts +0 -1
- package/src/urllib.ts +1 -0
- package/dist/commonjs/lib/type.js +0 -3
- package/dist/esm/lib/type.js +0 -2
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { Socket } from 'node:net';
|
|
2
2
|
import type { RequestOptions as HttpClientRequestOptions } from 'urllib';
|
|
3
3
|
import type { EggLoggerOptions, EggLoggersOptions } from 'egg-logger';
|
|
4
|
-
import type { FileLoaderOptions } from '@eggjs/core';
|
|
5
|
-
import type { EggApplicationCore,
|
|
4
|
+
import type { FileLoaderOptions, EggAppConfig as EggCoreAppConfig } from '@eggjs/core';
|
|
5
|
+
import type { EggApplicationCore, Context } from './egg.js';
|
|
6
6
|
import type { MetaMiddlewareOptions } from '../app/middleware/meta.js';
|
|
7
7
|
import type { NotFoundMiddlewareOptions } from '../app/middleware/notfound.js';
|
|
8
8
|
import type { SiteFileMiddlewareOptions } from '../app/middleware/site_file.js';
|
|
9
|
-
|
|
9
|
+
import '@eggjs/watcher';
|
|
10
|
+
import '@eggjs/development';
|
|
11
|
+
export type { EggAppInfo, } from '@eggjs/core';
|
|
12
|
+
type IgnoreItem = string | RegExp | ((ctx: Context) => boolean);
|
|
10
13
|
type IgnoreOrMatch = IgnoreItem | IgnoreItem[];
|
|
11
14
|
export interface ClientErrorResponse {
|
|
12
15
|
body: string | Buffer;
|
|
@@ -41,7 +44,7 @@ export interface CustomLoaderConfig extends Omit<FileLoaderOptions, 'inject' | '
|
|
|
41
44
|
*/
|
|
42
45
|
loadunit?: boolean;
|
|
43
46
|
}
|
|
44
|
-
export interface EggAppConfig {
|
|
47
|
+
export interface EggAppConfig extends EggCoreAppConfig {
|
|
45
48
|
workerStartTimeout: number;
|
|
46
49
|
baseDir: string;
|
|
47
50
|
middleware: string[];
|
|
@@ -87,7 +90,7 @@ export interface EggAppConfig {
|
|
|
87
90
|
};
|
|
88
91
|
/** Default is `'error'`, it will return `400` response when `Prototype-Poisoning` happen. */
|
|
89
92
|
onProtoPoisoning: 'error' | 'remove' | 'ignore';
|
|
90
|
-
onerror(err: any, ctx:
|
|
93
|
+
onerror(err: any, ctx: Context): void;
|
|
91
94
|
};
|
|
92
95
|
/**
|
|
93
96
|
* logger options
|
|
@@ -117,43 +120,14 @@ export interface EggAppConfig {
|
|
|
117
120
|
timeout?: number;
|
|
118
121
|
/** Default request args for httpclient */
|
|
119
122
|
request?: HttpClientRequestOptions;
|
|
120
|
-
};
|
|
121
|
-
development: {
|
|
122
|
-
/**
|
|
123
|
-
* dirs needed watch, when files under these change, application will reload, use relative path
|
|
124
|
-
*/
|
|
125
|
-
watchDirs: string[];
|
|
126
|
-
/**
|
|
127
|
-
* dirs don't need watch, including subdirectories, use relative path
|
|
128
|
-
*/
|
|
129
|
-
ignoreDirs: string[];
|
|
130
|
-
/**
|
|
131
|
-
* don't wait all plugins ready, default is true.
|
|
132
|
-
*/
|
|
133
|
-
fastReady: boolean;
|
|
134
|
-
/**
|
|
135
|
-
* whether reload on debug, default is true.
|
|
136
|
-
*/
|
|
137
|
-
reloadOnDebug: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* whether override default watchDirs, default is false.
|
|
140
|
-
*/
|
|
141
|
-
overrideDefault: boolean;
|
|
142
|
-
/**
|
|
143
|
-
* whether override default ignoreDirs, default is false.
|
|
144
|
-
*/
|
|
145
|
-
overrideIgnore: boolean;
|
|
146
123
|
/**
|
|
147
|
-
*
|
|
124
|
+
* @deprecated keep compatible with egg 3.x, no more used
|
|
148
125
|
*/
|
|
149
|
-
|
|
126
|
+
useHttpClientNext?: boolean;
|
|
150
127
|
};
|
|
151
128
|
/**
|
|
152
129
|
* customLoader config
|
|
153
130
|
*/
|
|
154
|
-
customLoader: {
|
|
155
|
-
[key: string]: CustomLoaderConfig;
|
|
156
|
-
};
|
|
157
131
|
/**
|
|
158
132
|
* It will ignore special keys when dumpConfig
|
|
159
133
|
*/
|
|
@@ -267,7 +241,6 @@ export interface EggAppConfig {
|
|
|
267
241
|
enable: boolean;
|
|
268
242
|
allowedMethods: string[];
|
|
269
243
|
};
|
|
270
|
-
watcher: Record<string, any>;
|
|
271
244
|
onClientError?(err: Error, socket: Socket, app: EggApplicationCore): ClientErrorResponse | Promise<ClientErrorResponse>;
|
|
272
245
|
/**
|
|
273
246
|
* server timeout in milliseconds, default to 0 (no timeout).
|
|
@@ -290,4 +263,32 @@ export interface EggAppConfig {
|
|
|
290
263
|
};
|
|
291
264
|
[prop: string]: any;
|
|
292
265
|
}
|
|
293
|
-
export
|
|
266
|
+
export type RequestObjectBody = Record<string, any>;
|
|
267
|
+
/**
|
|
268
|
+
* plugin config item interface
|
|
269
|
+
*/
|
|
270
|
+
export interface IEggPluginItem {
|
|
271
|
+
env?: EggEnvType[];
|
|
272
|
+
path?: string;
|
|
273
|
+
package?: string;
|
|
274
|
+
enable?: boolean;
|
|
275
|
+
}
|
|
276
|
+
export type EggPluginItem = IEggPluginItem | boolean;
|
|
277
|
+
/**
|
|
278
|
+
* build-in plugin list
|
|
279
|
+
*/
|
|
280
|
+
export interface EggPlugin {
|
|
281
|
+
[key: string]: EggPluginItem | undefined;
|
|
282
|
+
onerror?: EggPluginItem;
|
|
283
|
+
session?: EggPluginItem;
|
|
284
|
+
i18n?: EggPluginItem;
|
|
285
|
+
watcher?: EggPluginItem;
|
|
286
|
+
multipart?: EggPluginItem;
|
|
287
|
+
security?: EggPluginItem;
|
|
288
|
+
development?: EggPluginItem;
|
|
289
|
+
logrotator?: EggPluginItem;
|
|
290
|
+
schedule?: EggPluginItem;
|
|
291
|
+
static?: EggPluginItem;
|
|
292
|
+
jsonp?: EggPluginItem;
|
|
293
|
+
view?: EggPluginItem;
|
|
294
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// import plugins types
|
|
2
|
+
import '@eggjs/watcher';
|
|
3
|
+
import '@eggjs/development';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWtCQSx1QkFBdUI7QUFDdkIsT0FBTyxnQkFBZ0IsQ0FBQztBQUN4QixPQUFPLG9CQUFvQixDQUFDIn0=
|
package/dist/esm/lib/utils.js
CHANGED
|
@@ -11,4 +11,4 @@ export function getSourceDirname() {
|
|
|
11
11
|
export function getSourceFile(filename) {
|
|
12
12
|
return path.join(getSourceDirname(), filename);
|
|
13
13
|
}
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUM3QixPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBRXpDLE1BQU0sVUFBVSxnQkFBZ0I7SUFDOUIsSUFBSSxPQUFPLFNBQVMsS0FBSyxXQUFXLEVBQUUsQ0FBQztRQUNyQyxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDakMsQ0FBQztJQUNELDZEQUE2RDtJQUM3RCxhQUFhO0lBQ2IsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3BFLENBQUM7QUFFRCxNQUFNLFVBQVUsYUFBYSxDQUFDLFFBQWdCO0lBQzVDLE9BQU8sSUFBSSxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsRUFBRSxFQUFFLFFBQVEsQ0FBQyxDQUFDO0FBQ2pELENBQUMifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'urllib';
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egg",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">= 18.19.0"
|
|
6
6
|
},
|
|
@@ -19,16 +19,15 @@
|
|
|
19
19
|
"egg"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@eggjs/cluster": "
|
|
22
|
+
"@eggjs/cluster": "^3.0.0",
|
|
23
23
|
"@eggjs/cookies": "^3.0.0",
|
|
24
|
-
"@eggjs/core": "
|
|
24
|
+
"@eggjs/core": "^6.2.13",
|
|
25
|
+
"@eggjs/development": "^4.0.0",
|
|
25
26
|
"@eggjs/schedule": "^5.0.2",
|
|
26
|
-
"@eggjs/utils": "^4.
|
|
27
|
-
"@eggjs/watcher": "^4.0.
|
|
27
|
+
"@eggjs/utils": "^4.2.4",
|
|
28
|
+
"@eggjs/watcher": "^4.0.3",
|
|
28
29
|
"circular-json-for-egg": "^1.0.0",
|
|
29
30
|
"cluster-client": "^3.7.0",
|
|
30
|
-
"delegates": "^1.0.0",
|
|
31
|
-
"egg-development": "^3.0.0",
|
|
32
31
|
"egg-errors": "^2.3.1",
|
|
33
32
|
"egg-i18n": "^2.1.1",
|
|
34
33
|
"egg-jsonp": "^2.0.0",
|
|
@@ -46,10 +45,10 @@
|
|
|
46
45
|
"is-type-of": "^2.1.0",
|
|
47
46
|
"koa-bodyparser": "^4.4.1",
|
|
48
47
|
"koa-override": "^4.0.0",
|
|
49
|
-
"onelogger": "^1.0.
|
|
48
|
+
"onelogger": "^1.0.1",
|
|
50
49
|
"performance-ms": "^1.1.0",
|
|
51
50
|
"sendmessage": "^3.0.1",
|
|
52
|
-
"urllib": "^4.
|
|
51
|
+
"urllib": "^4.6.11",
|
|
53
52
|
"utility": "^2.1.0",
|
|
54
53
|
"ylru": "^1.3.2"
|
|
55
54
|
},
|
|
@@ -57,18 +56,18 @@
|
|
|
57
56
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
58
57
|
"@eggjs/bin": "^7.0.0",
|
|
59
58
|
"@eggjs/koa": "^2.19.1",
|
|
60
|
-
"@eggjs/mock": "
|
|
59
|
+
"@eggjs/mock": "^6.0.5",
|
|
60
|
+
"@eggjs/supertest": "^8.1.1",
|
|
61
61
|
"@eggjs/tsconfig": "1",
|
|
62
|
-
"@types/delegates": "^1.0.3",
|
|
63
62
|
"@types/koa-bodyparser": "^4.3.12",
|
|
64
63
|
"@types/mocha": "^10.0.7",
|
|
65
64
|
"@types/ms": "^0.7.34",
|
|
66
65
|
"@types/node": "22",
|
|
67
|
-
"@types/supertest": "^6.0.2",
|
|
68
66
|
"address": "2",
|
|
69
67
|
"assert-file": "1",
|
|
70
68
|
"coffee": "5",
|
|
71
69
|
"cross-env": "7",
|
|
70
|
+
"dumi": "^2.4.17",
|
|
72
71
|
"egg-plugin-puml": "^2.4.0",
|
|
73
72
|
"egg-tracer": "^2.1.0",
|
|
74
73
|
"egg-view-nunjucks": "^2.3.0",
|
|
@@ -77,13 +76,13 @@
|
|
|
77
76
|
"formstream": "^1.5.1",
|
|
78
77
|
"koa-static": "^5.0.0",
|
|
79
78
|
"mm": "^3.4.0",
|
|
80
|
-
"pedding": "^
|
|
79
|
+
"pedding": "^2.0.1",
|
|
81
80
|
"prettier": "^2.7.1",
|
|
82
81
|
"rimraf": "6",
|
|
83
82
|
"runscript": "^2.0.1",
|
|
84
83
|
"sdk-base": "^4.2.1",
|
|
85
84
|
"spy": "^1.0.0",
|
|
86
|
-
"
|
|
85
|
+
"tsd": "^0.31.2",
|
|
87
86
|
"tshy": "^3.0.2",
|
|
88
87
|
"tshy-after": "1",
|
|
89
88
|
"typescript": "5"
|
|
@@ -98,11 +97,9 @@
|
|
|
98
97
|
"preci": "npm run clean && npm run lint",
|
|
99
98
|
"ci": "egg-bin cov",
|
|
100
99
|
"postci": "npm run prepublishOnly && npm run clean",
|
|
101
|
-
"prepublishOnly": "tshy && tshy-after && attw --pack",
|
|
102
|
-
"site:dev": "cross-env
|
|
103
|
-
"site:
|
|
104
|
-
"site:build": "cross-env NODE_OPTIONS=--openssl-legacy-provider APP_ROOT=./site dumi build",
|
|
105
|
-
"site:buildWithNode14-16": "cross-env APP_ROOT=./site dumi build",
|
|
100
|
+
"prepublishOnly": "tshy && tshy-after && attw --pack --profile node16",
|
|
101
|
+
"site:dev": "cross-env APP_ROOT=./site dumi dev",
|
|
102
|
+
"site:build": "cross-env APP_ROOT=./site dumi build",
|
|
106
103
|
"site:prettier": "prettier --config site/.prettierrc --ignore-path site/.prettierignore --write \"site/**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
|
107
104
|
"puml": "puml . --dest ./site"
|
|
108
105
|
},
|
|
@@ -131,6 +128,7 @@
|
|
|
131
128
|
"tshy": {
|
|
132
129
|
"exports": {
|
|
133
130
|
".": "./src/index.ts",
|
|
131
|
+
"./urllib": "./src/urllib.ts",
|
|
134
132
|
"./package.json": "./package.json"
|
|
135
133
|
}
|
|
136
134
|
},
|
|
@@ -145,6 +143,16 @@
|
|
|
145
143
|
"default": "./dist/commonjs/index.js"
|
|
146
144
|
}
|
|
147
145
|
},
|
|
146
|
+
"./urllib": {
|
|
147
|
+
"import": {
|
|
148
|
+
"types": "./dist/esm/urllib.d.ts",
|
|
149
|
+
"default": "./dist/esm/urllib.js"
|
|
150
|
+
},
|
|
151
|
+
"require": {
|
|
152
|
+
"types": "./dist/commonjs/urllib.d.ts",
|
|
153
|
+
"default": "./dist/commonjs/urllib.js"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
148
156
|
"./package.json": "./package.json"
|
|
149
157
|
},
|
|
150
158
|
"types": "./dist/commonjs/index.d.ts",
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import delegate from 'delegates';
|
|
2
1
|
import { assign } from 'utility';
|
|
3
2
|
import { now, diff } from 'performance-ms';
|
|
4
3
|
import {
|
|
5
4
|
utils, Context as EggCoreContext, Router,
|
|
6
|
-
type ContextDelegation as EggCoreContextDelegation,
|
|
7
5
|
} from '@eggjs/core';
|
|
8
6
|
import type { Cookies as ContextCookies } from '@eggjs/cookies';
|
|
9
|
-
import { EggLogger } from 'egg-logger';
|
|
7
|
+
import type { EggLogger } from 'egg-logger';
|
|
10
8
|
import type { Application } from '../../lib/application.js';
|
|
11
9
|
import type {
|
|
12
10
|
HttpClientRequestURL, HttpClientRequestOptions, HttpClient,
|
|
13
11
|
} from '../../lib/core/httpclient.js';
|
|
14
|
-
import type { ContextHttpClient } from '../../lib/core/context_httpclient.js';
|
|
15
12
|
import type { BaseContextClass } from '../../lib//core/base_context_class.js';
|
|
16
|
-
import Request from './request.js';
|
|
17
|
-
import Response from './response.js';
|
|
13
|
+
import type Request from './request.js';
|
|
14
|
+
import type Response from './response.js';
|
|
18
15
|
import type Helper from './helper.js';
|
|
19
16
|
|
|
20
17
|
import './context.types.js';
|
|
@@ -34,7 +31,9 @@ interface Cookies extends ContextCookies {
|
|
|
34
31
|
export default class Context extends EggCoreContext {
|
|
35
32
|
declare app: Application;
|
|
36
33
|
declare request: Request;
|
|
34
|
+
declare response: Response;
|
|
37
35
|
declare service: BaseContextClass;
|
|
36
|
+
declare proxy: any;
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* Request start time
|
|
@@ -61,19 +60,19 @@ export default class Context extends EggCoreContext {
|
|
|
61
60
|
/**
|
|
62
61
|
* Get a wrapper httpclient instance contain ctx in the hold request process
|
|
63
62
|
*
|
|
64
|
-
* @return {
|
|
63
|
+
* @return {HttpClient} the wrapper httpclient instance
|
|
65
64
|
*/
|
|
66
|
-
get httpclient():
|
|
65
|
+
get httpclient(): HttpClient {
|
|
67
66
|
if (!this[CONTEXT_HTTPCLIENT]) {
|
|
68
67
|
this[CONTEXT_HTTPCLIENT] = new this.app.ContextHttpClient(this as any);
|
|
69
68
|
}
|
|
70
|
-
return this[CONTEXT_HTTPCLIENT] as
|
|
69
|
+
return this[CONTEXT_HTTPCLIENT] as HttpClient;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
/**
|
|
74
73
|
* Alias to {@link Context#httpclient}
|
|
75
74
|
*/
|
|
76
|
-
get httpClient():
|
|
75
|
+
get httpClient(): HttpClient {
|
|
77
76
|
return this.httpclient;
|
|
78
77
|
}
|
|
79
78
|
|
|
@@ -231,7 +230,7 @@ export default class Context extends EggCoreContext {
|
|
|
231
230
|
* });
|
|
232
231
|
* ```
|
|
233
232
|
*/
|
|
234
|
-
runInBackground(scope: (ctx:
|
|
233
|
+
runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void {
|
|
235
234
|
// try to use custom function name first
|
|
236
235
|
if (!taskName) {
|
|
237
236
|
taskName = Reflect.get(scope, '_name') || scope.name || utils.getCalleeFromStack(true);
|
|
@@ -244,7 +243,7 @@ export default class Context extends EggCoreContext {
|
|
|
244
243
|
|
|
245
244
|
// let plugins or frameworks to reuse _runInBackground in some cases.
|
|
246
245
|
// e.g.: https://github.com/eggjs/egg-mock/pull/78
|
|
247
|
-
async _runInBackground(scope: (ctx:
|
|
246
|
+
async _runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string) {
|
|
248
247
|
const startTime = now();
|
|
249
248
|
try {
|
|
250
249
|
await scope(this as any);
|
|
@@ -258,46 +257,52 @@ export default class Context extends EggCoreContext {
|
|
|
258
257
|
this.app.emit('error', err, this);
|
|
259
258
|
}
|
|
260
259
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Context delegation.
|
|
265
|
-
*/
|
|
266
260
|
|
|
267
|
-
delegate(Context.prototype, 'request')
|
|
268
261
|
/**
|
|
269
262
|
* @member {Boolean} Context#acceptJSON
|
|
270
263
|
* @see Request#acceptJSON
|
|
271
264
|
* @since 1.0.0
|
|
272
265
|
*/
|
|
273
|
-
|
|
266
|
+
get acceptJSON(): boolean {
|
|
267
|
+
return this.request.acceptJSON;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
get query(): Record<string, string> {
|
|
271
|
+
return this.request.query;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
274
|
/**
|
|
275
275
|
* @member {Array} Context#queries
|
|
276
276
|
* @see Request#queries
|
|
277
277
|
* @since 1.0.0
|
|
278
278
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
* @since 1.0.0
|
|
284
|
-
*/
|
|
285
|
-
.getter('accept')
|
|
279
|
+
get queries(): Record<string, string[]> {
|
|
280
|
+
return this.request.queries;
|
|
281
|
+
}
|
|
282
|
+
|
|
286
283
|
/**
|
|
287
284
|
* @member {string} Context#ip
|
|
288
285
|
* @see Request#ip
|
|
289
286
|
* @since 1.0.0
|
|
290
287
|
*/
|
|
291
|
-
|
|
288
|
+
get ip(): string {
|
|
289
|
+
return this.request.ip;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
set ip(val: string) {
|
|
293
|
+
this.request.ip = val;
|
|
294
|
+
}
|
|
292
295
|
|
|
293
|
-
delegate(Context.prototype, 'response')
|
|
294
296
|
/**
|
|
295
297
|
* @member {Number} Context#realStatus
|
|
296
298
|
* @see Response#realStatus
|
|
297
299
|
* @since 1.0.0
|
|
298
300
|
*/
|
|
299
|
-
|
|
301
|
+
get realStatus(): number {
|
|
302
|
+
return this.response.realStatus;
|
|
303
|
+
}
|
|
300
304
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
305
|
+
set realStatus(val: number) {
|
|
306
|
+
this.response.realStatus = val;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Router,
|
|
3
3
|
} from '@eggjs/core';
|
|
4
|
+
import type { EggLogger } from 'egg-logger';
|
|
4
5
|
import type {
|
|
5
6
|
HttpClientRequestURL, HttpClientRequestOptions, HttpClient,
|
|
6
7
|
} from '../../lib/core/httpclient.js';
|
|
7
|
-
import type {
|
|
8
|
-
ContextHttpClient,
|
|
9
|
-
} from '../../lib/core/context_httpclient.js';
|
|
10
8
|
import type Helper from './helper.js';
|
|
11
|
-
import type { EggLogger } from 'egg-logger';
|
|
12
9
|
|
|
13
10
|
declare module '@eggjs/core' {
|
|
14
11
|
// add Context overrides types
|
|
@@ -17,8 +14,11 @@ declare module '@eggjs/core' {
|
|
|
17
14
|
get router(): Router;
|
|
18
15
|
set router(val: Router);
|
|
19
16
|
get helper(): Helper;
|
|
20
|
-
get httpclient():
|
|
21
|
-
get httpClient():
|
|
17
|
+
get httpclient(): HttpClient;
|
|
18
|
+
get httpClient(): HttpClient;
|
|
22
19
|
getLogger(name: string): EggLogger;
|
|
20
|
+
get logger(): EggLogger;
|
|
21
|
+
get coreLogger(): EggLogger;
|
|
22
|
+
get locals(): Record<string, any>;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import querystring from 'node:querystring';
|
|
2
2
|
import { Request as EggCoreRequest } from '@eggjs/core';
|
|
3
3
|
import type { Application } from '../../lib/application.js';
|
|
4
|
-
import type
|
|
4
|
+
import type Context from './context.js';
|
|
5
5
|
import Response from './response.js';
|
|
6
6
|
|
|
7
7
|
const QUERY_CACHE = Symbol('request query cache');
|
|
@@ -11,11 +11,18 @@ const HOST = Symbol('request host');
|
|
|
11
11
|
const IPS = Symbol('request ips');
|
|
12
12
|
const RE_ARRAY_KEY = /[^\[\]]+\[\]$/;
|
|
13
13
|
|
|
14
|
+
import './request.types.js';
|
|
15
|
+
|
|
14
16
|
export default class Request extends EggCoreRequest {
|
|
15
17
|
declare app: Application;
|
|
16
|
-
declare ctx:
|
|
18
|
+
declare ctx: Context;
|
|
17
19
|
declare response: Response;
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Request body, parsed from koa-bodyparser or egg-multipart
|
|
23
|
+
*/
|
|
24
|
+
declare body: any;
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* Parse the "Host" header field host
|
|
21
28
|
* and support X-Forwarded-Host when a
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { performance } from 'node:perf_hooks';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Context, Next } from '../../lib/egg.js';
|
|
7
7
|
|
|
8
8
|
export interface MetaMiddlewareOptions {
|
|
9
9
|
enable: boolean;
|
|
@@ -11,7 +11,7 @@ export interface MetaMiddlewareOptions {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export default (options: MetaMiddlewareOptions) => {
|
|
14
|
-
return async function meta(ctx:
|
|
14
|
+
return async function meta(ctx: Context, next: Next) {
|
|
15
15
|
if (options.logging) {
|
|
16
16
|
ctx.coreLogger.info('[meta] request started, host: %s, user-agent: %s',
|
|
17
17
|
ctx.host, ctx.header['user-agent']);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Next,
|
|
1
|
+
import type { Next, Context } from '../../lib/egg.js';
|
|
2
2
|
|
|
3
3
|
export interface NotFoundMiddlewareOptions {
|
|
4
4
|
enable: boolean;
|
|
@@ -6,7 +6,7 @@ export interface NotFoundMiddlewareOptions {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export default (options: NotFoundMiddlewareOptions) => {
|
|
9
|
-
return async function notfound(ctx:
|
|
9
|
+
return async function notfound(ctx: Context, next: Next) {
|
|
10
10
|
await next();
|
|
11
11
|
|
|
12
12
|
if (ctx.status !== 404 || ctx.body) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import type { Next,
|
|
4
|
+
import type { Next, Context } from '../../lib/egg.js';
|
|
5
5
|
|
|
6
|
-
export type SiteFileContentFun = (ctx:
|
|
6
|
+
export type SiteFileContentFun = (ctx: Context) => Promise<Buffer | string>;
|
|
7
7
|
|
|
8
8
|
export interface SiteFileMiddlewareOptions {
|
|
9
9
|
enable: boolean;
|
|
@@ -14,7 +14,7 @@ export interface SiteFileMiddlewareOptions {
|
|
|
14
14
|
const BUFFER_CACHE = Symbol('siteFile URL buffer cache');
|
|
15
15
|
|
|
16
16
|
export default (options: SiteFileMiddlewareOptions) => {
|
|
17
|
-
return async function siteFile(ctx:
|
|
17
|
+
return async function siteFile(ctx: Context, next: Next) {
|
|
18
18
|
if (ctx.method !== 'HEAD' && ctx.method !== 'GET') {
|
|
19
19
|
return next();
|
|
20
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import type { EggAppInfo } from '@eggjs/core';
|
|
4
|
-
import type { EggAppConfig } from '../lib/
|
|
4
|
+
import type { EggAppConfig } from '../lib/types.js';
|
|
5
5
|
import { getSourceFile } from '../lib/utils.js';
|
|
6
6
|
|
|
7
7
|
/**
|