koatty_container
Advanced tools
Comparing version 1.8.1 to 1.8.2
@@ -0,0 +0,0 @@ /* |
@@ -5,2 +5,9 @@ # Changelog | ||
### [1.8.2](https://github.com/koatty/koatty_container/compare/v1.8.1...v1.8.2) (2023-11-09) | ||
### Bug Fixes | ||
* 修复多个aop绑定冲突问题 ([277c48f](https://github.com/koatty/koatty_container/commit/277c48febc4e8f81ff80317ff8ca414ab450f6bb)) | ||
### [1.8.1](https://github.com/koatty/koatty_container/compare/v1.8.0...v1.8.1) (2023-07-22) | ||
@@ -7,0 +14,0 @@ |
/*! | ||
* @Author: richen | ||
* @Date: 2023-07-22 11:28:38 | ||
* @Date: 2023-11-09 22:56:59 | ||
* @License: BSD (3-Clause) | ||
@@ -12,6 +12,6 @@ * @Copyright (c) - <richenlin(at)gmail.com> | ||
* @export | ||
* @param {(string | Function)} aopName | ||
* @param {string} aopName | ||
* @returns {MethodDecorator} | ||
*/ | ||
export declare function After(aopName: string | Function): MethodDecorator; | ||
export declare function After(aopName: string): MethodDecorator; | ||
@@ -25,3 +25,3 @@ /** | ||
*/ | ||
export declare function AfterEach(aopName?: string | Function): ClassDecorator; | ||
export declare function AfterEach(aopName: string): ClassDecorator; | ||
@@ -88,6 +88,6 @@ /** | ||
* @export | ||
* @param {(string | Function)} aopName | ||
* @param {string} aopName | ||
* @returns {MethodDecorator} | ||
*/ | ||
export declare function Before(aopName: string | Function): MethodDecorator; | ||
export declare function Before(aopName: string): MethodDecorator; | ||
@@ -101,3 +101,3 @@ /** | ||
*/ | ||
export declare function BeforeEach(aopName?: string | Function): ClassDecorator; | ||
export declare function BeforeEach(aopName: string): ClassDecorator; | ||
@@ -104,0 +104,0 @@ export declare type ComponentType = 'COMPONENT' | 'CONTROLLER' | 'MIDDLEWARE' | 'SERVICE'; |
/*! | ||
* @Author: richen | ||
* @Date: 2023-07-22 11:28:26 | ||
* @Date: 2023-11-09 22:56:48 | ||
* @License: BSD (3-Clause) | ||
@@ -363,3 +363,3 @@ * @Copyright (c) - <richenlin(at)gmail.com> | ||
* @export | ||
* @param {(string | Function)} aopName | ||
* @param {string} aopName | ||
* @returns {MethodDecorator} | ||
@@ -384,3 +384,3 @@ */ | ||
// return descriptor; | ||
IOCContainer.saveClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
IOCContainer.attachClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
type: exports.AOPType.Before, | ||
@@ -401,3 +401,3 @@ name: aopName, | ||
return (target) => { | ||
IOCContainer.saveClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
IOCContainer.attachClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
type: exports.AOPType.BeforeEach, | ||
@@ -412,3 +412,3 @@ name: aopName | ||
* @export | ||
* @param {(string | Function)} aopName | ||
* @param {string} aopName | ||
* @returns {MethodDecorator} | ||
@@ -434,3 +434,3 @@ */ | ||
// return descriptor; | ||
IOCContainer.saveClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
IOCContainer.attachClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
type: exports.AOPType.After, | ||
@@ -451,3 +451,3 @@ name: aopName, | ||
return (target) => { | ||
IOCContainer.saveClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
IOCContainer.attachClassMetadata(TAGGED_CLS, TAGGED_AOP, { | ||
type: exports.AOPType.AfterEach, | ||
@@ -459,33 +459,6 @@ name: aopName | ||
/** | ||
* Execute aspect | ||
* | ||
* @param {(string | Function)} aopName | ||
* @param {any[]} props | ||
* @returns {*} | ||
*/ | ||
async function executeAspect(aopName, props) { | ||
// tslint:disable-next-line: one-variable-per-declaration | ||
let aspect; //, name = ""; | ||
if (helper__namespace.isClass(aopName)) { | ||
// tslint:disable-next-line: no-invalid-this | ||
aspect = IOCContainer.getInsByClass(aopName); | ||
// name = IOCContainer.getIdentifier(<Function>aopName) || (<Function>aopName).name || ""; | ||
} | ||
else { | ||
// tslint:disable-next-line: no-invalid-this | ||
aspect = IOCContainer.get(aopName, "COMPONENT"); | ||
// name = <string>aopName; | ||
} | ||
if (aspect && helper__namespace.isFunction(aspect.run)) { | ||
koatty_logger.DefaultLogger.Debug(`Execute the aspect ${aopName}`); | ||
// tslint:disable-next-line: no-invalid-this | ||
await aspect.run(props); | ||
} | ||
return Promise.resolve(); | ||
} | ||
/** | ||
* inject AOP | ||
* | ||
* @export | ||
* @param {*} target | ||
* @param {Function} target | ||
* @param {*} instance | ||
@@ -495,2 +468,3 @@ * @param {Container} container | ||
function injectAOP(target, instance, container) { | ||
var _a; | ||
const allMethods = getMethodNames(target); | ||
@@ -506,15 +480,17 @@ // only binding self method | ||
} | ||
const classMetaData = container.getClassMetadata(TAGGED_CLS, TAGGED_AOP, target); | ||
const { type, name, method } = classMetaData || {}; | ||
if (name && [exports.AOPType.Before, exports.AOPType.BeforeEach, exports.AOPType.After, exports.AOPType.AfterEach].includes(type)) { | ||
methodsFilter(selfMethods).forEach((element) => { | ||
if (element === method) { | ||
// If the class has defined the default AOP method, @BeforeEach and @AfterEach will not take effect | ||
if (hasDefault && (type === exports.AOPType.BeforeEach || type === exports.AOPType.AfterEach)) { | ||
return; | ||
const classMetaDatas = (_a = container.getClassMetadata(TAGGED_CLS, TAGGED_AOP, target)) !== null && _a !== void 0 ? _a : []; | ||
for (const classMetaData of classMetaDatas) { | ||
const { type, name, method } = classMetaData || {}; | ||
if (name && [exports.AOPType.Before, exports.AOPType.BeforeEach, exports.AOPType.After, exports.AOPType.AfterEach].includes(type)) { | ||
methodsFilter(selfMethods).forEach((element) => { | ||
if (element === method) { | ||
// If the class has defined the default AOP method, @BeforeEach and @AfterEach will not take effect | ||
if (hasDefault && (type === exports.AOPType.BeforeEach || type === exports.AOPType.AfterEach)) { | ||
return; | ||
} | ||
// Logger.Debug(`Register inject AOP ${target.name} method: ${element} => ${type}`); | ||
defineAOPProperty(target, element, name, type); | ||
} | ||
// Logger.Debug(`Register inject AOP ${target.name} method: ${element} => ${type}`); | ||
defineAOPProperty(target, element, name, type); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -542,3 +518,3 @@ } | ||
* @export | ||
* @param {*} target | ||
* @param {Function} target | ||
* @param {*} instance | ||
@@ -553,5 +529,5 @@ * @param {string[]} methods | ||
// ); | ||
koatty_logger.DefaultLogger.Debug(`The ${target.name} class has default AOP method, @BeforeEach and @AfterEach not take effect`); | ||
methods.forEach((element) => { | ||
if (helper__namespace.isFunction(instance.__before)) { | ||
koatty_logger.DefaultLogger.Debug(`The ${target.name} class has AOP method '__before', @BeforeEach is not take effect`); | ||
koatty_logger.DefaultLogger.Debug(`Register inject default AOP ${target.name} method: ${element} => __before`); | ||
@@ -561,2 +537,3 @@ defineAOPProperty(target, element, "__before", exports.AOPType.BeforeEach); | ||
if (helper__namespace.isFunction(instance.__after)) { | ||
koatty_logger.DefaultLogger.Debug(`The ${target.name} class has AOP method '__after', @AfterEach is not take effect`); | ||
koatty_logger.DefaultLogger.Debug(`Register inject default AOP ${target.name} method: ${element} => __after`); | ||
@@ -612,2 +589,19 @@ defineAOPProperty(target, element, "__after", exports.AOPType.AfterEach); | ||
} | ||
/** | ||
* Execute aspect | ||
* | ||
* @param {string} aopName | ||
* @param {any[]} props | ||
* @returns {*} | ||
*/ | ||
async function executeAspect(aopName, props) { | ||
// tslint:disable-next-line: one-variable-per-declaration | ||
const aspect = IOCContainer.get(aopName, "COMPONENT"); | ||
if (aspect && helper__namespace.isFunction(aspect.run)) { | ||
koatty_logger.DefaultLogger.Debug(`Execute the aspect ${aopName}`); | ||
// tslint:disable-next-line: no-invalid-this | ||
await aspect.run(props); | ||
} | ||
return Promise.resolve(); | ||
} | ||
@@ -614,0 +608,0 @@ /* |
{ | ||
"name": "koatty_container", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"description": "IOC Container for Koatty.", | ||
@@ -12,3 +12,3 @@ "scripts": { | ||
"eslint": "eslint --ext .ts,.js ./", | ||
"prepublishOnly": "npm test && npm run build", | ||
"prepublishOnly": "npm test && npm run build && git push --follow-tags origin", | ||
"prerelease": "npm test && npm run build", | ||
@@ -19,3 +19,2 @@ "release": "standard-version", | ||
"release:minor": "npm run release -- --release-as minor", | ||
"pub": "git push --follow-tags origin && npm publish", | ||
"test": "npm run eslint && jest --passWithNoTests", | ||
@@ -82,3 +81,3 @@ "test:cov": "jest --collectCoverage --detectOpenHandles", | ||
"reflect-metadata": "^0.1.13", | ||
"tslib": "^2.6.0" | ||
"tslib": "^2.6.2" | ||
}, | ||
@@ -85,0 +84,0 @@ "peerDependencies": { |
@@ -0,0 +0,0 @@ # koatty_container |
{ | ||
"name": "koatty_container", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"description": "IOC Container for Koatty.", | ||
@@ -12,3 +12,3 @@ "scripts": { | ||
"eslint": "eslint --ext .ts,.js ./", | ||
"prepublishOnly": "npm test && npm run build", | ||
"prepublishOnly": "npm test && npm run build && git push --follow-tags origin", | ||
"prerelease": "npm test && npm run build", | ||
@@ -19,3 +19,2 @@ "release": "standard-version", | ||
"release:minor": "npm run release -- --release-as minor", | ||
"pub": "git push --follow-tags origin && npm publish", | ||
"test": "npm run eslint && jest --passWithNoTests", | ||
@@ -82,3 +81,3 @@ "test:cov": "jest --collectCoverage --detectOpenHandles", | ||
"reflect-metadata": "^0.1.13", | ||
"tslib": "^2.6.0" | ||
"tslib": "^2.6.2" | ||
}, | ||
@@ -85,0 +84,0 @@ "peerDependencies": { |
@@ -0,0 +0,0 @@ # koatty_container |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123091
2564
Updatedtslib@^2.6.2