koatty_container
Advanced tools
Comparing version 1.2.2 to 1.3.0
@@ -33,4 +33,4 @@ /** | ||
/** | ||
* inject autowired class | ||
* | ||
* | ||
* @export | ||
@@ -37,0 +37,0 @@ * @param {*} target |
@@ -17,2 +17,3 @@ "use strict"; | ||
const IContainer_1 = require("./IContainer"); | ||
const Util_1 = require("./Util"); | ||
/** | ||
@@ -68,3 +69,3 @@ * Marks a constructor method as to be autowired by Koatty"s dependency injection facilities. | ||
} | ||
Container_1.Container.getInstance().savePropertyData(IContainer_1.TAGGED_PROP, { | ||
Container_1.IOCContainer.savePropertyData(IContainer_1.TAGGED_PROP, { | ||
type, | ||
@@ -90,4 +91,4 @@ identifier, | ||
/** | ||
* inject autowired class | ||
* | ||
* | ||
* @export | ||
@@ -100,3 +101,3 @@ * @param {*} target | ||
function injectAutowired(target, instance, container, isLazy = false) { | ||
const metaData = recursiveGetMetadata(IContainer_1.TAGGED_PROP, target); | ||
const metaData = Util_1.RecursiveGetMetadata(IContainer_1.TAGGED_PROP, target); | ||
// tslint:disable-next-line: forin | ||
@@ -136,65 +137,2 @@ for (const metaKey in metaData) { | ||
exports.injectAutowired = injectAutowired; | ||
// get property of an object | ||
const functionPrototype = Object.getPrototypeOf(Function); | ||
// https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof | ||
function ordinaryGetPrototypeOf(obj) { | ||
const proto = Object.getPrototypeOf(obj); | ||
if (typeof obj !== "function" || obj === functionPrototype) { | ||
return proto; | ||
} | ||
// TypeScript doesn't set __proto__ in ES5, as it's non-standard. | ||
// Try to determine the superclass constructor. Compatible implementations | ||
// must either set __proto__ on a subclass constructor to the superclass constructor, | ||
// or ensure each class has a valid `constructor` property on its prototype that | ||
// points back to the constructor. | ||
// If this is not the same as Function.[[Prototype]], then this is definately inherited. | ||
// This is the case when in ES6 or when using __proto__ in a compatible browser. | ||
if (proto !== functionPrototype) { | ||
return proto; | ||
} | ||
// If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage. | ||
const prototype = obj.prototype; | ||
const prototypeProto = prototype && Object.getPrototypeOf(prototype); | ||
// tslint:disable-next-line: triple-equals | ||
if (prototypeProto == undefined || prototypeProto === Object.prototype) { | ||
return proto; | ||
} | ||
// If the constructor was not a function, then we cannot determine the heritage. | ||
const constructor = prototypeProto.constructor; | ||
if (typeof constructor !== "function") { | ||
return proto; | ||
} | ||
// If we have some kind of self-reference, then we cannot determine the heritage. | ||
if (constructor === obj) { | ||
return proto; | ||
} | ||
// we have a pretty good guess at the heritage. | ||
return constructor; | ||
} | ||
/** | ||
* get metadata value of a metadata key on the prototype chain of an object and property | ||
* @param metadataKey metadata's key | ||
* @param target the target of metadataKey | ||
*/ | ||
function recursiveGetMetadata(metadataKey, target, propertyKey) { | ||
// get metadata value of a metadata key on the prototype | ||
// let metadata = Reflect.getOwnMetadata(metadataKey, target, propertyKey); | ||
const IOCContainer = Container_1.Container.getInstance(); | ||
const metadata = IOCContainer.listPropertyData(metadataKey, target) || {}; | ||
// get metadata value of a metadata key on the prototype chain | ||
let parent = ordinaryGetPrototypeOf(target); | ||
while (parent !== null) { | ||
// metadata = Reflect.getOwnMetadata(metadataKey, parent, propertyKey); | ||
const pmetadata = IOCContainer.listPropertyData(metadataKey, parent); | ||
if (pmetadata) { | ||
for (const n in pmetadata) { | ||
if (!metadata.hasOwnProperty(n)) { | ||
metadata[n] = pmetadata[n]; | ||
} | ||
} | ||
} | ||
parent = ordinaryGetPrototypeOf(parent); | ||
} | ||
return metadata; | ||
} | ||
//# sourceMappingURL=Autowired.js.map |
@@ -208,1 +208,2 @@ /** | ||
} | ||
export declare const IOCContainer: Container; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Container = void 0; | ||
exports.IOCContainer = exports.Container = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -16,2 +16,4 @@ /** | ||
const IContainer_1 = require("./IContainer"); | ||
const Value_1 = require("./Value"); | ||
const AOP_1 = require("./AOP"); | ||
/** | ||
@@ -105,2 +107,6 @@ * IOC Container | ||
}); | ||
// inject value | ||
Value_1.injectValue(target, target.prototype, this, app.config); | ||
// inject AOP | ||
AOP_1.injectAOP(target, target.prototype, this); | ||
// inject autowired | ||
@@ -426,2 +432,4 @@ Autowired_1.injectAutowired(target, target.prototype, this); | ||
exports.Container = Container; | ||
// export Singleton | ||
exports.IOCContainer = Container.getInstance(); | ||
//# sourceMappingURL=Container.js.map |
@@ -12,2 +12,3 @@ /** | ||
export declare const TAGGED_PROP = "INJECT_TAGGED_PROP"; | ||
export declare const TAGGED_AOP = "INJECT_TAGGED_AOP"; | ||
export declare const TAGGED_METHOD = "INJECT_TAGGED_METHOD"; | ||
@@ -14,0 +15,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TAGGED_METHOD = exports.TAGGED_PROP = exports.TAGGED_ARGS = exports.TAGGED_CLS = void 0; | ||
exports.TAGGED_METHOD = exports.TAGGED_AOP = exports.TAGGED_PROP = exports.TAGGED_ARGS = exports.TAGGED_CLS = void 0; | ||
// used to store class to be injected | ||
@@ -10,4 +10,6 @@ exports.TAGGED_CLS = 'INJECT_TAGGED_CLS'; | ||
exports.TAGGED_PROP = 'INJECT_TAGGED_PROP'; | ||
// used to store class AOP tags | ||
exports.TAGGED_AOP = 'INJECT_TAGGED_AOP'; | ||
// used to store class method to be injected | ||
exports.TAGGED_METHOD = 'INJECT_TAGGED_METHOD'; | ||
//# sourceMappingURL=IContainer.js.map |
@@ -7,6 +7,6 @@ /** | ||
*/ | ||
import { Container } from './Container'; | ||
export { Autowired } from "./Autowired"; | ||
export { Value, Config } from "./Value"; | ||
export { Aspect, Before, BeforeEach, After, AfterEach } from "./AOP"; | ||
export * from "./Container"; | ||
export * from "./IContainer"; | ||
export declare const IOCContainer: Container; |
@@ -9,11 +9,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IOCContainer = exports.Autowired = void 0; | ||
exports.AfterEach = exports.After = exports.BeforeEach = exports.Before = exports.Aspect = exports.Config = exports.Value = exports.Autowired = void 0; | ||
const tslib_1 = require("tslib"); | ||
const Container_1 = require("./Container"); | ||
var Autowired_1 = require("./Autowired"); | ||
Object.defineProperty(exports, "Autowired", { enumerable: true, get: function () { return Autowired_1.Autowired; } }); | ||
var Value_1 = require("./Value"); | ||
Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return Value_1.Value; } }); | ||
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return Value_1.Config; } }); | ||
var AOP_1 = require("./AOP"); | ||
Object.defineProperty(exports, "Aspect", { enumerable: true, get: function () { return AOP_1.Aspect; } }); | ||
Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return AOP_1.Before; } }); | ||
Object.defineProperty(exports, "BeforeEach", { enumerable: true, get: function () { return AOP_1.BeforeEach; } }); | ||
Object.defineProperty(exports, "After", { enumerable: true, get: function () { return AOP_1.After; } }); | ||
Object.defineProperty(exports, "AfterEach", { enumerable: true, get: function () { return AOP_1.AfterEach; } }); | ||
tslib_1.__exportStar(require("./Container"), exports); | ||
tslib_1.__exportStar(require("./IContainer"), exports); | ||
// export Singleton | ||
exports.IOCContainer = Container_1.Container.getInstance(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "koatty_container", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"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
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
75952
26
1554
1
3