egg 3.14.2 → 3.15.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/index.d.ts CHANGED
@@ -729,8 +729,9 @@ declare module 'egg' {
729
729
  * Run async function in the anonymous context scope
730
730
  * @see Context#runInAnonymousContextScope
731
731
  * @param {Function} scope - the first args is an anonymous ctx, scope should be async function
732
+ * @param {Request} req - if you want to mock request like querystring, you can pass an object to this function.
732
733
  */
733
- runInAnonymousContextScope(scope: (ctx: Context) => Promise<void>): Promise<void>;
734
+ runInAnonymousContextScope<R>(scope: (ctx: Context) => Promise<R>, req?: Request): Promise<R>;
734
735
 
735
736
  /**
736
737
  * Get current execute ctx async local storage
@@ -260,12 +260,13 @@ class Application extends EggApplication {
260
260
  * Run async function in the anonymous context scope
261
261
  * @see Context#runInAnonymousContextScope
262
262
  * @param {Function} scope - the first args is an anonymous ctx, scope should be async function
263
+ * @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
263
264
  */
264
- async runInAnonymousContextScope(scope) {
265
- const ctx = this.createAnonymousContext();
265
+ async runInAnonymousContextScope(scope, req) {
266
+ const ctx = this.createAnonymousContext(req);
266
267
  if (!scope.name) scope._name = eggUtils.getCalleeFromStack(true);
267
- await this.ctxStorage.run(ctx, async () => {
268
- await scope(ctx);
268
+ return await this.ctxStorage.run(ctx, async () => {
269
+ return await scope(ctx);
269
270
  });
270
271
  }
271
272
 
package/lib/egg.js CHANGED
@@ -510,7 +510,7 @@ class EggApplication extends EggCore {
510
510
  * Create an anonymous context, the context isn't request level, so the request is mocked.
511
511
  * then you can use context level API like `ctx.service`
512
512
  * @member {String} EggApplication#createAnonymousContext
513
- * @param {Request} req - if you want to mock request like querystring, you can pass an object to this function.
513
+ * @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
514
514
  * @return {Context} context
515
515
  */
516
516
  createAnonymousContext(req) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "3.14.2",
3
+ "version": "3.15.0",
4
4
  "publishConfig": {
5
5
  "tag": "latest"
6
6
  },