koatty_container
Advanced tools
Comparing version 1.6.6 to 1.6.8
@@ -5,10 +5,4 @@ # Changelog | ||
### [1.6.6](https://github.com/koatty/koatty_container/compare/v1.6.2...v1.6.6) (2021-11-23) | ||
### [1.6.8](https://github.com/koatty/koatty_container/compare/v1.6.7...v1.6.8) (2021-11-23) | ||
### [1.6.4](https://github.com/koatty/koatty_container/compare/v1.6.2...v1.6.4) (2021-11-23) | ||
### [1.6.2](https://github.com/koatty/koatty_container/compare/v1.6.0...v1.6.2) (2021-11-20) | ||
### [1.6.0](https://github.com/koatty/koatty_container/compare/v1.5.2...v1.6.0) (2021-07-12) | ||
### [1.5.2](https://github.com/koatty/koatty_container/compare/v1.4.4...v1.5.2) (2021-07-09) | ||
@@ -15,0 +9,0 @@ |
113
dist/AOP.js
@@ -59,14 +59,22 @@ "use strict"; | ||
return (target, methodName, descriptor) => { | ||
const { value, configurable, enumerable } = descriptor; | ||
descriptor = { | ||
configurable, | ||
enumerable, | ||
writable: true, | ||
async value(...props) { | ||
await executeAspect(aopName, props); | ||
// tslint:disable-next-line: no-invalid-this | ||
return value.apply(this, props); | ||
}, | ||
}; | ||
return descriptor; | ||
if (!aopName) { | ||
throw Error("AopName is required."); | ||
} | ||
// const { value, configurable, enumerable } = descriptor; | ||
// descriptor = { | ||
// configurable, | ||
// enumerable, | ||
// writable: true, | ||
// async value(...props: any[]) { | ||
// await executeAspect(aopName, props); | ||
// // tslint:disable-next-line: no-invalid-this | ||
// return value.apply(this, props); | ||
// }, | ||
// }; | ||
// return descriptor; | ||
Container_1.IOCContainer.saveClassMetadata(IContainer_1.TAGGED_CLS, IContainer_1.TAGGED_AOP, { | ||
type: AOPType.Before, | ||
name: aopName, | ||
method: methodName, | ||
}, target); | ||
}; | ||
@@ -103,15 +111,20 @@ } | ||
} | ||
const { value, configurable, enumerable } = descriptor; | ||
descriptor = { | ||
configurable, | ||
enumerable, | ||
writable: true, | ||
async value(...props) { | ||
// tslint:disable-next-line: no-invalid-this | ||
const res = await value.apply(this, props); | ||
await executeAspect(aopName, props); | ||
return res; | ||
} | ||
}; | ||
return descriptor; | ||
// const { value, configurable, enumerable } = descriptor; | ||
// descriptor = { | ||
// configurable, | ||
// enumerable, | ||
// writable: true, | ||
// async value(...props: any[]) { | ||
// // tslint:disable-next-line: no-invalid-this | ||
// const res = await value.apply(this, props); | ||
// await executeAspect(aopName, props); | ||
// return res; | ||
// } | ||
// }; | ||
// return descriptor; | ||
Container_1.IOCContainer.saveClassMetadata(IContainer_1.TAGGED_CLS, IContainer_1.TAGGED_AOP, { | ||
type: AOPType.After, | ||
name: aopName, | ||
method: methodName, | ||
}, target); | ||
}; | ||
@@ -174,3 +187,3 @@ } | ||
const allMethods = (0, Util_1.getMethodNames)(target); | ||
const methods = allMethods.filter((m) => !["constructor", "init", "__before", "__after"].includes(m)); | ||
const methods = allMethods.filter((m) => !["constructor", "init", "__before", "__after"].includes(m) && target.prototype.hasOwnProperty(m)); | ||
if (allMethods.includes("__before") || allMethods.includes("__after")) { | ||
@@ -183,7 +196,13 @@ // inject default AOP method | ||
if (classMetaData) { | ||
const { type, name } = classMetaData; | ||
if (name && [AOPType.BeforeEach, AOPType.AfterEach].includes(type)) { | ||
const { type, name, method } = classMetaData; | ||
if (name && [AOPType.Before, AOPType.BeforeEach, AOPType.After, AOPType.AfterEach].includes(type)) { | ||
methods.forEach((element) => { | ||
// logger.Debug(`Register inject AOP ${target.name} method: ${element} => ${type}`); | ||
defineAOPProperty(target, element, name, type); | ||
if ([AOPType.Before, AOPType.After].includes(type) && method === element) { | ||
// Logger.Debug(`Register inject AOP ${target.name} method: ${element} => ${type}`); | ||
defineAOPProperty(target, element, name, type); | ||
} | ||
else { | ||
// Logger.Debug(`Register inject AOP ${target.name} method: ${element} => ${type}`); | ||
defineAOPProperty(target, element, name, type); | ||
} | ||
}); | ||
@@ -246,10 +265,7 @@ } | ||
const oldMethod = Reflect.get(classes.prototype, protoName); | ||
if (!oldMethod) { | ||
throw Error(`${protoName} method does not exist.`); | ||
} | ||
Reflect.defineProperty(classes.prototype, protoName, { | ||
writable: true, | ||
async value(...props) { | ||
if (type === AOPType.BeforeEach) { | ||
if (aopName) { | ||
if (oldMethod) { | ||
Reflect.defineProperty(classes.prototype, protoName, { | ||
writable: true, | ||
async value(...props) { | ||
if ([AOPType.Before, AOPType.BeforeEach].includes(type)) { | ||
if (aopName === "__before") { | ||
@@ -263,10 +279,8 @@ // logger.Info(`Execute the aspect ${classes.name}.__before`); | ||
} | ||
// tslint:disable-next-line: no-invalid-this | ||
return Reflect.apply(oldMethod, this, props); | ||
} | ||
// tslint:disable-next-line: no-invalid-this | ||
return Reflect.apply(oldMethod, this, props); | ||
} | ||
else if (type === AOPType.AfterEach) { | ||
// tslint:disable-next-line: no-invalid-this | ||
const res = await Reflect.apply(oldMethod, this, props); | ||
if (aopName) { | ||
else { | ||
// tslint:disable-next-line: no-invalid-this | ||
const res = await Reflect.apply(oldMethod, this, props); | ||
if (aopName === "__after") { | ||
@@ -280,8 +294,11 @@ // logger.Info(`Execute the aspect ${classes.name}.__after`); | ||
} | ||
return res; | ||
} | ||
return res; | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
else { | ||
throw Error(`${protoName} method does not exist.`); | ||
} | ||
} | ||
//# sourceMappingURL=AOP.js.map |
{ | ||
"name": "koatty_container", | ||
"version": "1.6.6", | ||
"version": "1.6.8", | ||
"description": "IOC Container for Koatty.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1858977
1824