egg 4.0.0 → 4.0.1
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 +14 -1
- package/dist/commonjs/app/extend/context.js +1 -2
- package/dist/commonjs/app/extend/request.d.ts +9 -1
- package/dist/commonjs/app/extend/request.js +1 -2
- package/dist/commonjs/app/extend/response.d.ts +6 -1
- package/dist/commonjs/app/extend/response.js +1 -2
- package/dist/commonjs/config/plugin.js +4 -5
- package/dist/commonjs/lib/core/httpclient.d.ts +3 -3
- package/dist/commonjs/lib/core/httpclient.js +10 -5
- package/dist/commonjs/lib/egg.d.ts +20 -2
- package/dist/commonjs/lib/egg.js +9 -3
- package/dist/commonjs/lib/types.d.ts +14 -49
- package/dist/commonjs/lib/types.js +4 -1
- package/dist/esm/app/extend/context.d.ts +14 -1
- package/dist/esm/app/extend/context.js +1 -2
- package/dist/esm/app/extend/request.d.ts +9 -1
- package/dist/esm/app/extend/request.js +1 -2
- package/dist/esm/app/extend/response.d.ts +6 -1
- package/dist/esm/app/extend/response.js +1 -2
- package/dist/esm/config/plugin.js +4 -5
- package/dist/esm/lib/core/httpclient.d.ts +3 -3
- package/dist/esm/lib/core/httpclient.js +10 -5
- package/dist/esm/lib/egg.d.ts +20 -2
- package/dist/esm/lib/egg.js +9 -3
- package/dist/esm/lib/types.d.ts +14 -49
- package/dist/esm/lib/types.js +4 -1
- package/dist/package.json +1 -1
- package/package.json +4 -4
- package/src/app/extend/context.ts +16 -2
- package/src/app/extend/request.ts +11 -2
- package/src/app/extend/response.ts +8 -2
- package/src/config/plugin.ts +3 -5
- package/src/lib/core/httpclient.ts +11 -4
- package/src/lib/egg.ts +29 -5
- package/src/lib/types.ts +15 -82
- package/dist/commonjs/app/extend/context.types.d.ts +0 -18
- package/dist/commonjs/app/extend/context.types.js +0 -3
- package/dist/commonjs/app/extend/request.types.d.ts +0 -10
- package/dist/commonjs/app/extend/request.types.js +0 -3
- package/dist/commonjs/app/extend/response.types.d.ts +0 -7
- package/dist/commonjs/app/extend/response.types.js +0 -3
- package/dist/commonjs/lib/egg.types.d.ts +0 -13
- package/dist/commonjs/lib/egg.types.js +0 -3
- package/dist/esm/app/extend/context.types.d.ts +0 -18
- package/dist/esm/app/extend/context.types.js +0 -2
- package/dist/esm/app/extend/request.types.d.ts +0 -10
- package/dist/esm/app/extend/request.types.js +0 -2
- package/dist/esm/app/extend/response.types.d.ts +0 -7
- package/dist/esm/app/extend/response.types.js +0 -2
- package/dist/esm/lib/egg.types.d.ts +0 -13
- package/dist/esm/lib/egg.types.js +0 -2
- package/src/app/extend/context.types.ts +0 -24
- package/src/app/extend/request.types.ts +0 -10
- package/src/app/extend/response.types.ts +0 -7
- package/src/lib/egg.types.ts +0 -15
package/src/lib/egg.ts
CHANGED
|
@@ -31,7 +31,9 @@ import type { EggAppConfig } from './types.js';
|
|
|
31
31
|
import { create as createMessenger, IMessenger } from './core/messenger/index.js';
|
|
32
32
|
import { ContextHttpClient } from './core/context_httpclient.js';
|
|
33
33
|
import {
|
|
34
|
-
HttpClient,
|
|
34
|
+
HttpClient,
|
|
35
|
+
type HttpClientRequestOptions, type HttpClientRequestURL, type HttpClientResponse,
|
|
36
|
+
type HttpClientOptions,
|
|
35
37
|
} from './core/httpclient.js';
|
|
36
38
|
import { createLoggers } from './core/logger.js';
|
|
37
39
|
import {
|
|
@@ -43,8 +45,6 @@ import { BaseHookClass } from './core/base_hook_class.js';
|
|
|
43
45
|
import type { EggApplicationLoader } from './loader/index.js';
|
|
44
46
|
import { getSourceDirname } from './utils.js';
|
|
45
47
|
|
|
46
|
-
import './egg.types.js';
|
|
47
|
-
|
|
48
48
|
const EGG_PATH = Symbol.for('egg#eggPath');
|
|
49
49
|
|
|
50
50
|
export interface EggApplicationCoreOptions extends Omit<EggCoreOptions, 'baseDir'> {
|
|
@@ -387,14 +387,22 @@ export class EggApplicationCore extends EggCore {
|
|
|
387
387
|
return await this.httpClient.request<T>(url, options);
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Create a new HttpClient instance with custom options
|
|
392
|
+
* @param {Object} [options] HttpClient init options
|
|
393
|
+
*/
|
|
394
|
+
createHttpClient(options?: HttpClientOptions): HttpClient {
|
|
395
|
+
return new this.HttpClient(this, options);
|
|
396
|
+
}
|
|
397
|
+
|
|
390
398
|
/**
|
|
391
399
|
* HttpClient instance
|
|
392
400
|
* @see https://github.com/node-modules/urllib
|
|
393
401
|
* @member {HttpClient}
|
|
394
402
|
*/
|
|
395
|
-
get httpClient() {
|
|
403
|
+
get httpClient(): HttpClient {
|
|
396
404
|
if (!this.#httpClient) {
|
|
397
|
-
this.#httpClient =
|
|
405
|
+
this.#httpClient = this.createHttpClient();
|
|
398
406
|
}
|
|
399
407
|
return this.#httpClient;
|
|
400
408
|
}
|
|
@@ -680,3 +688,19 @@ export class EggApplicationCore extends EggCore {
|
|
|
680
688
|
return context;
|
|
681
689
|
}
|
|
682
690
|
}
|
|
691
|
+
|
|
692
|
+
declare module '@eggjs/core' {
|
|
693
|
+
// add EggApplicationCore overrides types
|
|
694
|
+
interface EggCore {
|
|
695
|
+
inspect(): any;
|
|
696
|
+
get currentContext(): EggContext | undefined;
|
|
697
|
+
ctxStorage: AsyncLocalStorage<EggContext>;
|
|
698
|
+
get logger(): EggLogger;
|
|
699
|
+
get coreLogger(): EggLogger;
|
|
700
|
+
getLogger(name: string): EggLogger;
|
|
701
|
+
createHttpClient(options?: HttpClientOptions): HttpClient;
|
|
702
|
+
HttpClient: typeof HttpClient;
|
|
703
|
+
get httpClient(): HttpClient;
|
|
704
|
+
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<HttpClientResponse<T>>;
|
|
705
|
+
}
|
|
706
|
+
}
|
package/src/lib/types.ts
CHANGED
|
@@ -19,6 +19,9 @@ import type { SiteFileMiddlewareOptions } from '../app/middleware/site_file.js';
|
|
|
19
19
|
// import plugins types
|
|
20
20
|
import '@eggjs/watcher';
|
|
21
21
|
import '@eggjs/development';
|
|
22
|
+
import '@eggjs/jsonp';
|
|
23
|
+
import '@eggjs/i18n';
|
|
24
|
+
import '@eggjs/static';
|
|
22
25
|
|
|
23
26
|
export type {
|
|
24
27
|
EggAppInfo,
|
|
@@ -63,6 +66,17 @@ export interface CustomLoaderConfig extends Omit<FileLoaderOptions, 'inject' | '
|
|
|
63
66
|
loadunit?: boolean;
|
|
64
67
|
}
|
|
65
68
|
|
|
69
|
+
export interface HttpClientConfig {
|
|
70
|
+
/** Request timeout */
|
|
71
|
+
timeout?: number;
|
|
72
|
+
/** Default request args for httpclient */
|
|
73
|
+
request?: HttpClientRequestOptions;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated keep compatible with egg 3.x, no more used
|
|
76
|
+
*/
|
|
77
|
+
useHttpClientNext?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
66
80
|
export interface EggAppConfig extends EggCoreAppConfig {
|
|
67
81
|
workerStartTimeout: number;
|
|
68
82
|
baseDir: string;
|
|
@@ -138,47 +152,7 @@ export interface EggAppConfig extends EggCoreAppConfig {
|
|
|
138
152
|
};
|
|
139
153
|
|
|
140
154
|
/** Configuration of httpclient in egg. */
|
|
141
|
-
httpclient:
|
|
142
|
-
/** Request timeout */
|
|
143
|
-
timeout?: number;
|
|
144
|
-
/** Default request args for httpclient */
|
|
145
|
-
request?: HttpClientRequestOptions;
|
|
146
|
-
/**
|
|
147
|
-
* @deprecated keep compatible with egg 3.x, no more used
|
|
148
|
-
*/
|
|
149
|
-
useHttpClientNext?: boolean;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// development: {
|
|
153
|
-
// /**
|
|
154
|
-
// * dirs needed watch, when files under these change, application will reload, use relative path
|
|
155
|
-
// */
|
|
156
|
-
// watchDirs: string[];
|
|
157
|
-
// /**
|
|
158
|
-
// * dirs don't need watch, including subdirectories, use relative path
|
|
159
|
-
// */
|
|
160
|
-
// ignoreDirs: string[];
|
|
161
|
-
// /**
|
|
162
|
-
// * don't wait all plugins ready, default is true.
|
|
163
|
-
// */
|
|
164
|
-
// fastReady: boolean;
|
|
165
|
-
// /**
|
|
166
|
-
// * whether reload on debug, default is true.
|
|
167
|
-
// */
|
|
168
|
-
// reloadOnDebug: boolean;
|
|
169
|
-
// /**
|
|
170
|
-
// * whether override default watchDirs, default is false.
|
|
171
|
-
// */
|
|
172
|
-
// overrideDefault: boolean;
|
|
173
|
-
// /**
|
|
174
|
-
// * whether override default ignoreDirs, default is false.
|
|
175
|
-
// */
|
|
176
|
-
// overrideIgnore: boolean;
|
|
177
|
-
// /**
|
|
178
|
-
// * whether to reload, use https://github.com/sindresorhus/multimatch
|
|
179
|
-
// */
|
|
180
|
-
// reloadPattern: string[] | string;
|
|
181
|
-
// };
|
|
155
|
+
httpclient: HttpClientConfig;
|
|
182
156
|
|
|
183
157
|
/**
|
|
184
158
|
* customLoader config
|
|
@@ -209,32 +183,6 @@ export interface EggAppConfig extends EggCoreAppConfig {
|
|
|
209
183
|
|
|
210
184
|
hostHeaders: string;
|
|
211
185
|
|
|
212
|
-
/**
|
|
213
|
-
* I18n options
|
|
214
|
-
*/
|
|
215
|
-
i18n: {
|
|
216
|
-
/**
|
|
217
|
-
* default value EN_US
|
|
218
|
-
*/
|
|
219
|
-
defaultLocale: string;
|
|
220
|
-
/**
|
|
221
|
-
* i18n resource file dir, not recommend to change default value
|
|
222
|
-
*/
|
|
223
|
-
dirs: string[];
|
|
224
|
-
/**
|
|
225
|
-
* custom the locale value field, default `query.locale`, you can modify this config, such as `query.lang`
|
|
226
|
-
*/
|
|
227
|
-
queryField: string;
|
|
228
|
-
/**
|
|
229
|
-
* The locale value key in the cookie, default is locale.
|
|
230
|
-
*/
|
|
231
|
-
cookieField: string;
|
|
232
|
-
/**
|
|
233
|
-
* Locale cookie expire time, default `1y`, If pass number value, the unit will be ms
|
|
234
|
-
*/
|
|
235
|
-
cookieMaxAge: string | number;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
186
|
/**
|
|
239
187
|
* Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true.
|
|
240
188
|
*/
|
|
@@ -249,21 +197,6 @@ export interface EggAppConfig extends EggCoreAppConfig {
|
|
|
249
197
|
httpOnly?: boolean;
|
|
250
198
|
};
|
|
251
199
|
|
|
252
|
-
/**
|
|
253
|
-
* jsonp options
|
|
254
|
-
* @member Config#jsonp
|
|
255
|
-
* @property {String} callback - jsonp callback method key, default to `_callback`
|
|
256
|
-
* @property {Number} limit - callback method name's max length, default to `50`
|
|
257
|
-
* @property {Boolean} csrf - enable csrf check or not. default to false
|
|
258
|
-
* @property {String|RegExp|Array} whiteList - referrer white list
|
|
259
|
-
*/
|
|
260
|
-
jsonp: {
|
|
261
|
-
limit: number;
|
|
262
|
-
callback: string;
|
|
263
|
-
csrf: boolean;
|
|
264
|
-
whiteList: string | RegExp | Array<string | RegExp>;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
200
|
/**
|
|
268
201
|
* The key that signing cookies. It can contain multiple keys separated by .
|
|
269
202
|
*/
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Router } from '@eggjs/core';
|
|
2
|
-
import type { EggLogger } from 'egg-logger';
|
|
3
|
-
import type { HttpClientRequestURL, HttpClientRequestOptions, HttpClient } from '../../lib/core/httpclient.js';
|
|
4
|
-
import type Helper from './helper.js';
|
|
5
|
-
declare module '@eggjs/core' {
|
|
6
|
-
interface Context {
|
|
7
|
-
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
|
|
8
|
-
get router(): Router;
|
|
9
|
-
set router(val: Router);
|
|
10
|
-
get helper(): Helper;
|
|
11
|
-
get httpclient(): HttpClient;
|
|
12
|
-
get httpClient(): HttpClient;
|
|
13
|
-
getLogger(name: string): EggLogger;
|
|
14
|
-
get logger(): EggLogger;
|
|
15
|
-
get coreLogger(): EggLogger;
|
|
16
|
-
get locals(): Record<string, any>;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udGV4dC50eXBlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9hcHAvZXh0ZW5kL2NvbnRleHQudHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVxdWVzdC50eXBlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9hcHAvZXh0ZW5kL3JlcXVlc3QudHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzcG9uc2UudHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXBwL2V4dGVuZC9yZXNwb25zZS50eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import type EggContext from '../app/extend/context.js';
|
|
3
|
-
import type { EggLogger } from 'egg-logger';
|
|
4
|
-
declare module '@eggjs/core' {
|
|
5
|
-
interface EggCore {
|
|
6
|
-
inspect(): any;
|
|
7
|
-
get currentContext(): EggContext | undefined;
|
|
8
|
-
ctxStorage: AsyncLocalStorage<EggContext>;
|
|
9
|
-
get logger(): EggLogger;
|
|
10
|
-
get coreLogger(): EggLogger;
|
|
11
|
-
getLogger(name: string): EggLogger;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWdnLnR5cGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9lZ2cudHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Router } from '@eggjs/core';
|
|
2
|
-
import type { EggLogger } from 'egg-logger';
|
|
3
|
-
import type { HttpClientRequestURL, HttpClientRequestOptions, HttpClient } from '../../lib/core/httpclient.js';
|
|
4
|
-
import type Helper from './helper.js';
|
|
5
|
-
declare module '@eggjs/core' {
|
|
6
|
-
interface Context {
|
|
7
|
-
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
|
|
8
|
-
get router(): Router;
|
|
9
|
-
set router(val: Router);
|
|
10
|
-
get helper(): Helper;
|
|
11
|
-
get httpclient(): HttpClient;
|
|
12
|
-
get httpClient(): HttpClient;
|
|
13
|
-
getLogger(name: string): EggLogger;
|
|
14
|
-
get logger(): EggLogger;
|
|
15
|
-
get coreLogger(): EggLogger;
|
|
16
|
-
get locals(): Record<string, any>;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import type EggContext from '../app/extend/context.js';
|
|
3
|
-
import type { EggLogger } from 'egg-logger';
|
|
4
|
-
declare module '@eggjs/core' {
|
|
5
|
-
interface EggCore {
|
|
6
|
-
inspect(): any;
|
|
7
|
-
get currentContext(): EggContext | undefined;
|
|
8
|
-
ctxStorage: AsyncLocalStorage<EggContext>;
|
|
9
|
-
get logger(): EggLogger;
|
|
10
|
-
get coreLogger(): EggLogger;
|
|
11
|
-
getLogger(name: string): EggLogger;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Router,
|
|
3
|
-
} from '@eggjs/core';
|
|
4
|
-
import type { EggLogger } from 'egg-logger';
|
|
5
|
-
import type {
|
|
6
|
-
HttpClientRequestURL, HttpClientRequestOptions, HttpClient,
|
|
7
|
-
} from '../../lib/core/httpclient.js';
|
|
8
|
-
import type Helper from './helper.js';
|
|
9
|
-
|
|
10
|
-
declare module '@eggjs/core' {
|
|
11
|
-
// add Context overrides types
|
|
12
|
-
interface Context {
|
|
13
|
-
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
|
|
14
|
-
get router(): Router;
|
|
15
|
-
set router(val: Router);
|
|
16
|
-
get helper(): Helper;
|
|
17
|
-
get httpclient(): HttpClient;
|
|
18
|
-
get httpClient(): HttpClient;
|
|
19
|
-
getLogger(name: string): EggLogger;
|
|
20
|
-
get logger(): EggLogger;
|
|
21
|
-
get coreLogger(): EggLogger;
|
|
22
|
-
get locals(): Record<string, any>;
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/lib/egg.types.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import type EggContext from '../app/extend/context.js';
|
|
3
|
-
import type { EggLogger } from 'egg-logger';
|
|
4
|
-
|
|
5
|
-
declare module '@eggjs/core' {
|
|
6
|
-
// add EggApplicationCore overrides types
|
|
7
|
-
interface EggCore {
|
|
8
|
-
inspect(): any;
|
|
9
|
-
get currentContext(): EggContext | undefined;
|
|
10
|
-
ctxStorage: AsyncLocalStorage<EggContext>;
|
|
11
|
-
get logger(): EggLogger;
|
|
12
|
-
get coreLogger(): EggLogger;
|
|
13
|
-
getLogger(name: string): EggLogger;
|
|
14
|
-
}
|
|
15
|
-
}
|