inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
97 lines • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
exports.INCEPTUM_METADATA_KEY = 'inceptum';
class InceptumMetadata {
constructor() {
this.autowire = new Map();
this.defaultValue = new Map();
this.lazy = true;
this.startMethod = null;
this.stopMethod = null;
this.groups = [];
}
}
exports.InceptumMetadata = InceptumMetadata;
function hasDecoratorMetadata(target) {
return Reflect.hasMetadata(exports.INCEPTUM_METADATA_KEY, target);
}
exports.hasDecoratorMetadata = hasDecoratorMetadata;
function getDecoratorMetadata(target) {
return Reflect.getMetadata(exports.INCEPTUM_METADATA_KEY, target);
}
exports.getDecoratorMetadata = getDecoratorMetadata;
function getOrCreateMetadata(target) {
if (hasDecoratorMetadata(target)) {
return getDecoratorMetadata(target);
}
const metadata = new InceptumMetadata();
Reflect.defineMetadata(exports.INCEPTUM_METADATA_KEY, metadata, target);
return metadata;
}
function Autowire(what) {
return (target, key) => {
// console.log('Called Autowire');
const metadata = getOrCreateMetadata(target);
metadata.autowire.set(key, what);
};
}
exports.Autowire = Autowire;
function AutowireContext(target, key) {
// console.log('Called Autowire');
const metadata = getOrCreateMetadata(target);
metadata.autowire.set(key, '__CONTEXT__');
}
exports.AutowireContext = AutowireContext;
function AutowireConfig(configKey, defaultValue) {
return (target, key) => {
// console.log('Called Autowire');
const metadata = getOrCreateMetadata(target);
metadata.autowire.set(key, `#${configKey}`);
if (defaultValue !== undefined) {
metadata.defaultValue.set(configKey, defaultValue);
}
};
}
exports.AutowireConfig = AutowireConfig;
function AutowireGroup(groupName) {
return (target, key) => {
// console.log('Called Autowire');
const metadata = getOrCreateMetadata(target);
metadata.autowire.set(key, `%${groupName}`);
};
}
exports.AutowireGroup = AutowireGroup;
function AutowireGroupDefinitions(groupName) {
return (target, key) => {
// console.log('Called Autowire');
const metadata = getOrCreateMetadata(target);
metadata.autowire.set(key, `&${groupName}`);
};
}
exports.AutowireGroupDefinitions = AutowireGroupDefinitions;
function Lazy(lazy) {
return (target) => {
const metadata = getOrCreateMetadata(target.prototype);
metadata.lazy = lazy;
};
}
exports.Lazy = Lazy;
function StartMethod(target, key) {
const metadata = getOrCreateMetadata(target);
metadata.startMethod = key;
}
exports.StartMethod = StartMethod;
function StopMethod(target, key) {
const metadata = getOrCreateMetadata(target);
metadata.stopMethod = key;
}
exports.StopMethod = StopMethod;
function RegisterInGroup(groupName) {
return (target) => {
const metadata = getOrCreateMetadata(target.prototype);
metadata.groups.push(groupName);
};
}
exports.RegisterInGroup = RegisterInGroup;
//# sourceMappingURL=Decorators.js.map