egg 4.0.0-beta.9 → 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.
Files changed (150) hide show
  1. package/dist/commonjs/app/extend/context.d.ts +38 -11
  2. package/dist/commonjs/app/extend/context.js +25 -23
  3. package/dist/commonjs/app/extend/context.types.d.ts +6 -4
  4. package/dist/commonjs/app/extend/request.d.ts +7 -2
  5. package/dist/commonjs/app/extend/request.js +2 -1
  6. package/dist/commonjs/app/extend/request.types.d.ts +10 -0
  7. package/dist/commonjs/app/extend/request.types.js +3 -0
  8. package/dist/commonjs/app/extend/response.d.ts +1 -0
  9. package/dist/commonjs/app/extend/response.js +2 -1
  10. package/dist/commonjs/app/extend/response.types.d.ts +7 -0
  11. package/dist/commonjs/app/extend/response.types.js +3 -0
  12. package/dist/commonjs/app/middleware/meta.d.ts +2 -2
  13. package/dist/commonjs/app/middleware/meta.js +1 -1
  14. package/dist/commonjs/app/middleware/notfound.d.ts +2 -2
  15. package/dist/commonjs/app/middleware/notfound.js +1 -1
  16. package/dist/commonjs/app/middleware/site_file.d.ts +3 -3
  17. package/dist/commonjs/app/middleware/site_file.js +1 -1
  18. package/dist/commonjs/config/config.default.d.ts +1 -1
  19. package/dist/commonjs/config/plugin.js +2 -2
  20. package/dist/commonjs/index.d.ts +12 -7
  21. package/dist/commonjs/index.js +11 -22
  22. package/dist/commonjs/lib/application.d.ts +7 -3
  23. package/dist/commonjs/lib/application.js +15 -4
  24. package/dist/commonjs/lib/core/base_context_class.d.ts +6 -3
  25. package/dist/commonjs/lib/core/base_context_class.js +1 -2
  26. package/dist/commonjs/lib/core/base_hook_class.d.ts +2 -2
  27. package/dist/commonjs/lib/core/base_hook_class.js +1 -2
  28. package/dist/commonjs/lib/core/context_httpclient.d.ts +3 -3
  29. package/dist/commonjs/lib/core/context_httpclient.js +1 -1
  30. package/dist/commonjs/lib/core/httpclient.d.ts +4 -3
  31. package/dist/commonjs/lib/core/httpclient.js +1 -1
  32. package/dist/commonjs/lib/core/messenger/base.d.ts +8 -0
  33. package/dist/commonjs/lib/core/messenger/base.js +31 -0
  34. package/dist/commonjs/lib/core/messenger/index.js +3 -2
  35. package/dist/commonjs/lib/core/messenger/ipc.d.ts +2 -3
  36. package/dist/commonjs/lib/core/messenger/ipc.js +4 -6
  37. package/dist/commonjs/lib/core/messenger/local.d.ts +2 -3
  38. package/dist/commonjs/lib/core/messenger/local.js +4 -9
  39. package/dist/commonjs/lib/core/utils.d.ts +1 -1
  40. package/dist/commonjs/lib/core/utils.js +3 -3
  41. package/dist/commonjs/lib/egg.d.ts +17 -11
  42. package/dist/commonjs/lib/egg.js +13 -4
  43. package/dist/commonjs/lib/egg.types.d.ts +8 -1
  44. package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +5 -0
  45. package/dist/commonjs/lib/error/CookieLimitExceedError.js +16 -0
  46. package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +5 -0
  47. package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +16 -0
  48. package/dist/commonjs/lib/error/index.d.ts +2 -0
  49. package/dist/commonjs/lib/error/index.js +19 -0
  50. package/dist/commonjs/lib/start.d.ts +10 -1
  51. package/dist/commonjs/lib/start.js +1 -1
  52. package/dist/commonjs/lib/{type.d.ts → types.d.ts} +39 -38
  53. package/dist/commonjs/lib/types.js +6 -0
  54. package/dist/commonjs/lib/utils.js +1 -1
  55. package/dist/commonjs/urllib.d.ts +1 -0
  56. package/dist/commonjs/urllib.js +18 -0
  57. package/dist/esm/app/extend/context.d.ts +38 -11
  58. package/dist/esm/app/extend/context.js +24 -19
  59. package/dist/esm/app/extend/context.types.d.ts +6 -4
  60. package/dist/esm/app/extend/request.d.ts +7 -2
  61. package/dist/esm/app/extend/request.js +2 -1
  62. package/dist/esm/app/extend/request.types.d.ts +10 -0
  63. package/dist/esm/app/extend/request.types.js +2 -0
  64. package/dist/esm/app/extend/response.d.ts +1 -0
  65. package/dist/esm/app/extend/response.js +2 -1
  66. package/dist/esm/app/extend/response.types.d.ts +7 -0
  67. package/dist/esm/app/extend/response.types.js +2 -0
  68. package/dist/esm/app/middleware/meta.d.ts +2 -2
  69. package/dist/esm/app/middleware/meta.js +1 -1
  70. package/dist/esm/app/middleware/notfound.d.ts +2 -2
  71. package/dist/esm/app/middleware/notfound.js +1 -1
  72. package/dist/esm/app/middleware/site_file.d.ts +3 -3
  73. package/dist/esm/app/middleware/site_file.js +1 -1
  74. package/dist/esm/config/config.default.d.ts +1 -1
  75. package/dist/esm/config/plugin.js +2 -2
  76. package/dist/esm/index.d.ts +12 -7
  77. package/dist/esm/index.js +13 -8
  78. package/dist/esm/lib/application.d.ts +7 -3
  79. package/dist/esm/lib/application.js +15 -4
  80. package/dist/esm/lib/core/base_context_class.d.ts +6 -3
  81. package/dist/esm/lib/core/base_context_class.js +1 -2
  82. package/dist/esm/lib/core/base_hook_class.d.ts +2 -2
  83. package/dist/esm/lib/core/base_hook_class.js +1 -2
  84. package/dist/esm/lib/core/context_httpclient.d.ts +3 -3
  85. package/dist/esm/lib/core/context_httpclient.js +1 -1
  86. package/dist/esm/lib/core/httpclient.d.ts +4 -3
  87. package/dist/esm/lib/core/httpclient.js +1 -1
  88. package/dist/esm/lib/core/messenger/base.d.ts +8 -0
  89. package/dist/esm/lib/core/messenger/base.js +27 -0
  90. package/dist/esm/lib/core/messenger/index.js +3 -2
  91. package/dist/esm/lib/core/messenger/ipc.d.ts +2 -3
  92. package/dist/esm/lib/core/messenger/ipc.js +4 -6
  93. package/dist/esm/lib/core/messenger/local.d.ts +2 -3
  94. package/dist/esm/lib/core/messenger/local.js +4 -6
  95. package/dist/esm/lib/core/utils.d.ts +1 -1
  96. package/dist/esm/lib/core/utils.js +3 -3
  97. package/dist/esm/lib/egg.d.ts +17 -11
  98. package/dist/esm/lib/egg.js +15 -5
  99. package/dist/esm/lib/egg.types.d.ts +8 -1
  100. package/dist/esm/lib/error/CookieLimitExceedError.d.ts +5 -0
  101. package/dist/esm/lib/error/CookieLimitExceedError.js +12 -0
  102. package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +5 -0
  103. package/dist/esm/lib/error/MessageUnhandledRejectionError.js +12 -0
  104. package/dist/esm/lib/error/index.d.ts +2 -0
  105. package/dist/esm/lib/error/index.js +3 -0
  106. package/dist/esm/lib/start.d.ts +10 -1
  107. package/dist/esm/lib/start.js +1 -1
  108. package/dist/esm/lib/{type.d.ts → types.d.ts} +39 -38
  109. package/dist/esm/lib/types.js +4 -0
  110. package/dist/esm/lib/utils.js +1 -1
  111. package/dist/esm/urllib.d.ts +1 -0
  112. package/dist/esm/urllib.js +2 -0
  113. package/dist/package.json +1 -1
  114. package/package.json +27 -19
  115. package/src/app/extend/context.ts +37 -32
  116. package/src/app/extend/context.types.ts +6 -6
  117. package/src/app/extend/request.ts +9 -2
  118. package/src/app/extend/request.types.ts +10 -0
  119. package/src/app/extend/response.ts +2 -0
  120. package/src/app/extend/response.types.ts +7 -0
  121. package/src/app/middleware/meta.ts +2 -2
  122. package/src/app/middleware/notfound.ts +2 -2
  123. package/src/app/middleware/site_file.ts +3 -3
  124. package/src/config/config.default.ts +1 -1
  125. package/src/config/config.local.ts +1 -1
  126. package/src/config/config.unittest.ts +1 -1
  127. package/src/config/plugin.ts +1 -1
  128. package/src/index.ts +40 -7
  129. package/src/lib/agent.ts +1 -1
  130. package/src/lib/application.ts +18 -6
  131. package/src/lib/core/base_context_class.ts +6 -3
  132. package/src/lib/core/base_hook_class.ts +2 -2
  133. package/src/lib/core/context_httpclient.ts +3 -3
  134. package/src/lib/core/httpclient.ts +10 -4
  135. package/src/lib/core/messenger/base.ts +30 -0
  136. package/src/lib/core/messenger/index.ts +2 -1
  137. package/src/lib/core/messenger/ipc.ts +3 -5
  138. package/src/lib/core/messenger/local.ts +3 -5
  139. package/src/lib/core/utils.ts +2 -2
  140. package/src/lib/egg.ts +29 -18
  141. package/src/lib/egg.types.ts +9 -0
  142. package/src/lib/error/CookieLimitExceedError.ts +12 -0
  143. package/src/lib/error/MessageUnhandledRejectionError.ts +12 -0
  144. package/src/lib/error/index.ts +2 -0
  145. package/src/lib/start.ts +12 -2
  146. package/src/lib/{type.ts → types.ts} +83 -40
  147. package/src/lib/utils.ts +0 -1
  148. package/src/urllib.ts +1 -0
  149. package/dist/commonjs/lib/type.js +0 -3
  150. 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, ContextDelegation } from './egg.js';
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
- type IgnoreItem = string | RegExp | ((ctx: ContextDelegation) => boolean);
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: ContextDelegation): void;
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
- * whether to reload, use https://github.com/sindresorhus/multimatch
124
+ * @deprecated keep compatible with egg 3.x, no more used
148
125
  */
149
- reloadPattern: string[] | string;
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=
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUM3QixPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBRXpDLE1BQU0sVUFBVSxnQkFBZ0I7SUFDOUIsSUFBSSxPQUFPLFNBQVMsS0FBSyxXQUFXLEVBQUUsQ0FBQztRQUNyQyxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDakMsQ0FBQztJQUNELDZEQUE2RDtJQUM3RCxhQUFhO0lBQ2IsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3BFLENBQUM7QUFFRCxNQUFNLFVBQVUsYUFBYSxDQUFDLFFBQWdCO0lBQzVDLE9BQU8sSUFBSSxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsRUFBRSxFQUFFLFFBQVEsQ0FBQyxDQUFDO0FBQ2pELENBQUMifQ==
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUM3QixPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBRXpDLE1BQU0sVUFBVSxnQkFBZ0I7SUFDOUIsSUFBSSxPQUFPLFNBQVMsS0FBSyxXQUFXLEVBQUUsQ0FBQztRQUNyQyxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDakMsQ0FBQztJQUNELDZEQUE2RDtJQUM3RCxhQUFhO0lBQ2IsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3BFLENBQUM7QUFFRCxNQUFNLFVBQVUsYUFBYSxDQUFDLFFBQWdCO0lBQzVDLE9BQU8sSUFBSSxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsRUFBRSxFQUFFLFFBQVEsQ0FBQyxDQUFDO0FBQ2pELENBQUMifQ==
@@ -0,0 +1 @@
1
+ export * from 'urllib';
@@ -0,0 +1,2 @@
1
+ export * from 'urllib';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXJsbGliLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3VybGxpYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLFFBQVEsQ0FBQyJ9
package/dist/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "4.0.0-beta.9"
3
+ "version": "4.0.0"
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "4.0.0-beta.9",
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": "beta",
22
+ "@eggjs/cluster": "^3.0.0",
23
23
  "@eggjs/cookies": "^3.0.0",
24
- "@eggjs/core": "^6.2.5",
24
+ "@eggjs/core": "^6.2.13",
25
+ "@eggjs/development": "^4.0.0",
25
26
  "@eggjs/schedule": "^5.0.2",
26
- "@eggjs/utils": "^4.1.5",
27
- "@eggjs/watcher": "^4.0.1",
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.0",
48
+ "onelogger": "^1.0.1",
50
49
  "performance-ms": "^1.1.0",
51
50
  "sendmessage": "^3.0.1",
52
- "urllib": "^4.0.0",
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": "beta",
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": "^1.1.0",
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
- "supertest": "^7.0.0",
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 NODE_OPTIONS=--openssl-legacy-provider APP_ROOT=./site dumi dev",
103
- "site:devWithNode14-16": "cross-env APP_ROOT=./site dumi dev",
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 {ContextHttpClient} the wrapper httpclient instance
63
+ * @return {HttpClient} the wrapper httpclient instance
65
64
  */
66
- get httpclient(): ContextHttpClient {
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 ContextHttpClient;
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(): ContextHttpClient {
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: ContextDelegation) => Promise<void>, taskName?: string): void {
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: ContextDelegation) => Promise<void>, taskName: string) {
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
- .getter('acceptJSON')
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
- .getter('queries')
280
- /**
281
- * @member {Boolean} Context#accept
282
- * @see Request#accept
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
- .access('ip');
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
- .access('realStatus');
301
+ get realStatus(): number {
302
+ return this.response.realStatus;
303
+ }
300
304
 
301
- export type ContextDelegation = EggCoreContextDelegation & Context
302
- & Pick<Request, 'acceptJSON' | 'queries' | 'accept' | 'ip'>
303
- & Pick<Response, 'realStatus'>;
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(): ContextHttpClient;
21
- get httpClient(): ContextHttpClient;
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 { ContextDelegation } from './context.js';
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: ContextDelegation;
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
@@ -0,0 +1,10 @@
1
+ declare module '@eggjs/core' {
2
+ // add Request overrides types
3
+ interface Request {
4
+ body: any;
5
+ get acceptJSON(): boolean;
6
+ get query(): Record<string, string>;
7
+ set query(obj: Record<string, string>);
8
+ get queries(): Record<string, string[]>;
9
+ }
10
+ }
@@ -2,6 +2,8 @@ import { Response as KoaResponse } from '@eggjs/core';
2
2
 
3
3
  const REAL_STATUS = Symbol('response realStatus');
4
4
 
5
+ import './response.types.js';
6
+
5
7
  export default class Response extends KoaResponse {
6
8
  /**
7
9
  * Get or set a real status code.
@@ -0,0 +1,7 @@
1
+ declare module '@eggjs/core' {
2
+ // add Response overrides types
3
+ interface Response {
4
+ get realStatus(): number;
5
+ set realStatus(status: number);
6
+ }
7
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { performance } from 'node:perf_hooks';
6
- import type { ContextDelegation, Next } from '../../lib/egg.js';
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: ContextDelegation, next: Next) {
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, ContextDelegation } from '../../lib/egg.js';
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: ContextDelegation, next: Next) {
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, ContextDelegation } from '../../lib/egg.js';
4
+ import type { Next, Context } from '../../lib/egg.js';
5
5
 
6
- export type SiteFileContentFun = (ctx: ContextDelegation) => Promise<Buffer | string>;
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: ContextDelegation, next: Next) {
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/type.js';
4
+ import type { EggAppConfig } from '../lib/types.js';
5
5
  import { getSourceFile } from '../lib/utils.js';
6
6
 
7
7
  /**
@@ -1,4 +1,4 @@
1
- import type { EggAppConfig } from '../lib/type.js';
1
+ import type { EggAppConfig } from '../lib/types.js';
2
2
 
3
3
  export default () => {
4
4
  return {
@@ -1,4 +1,4 @@
1
- import type { EggAppConfig } from '../lib/type.js';
1
+ import type { EggAppConfig } from '../lib/types.js';
2
2
 
3
3
  export default () => {
4
4
  return {
@@ -74,7 +74,7 @@ export default {
74
74
  */
75
75
  development: {
76
76
  enable: true,
77
- package: 'egg-development',
77
+ package: '@eggjs/development',
78
78
  },
79
79
 
80
80
  /**