UNPKG

power-di

Version:

A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.

55 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMetadataField = exports.getMetadata = exports.MetadataType = exports.metaSymbol = void 0; exports.metaSymbol = Symbol('power-di-metadata'); var MetadataType = /** @class */ (function () { function MetadataType() { this.classInfo = { extends: [], implements: [], }; this.injects = []; this.postConstruct = []; this.preDestroy = []; this.aspects = []; } return MetadataType; }()); exports.MetadataType = MetadataType; /** * get metadata of class * @param type type of class */ function getMetadata(type) { if ([Object, Object.prototype, Array, Array.prototype, Error, Error.prototype, null].includes(type)) { return new MetadataType(); } var metadata = Object.getOwnPropertyDescriptor(type, exports.metaSymbol); if (!metadata || !metadata.value) { Object.defineProperty(type, exports.metaSymbol, { enumerable: false, configurable: false, value: new MetadataType(), }); return getMetadata(type); } return metadata.value; } exports.getMetadata = getMetadata; /** * get the field of class metadata * @param type type of class * @param key field */ function getMetadataField(type, key) { var field = getMetadata(type)[key]; if (Array.isArray(field)) { var superType = Object.getPrototypeOf(type); if (superType) { return getMetadataField(superType, key).concat(field); } } return field; } exports.getMetadataField = getMetadataField; //# sourceMappingURL=metadata.js.map