-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: @Middleware support Advice (#231)
<!-- Thank you for your pull request. Please review below requirements. Bug fixes and new features should include tests and possibly benchmarks. Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md 感谢您贡献代码。请确认下列 checklist 的完成情况。 Bug 修复和新功能必须包含测试,必要时请附上性能测试。 Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md --> ##### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] `npm test` passes - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added - [ ] commit message follows commit guidelines ##### Affected core subsystem(s) <!-- Provide affected core subsystem(s). --> ##### Description of change <!-- Provide a description of the change below this comment. --> <!-- - any feature? - close https://github.com/eggjs/egg/ISSUE_URL --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for Aspect-Oriented Programming (AOP) middleware, enhancing the functionality of controllers and methods. - Introduced new advice classes to track middleware applications, facilitating better logging and monitoring. - Enhanced controller metadata handling, streamlining the process of building and accessing metadata. - **Bug Fixes** - Refined middleware handling to ensure proper registration and retrieval of AOP-related middleware. - **Tests** - Expanded test coverage to include new AOP middleware functionality, ensuring robust validation of middleware behavior. - **Chores** - Updated configuration files to include new modules and plugins related to AOP capabilities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
21 changed files
with
399 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
core/controller-decorator/test/fixtures/AopMiddlewareController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { HTTPMethodEnum, IAdvice, ObjectInitType } from '@eggjs/tegg-types'; | ||
import { Middleware } from '../../src/decorator/Middleware'; | ||
import { Advice } from '@eggjs/aop-decorator'; | ||
import { HTTPController } from '../../src/decorator/http/HTTPController'; | ||
import { HTTPMethod } from '../../src/decorator/http/HTTPMethod'; | ||
|
||
@Advice({ | ||
initType: ObjectInitType.SINGLETON, | ||
}) | ||
export class FooAdvice implements IAdvice { | ||
async beforeCall(): Promise<void> { | ||
// ... | ||
} | ||
} | ||
|
||
@Advice({ | ||
initType: ObjectInitType.SINGLETON, | ||
}) | ||
export class BarAdvice implements IAdvice { | ||
async beforeCall(): Promise<void> { | ||
// ... | ||
} | ||
} | ||
|
||
@Advice({ | ||
initType: ObjectInitType.SINGLETON, | ||
}) | ||
export class FooMethodAdvice implements IAdvice { | ||
async beforeCall(): Promise<void> { | ||
// ... | ||
} | ||
} | ||
|
||
@Advice({ | ||
initType: ObjectInitType.SINGLETON, | ||
}) | ||
export class BarMethodAdvice implements IAdvice { | ||
async beforeCall(): Promise<void> { | ||
// ... | ||
} | ||
} | ||
|
||
@Middleware(FooAdvice, BarAdvice) | ||
@HTTPController() | ||
export class AopMiddlewareController { | ||
|
||
@Middleware(FooMethodAdvice, BarMethodAdvice) | ||
@HTTPMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/hello', | ||
}) | ||
async hello(): Promise<void> { | ||
return; | ||
} | ||
|
||
@HTTPMethod({ | ||
method: HTTPMethodEnum.GET, | ||
path: '/bye', | ||
}) | ||
async bye(): Promise<void> { | ||
return; | ||
} | ||
} |
Oops, something went wrong.