egg 3.14.1 → 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
@@ -546,7 +546,7 @@ declare module 'egg' {
546
546
  headers: { [key: string]: string };
547
547
  }
548
548
 
549
- export interface Router extends KoaRouter<any, Context> {
549
+ export interface Router extends Omit<KoaRouter<any, Context>, 'url'> {
550
550
  /**
551
551
  * restful router api
552
552
  */
@@ -554,7 +554,7 @@ declare module 'egg' {
554
554
 
555
555
  /**
556
556
  * @param {String} name - Router name
557
- * @param {Object} params - more parameters
557
+ * @param {Object} [params] - more parameters
558
558
  * @example
559
559
  * ```js
560
560
  * router.url('edit_post', { id: 1, name: 'foo', page: 2 })
@@ -565,7 +565,12 @@ declare module 'egg' {
565
565
  * @return {String} url by path name and query params.
566
566
  * @since 1.0.0
567
567
  */
568
- url(name: string, params: any): any;
568
+ url(name: string, params?: any): string;
569
+ /**
570
+ * Alias for the url method
571
+ */
572
+ pathFor(name: string, params?: any): string;
573
+ methods: string[];
569
574
  }
570
575
 
571
576
  export interface EggApplication extends EggCoreBase<EggAppConfig> { // tslint:disable-line
@@ -724,8 +729,9 @@ declare module 'egg' {
724
729
  * Run async function in the anonymous context scope
725
730
  * @see Context#runInAnonymousContextScope
726
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.
727
733
  */
728
- runInAnonymousContextScope(scope: (ctx: Context) => Promise<void>): Promise<void>;
734
+ runInAnonymousContextScope<R>(scope: (ctx: Context) => Promise<R>, req?: Request): Promise<R>;
729
735
 
730
736
  /**
731
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.1",
3
+ "version": "3.15.0",
4
4
  "publishConfig": {
5
5
  "tag": "latest"
6
6
  },