egg 3.0.0 → 3.2.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/README.md CHANGED
@@ -32,7 +32,7 @@ $ npm run dev
32
32
  $ open http://localhost:7001
33
33
  ```
34
34
 
35
- > Node.js >= 8.5.0 required.
35
+ > Node.js >= 14.20.0 required.
36
36
 
37
37
  ## Documentations
38
38
 
package/README.zh-CN.md CHANGED
@@ -18,7 +18,7 @@
18
18
  - 深度框架定制
19
19
  - 丰富的[插件](https://github.com/search?q=topic%3Aegg-plugin&type=Repositories)
20
20
 
21
- > 支持 Node.js 8.5.x 及以上版本。
21
+ > 支持 Node.js 14.20.0 及以上版本。
22
22
 
23
23
  ## 快速开始
24
24
 
@@ -290,6 +290,7 @@ module.exports = appInfo => {
290
290
  * @property {Number} httpsAgent.freeSocketTimeout - httpss agent socket keepalive max free time, default is 4000 ms.
291
291
  * @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
292
292
  * @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
293
+ * @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
293
294
  */
294
295
  config.httpclient = {
295
296
  enableDNSCache: false,
@@ -311,6 +312,7 @@ module.exports = appInfo => {
311
312
  maxSockets: Number.MAX_SAFE_INTEGER,
312
313
  maxFreeSockets: 256,
313
314
  },
315
+ useHttpClientNext: false,
314
316
  };
315
317
 
316
318
  /**
package/index.d.ts CHANGED
@@ -270,6 +270,8 @@ declare module 'egg' {
270
270
  dnsCacheLookupInterval?: number;
271
271
  /** DNS cache max age */
272
272
  dnsCacheMaxLength?: number;
273
+ /** use urllib@3 HttpClient */
274
+ useHttpClientNext?: boolean;
273
275
  }
274
276
 
275
277
  export interface EggAppConfig {
package/lib/agent.js CHANGED
@@ -10,7 +10,7 @@ const EGG_PATH = Symbol.for('egg#eggPath');
10
10
 
11
11
  /**
12
12
  * Singleton instance in Agent Worker, extend {@link EggApplication}
13
- * @extends EggApplication
13
+ * @augments EggApplication
14
14
  */
15
15
  class Agent extends EggApplication {
16
16
  /**
@@ -47,7 +47,7 @@ function escapeHeaderValue(value) {
47
47
  // Refs: https://github.com/nodejs/node/blob/b38c81/lib/_http_outgoing.js#L706-L710
48
48
  /**
49
49
  * Singleton instance in App Worker, extend {@link EggApplication}
50
- * @extends EggApplication
50
+ * @augments EggApplication
51
51
  */
52
52
  class Application extends EggApplication {
53
53
 
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const { HttpClient } = require('urllib-next');
4
+ const ms = require('humanize-ms');
5
+
6
+ class HttpClientNext extends HttpClient {
7
+ constructor(app) {
8
+ normalizeConfig(app);
9
+ const config = app.config.httpclient;
10
+ super({
11
+ app,
12
+ defaultArgs: config.request,
13
+ });
14
+ this.app = app;
15
+ }
16
+
17
+ async request(url, options) {
18
+ options = options || {};
19
+ if (options.ctx && options.ctx.tracer) {
20
+ options.tracer = options.ctx.tracer;
21
+ } else {
22
+ options.tracer = options.tracer || this.app.tracer;
23
+ }
24
+ return await super.request(url, options);
25
+ }
26
+
27
+ async curl(...args) {
28
+ return await this.request(...args);
29
+ }
30
+ }
31
+
32
+ function normalizeConfig(app) {
33
+ const config = app.config.httpclient;
34
+ if (typeof config.request.timeout === 'string') {
35
+ config.request.timeout = ms(config.request.timeout);
36
+ }
37
+ }
38
+
39
+ module.exports = HttpClientNext;
@@ -123,7 +123,7 @@ class Messenger extends EventEmitter {
123
123
  }
124
124
 
125
125
  /**
126
- * @method Messenger#on
126
+ * @function Messenger#on
127
127
  * @param {String} action - message key
128
128
  * @param {Object} data - message value
129
129
  */
@@ -132,7 +132,7 @@ class Messenger extends EventEmitter {
132
132
  }
133
133
 
134
134
  /**
135
- * @method Messenger#on
135
+ * @function Messenger#on
136
136
  * @param {String} action - message key
137
137
  * @param {Object} data - message value
138
138
  */
package/lib/egg.js CHANGED
@@ -15,6 +15,7 @@ const ContextHttpClient = require('./core/context_httpclient');
15
15
  const Messenger = require('./core/messenger');
16
16
  const DNSCacheHttpClient = require('./core/dnscache_httpclient');
17
17
  const HttpClient = require('./core/httpclient');
18
+ const HttpClientNext = require('./core/httpclient_next');
18
19
  const createLoggers = require('./core/logger');
19
20
  const Singleton = require('./core/singleton');
20
21
  const utils = require('./core/utils');
@@ -30,7 +31,7 @@ const CLUSTER_CLIENTS = Symbol.for('egg#clusterClients');
30
31
  * Base on koa's Application
31
32
  * @see https://github.com/eggjs/egg-core
32
33
  * @see http://koajs.com/#application
33
- * @extends EggCore
34
+ * @augments EggCore
34
35
  */
35
36
  class EggApplication extends EggCore {
36
37
 
@@ -291,7 +292,9 @@ class EggApplication extends EggCore {
291
292
  */
292
293
  get httpclient() {
293
294
  if (!this[HTTPCLIENT]) {
294
- if (this.config.httpclient.enableDNSCache) {
295
+ if (this.config.httpclient.useHttpClientNext) {
296
+ this[HTTPCLIENT] = new HttpClientNext(this);
297
+ } else if (this.config.httpclient.enableDNSCache) {
295
298
  this[HTTPCLIENT] = new DNSCacheHttpClient(this);
296
299
  } else {
297
300
  this[HTTPCLIENT] = new this.HttpClient(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "A web framework's framework for Node.js",
5
5
  "keywords": [
6
6
  "web",
@@ -14,83 +14,84 @@
14
14
  ],
15
15
  "dependencies": {
16
16
  "@types/accepts": "^1.3.5",
17
- "@types/koa": "^2.0.48",
18
- "@types/koa-router": "^7.0.40",
19
- "accepts": "^1.3.5",
20
- "agentkeepalive": "^4.0.2",
17
+ "@types/koa": "^2.13.5",
18
+ "@types/koa-router": "^7.4.4",
19
+ "accepts": "^1.3.8",
20
+ "agentkeepalive": "^4.2.1",
21
21
  "cache-content-type": "^1.0.1",
22
22
  "circular-json-for-egg": "^1.0.0",
23
- "cluster-client": "^3.0.1",
24
- "debug": "^4.1.1",
23
+ "cluster-client": "^3.1.1",
24
+ "debug": "^4.3.4",
25
25
  "delegates": "^1.0.0",
26
- "egg-cluster": "^1.23.0",
27
- "egg-cookies": "^2.3.0",
28
- "egg-core": "^4.18.0",
29
- "egg-development": "^2.4.2",
30
- "egg-errors": "^2.3.0",
31
- "egg-i18n": "^2.0.0",
26
+ "egg-cluster": "^1.27.1",
27
+ "egg-cookies": "^2.6.1",
28
+ "egg-core": "^4.26.1",
29
+ "egg-development": "^2.7.0",
30
+ "egg-errors": "^2.3.1",
31
+ "egg-i18n": "^2.1.1",
32
32
  "egg-jsonp": "^2.0.0",
33
- "egg-logger": "^2.3.2",
34
- "egg-logrotator": "^3.0.5",
35
- "egg-multipart": "^2.4.0",
36
- "egg-onerror": "^2.1.0",
37
- "egg-schedule": "^3.6.0",
38
- "egg-security": "^2.4.3",
39
- "egg-session": "^3.1.0",
33
+ "egg-logger": "^2.9.0",
34
+ "egg-logrotator": "^3.1.0",
35
+ "egg-multipart": "^3.0.0",
36
+ "egg-onerror": "^2.1.1",
37
+ "egg-schedule": "^3.7.0",
38
+ "egg-security": "^2.11.0",
39
+ "egg-session": "^3.3.0",
40
40
  "egg-static": "^2.2.0",
41
- "egg-view": "^2.1.2",
42
- "egg-watcher": "^3.1.0",
43
- "extend2": "^1.0.0",
41
+ "egg-view": "^2.1.3",
42
+ "egg-watcher": "^3.1.1",
43
+ "extend2": "^1.0.1",
44
44
  "graceful": "^1.0.2",
45
45
  "humanize-ms": "^1.2.1",
46
46
  "is-type-of": "^1.2.1",
47
- "koa-bodyparser": "^4.2.1",
47
+ "koa-bodyparser": "^4.3.0",
48
48
  "koa-is-json": "^1.0.0",
49
49
  "koa-override": "^3.0.0",
50
- "ms": "^2.1.1",
50
+ "ms": "^2.1.3",
51
51
  "mz": "^2.7.0",
52
- "on-finished": "^2.3.0",
53
- "semver": "^7.3.2",
52
+ "on-finished": "^2.4.1",
53
+ "semver": "^7.3.7",
54
54
  "sendmessage": "^1.1.0",
55
55
  "urllib": "^2.33.0",
56
- "utility": "^1.15.0",
57
- "ylru": "^1.2.1"
56
+ "urllib-next": "^3.1.3",
57
+ "utility": "^1.17.0",
58
+ "ylru": "^1.3.2"
58
59
  },
59
60
  "devDependencies": {
60
- "@umijs/preset-react": "^2.1.2",
61
- "address": "^1.0.3",
62
- "antd": "^4.18.6",
61
+ "@umijs/preset-react": "^2.1.6",
62
+ "address": "^1.2.1",
63
+ "antd": "^4.23.2",
63
64
  "assert-extends": "^1.0.1",
64
65
  "assert-file": "^1.0.0",
65
- "autod": "^3.0.1",
66
+ "autod": "^3.1.2",
66
67
  "autod-egg": "^1.1.0",
67
- "coffee": "^5.2.1",
68
- "dumi": "^1.1.38",
69
- "dumi-theme-egg": "^1.2.0",
70
- "egg-alinode": "^1.0.3",
71
- "egg-bin": "^4.12.3",
68
+ "coffee": "^5.4.0",
69
+ "dumi": "^1.1.47",
70
+ "dumi-theme-egg": "^1.2.2",
71
+ "egg-alinode": "^2.0.1",
72
+ "egg-bin": "^5",
72
73
  "egg-doctools": "^2.9.1",
73
- "egg-mock": "^3.21.0",
74
+ "egg-mock": "^4.2.1",
74
75
  "egg-plugin-puml": "^2.4.0",
75
76
  "egg-tracer": "^1.1.0",
76
- "egg-view-nunjucks": "^2.2.0",
77
- "eslint": "^5.15.1",
78
- "eslint-config-egg": "^7.1.0",
77
+ "egg-view-nunjucks": "^2.3.0",
78
+ "eslint": "^8.23.1",
79
+ "eslint-config-egg": "^12.0.0",
79
80
  "findlinks": "^2.1.0",
80
- "formstream": "^1.1.0",
81
- "glob": "^7.1.3",
82
- "jsdoc": "^3.6.10",
83
- "koa": "^2.11.0",
84
- "koa-static": "^3.0.0",
81
+ "formstream": "^1.1.1",
82
+ "glob": "^8",
83
+ "jsdoc": "^3.6.11",
84
+ "koa": "^2.13.4",
85
+ "koa-static": "^5.0.0",
85
86
  "mz": "^2.7.0",
86
87
  "mz-modules": "^2.1.0",
87
88
  "pedding": "^1.1.0",
88
- "prettier": "^2.5.1",
89
- "runscript": "^1.3.0",
89
+ "prettier": "^2.7.1",
90
+ "runscript": "^1.5.3",
90
91
  "spy": "^1.0.0",
91
- "supertest": "^3.4.2",
92
- "ts-node": "^8.0.3",
93
- "typescript": "^3.3.3333"
92
+ "supertest": "^6.2.4",
93
+ "ts-node": "^10.9.1",
94
+ "typescript": "^4.8.3"
94
95
  },
95
96
  "main": "index.js",
96
97
  "types": "index.d.ts",