"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var object_hash_1 = __importDefault(require("object-hash"));
var ExpressTS_1 = __importDefault(require("../app/ExpressTS"));
/**
* This decorator is used to define a Domain.
* Domain classes are **automatically** injected.
*
* All the Domain classes must be in ``src/domain`` and they must have [\@Inject]{@link Inject}
*
* For an example on how the domain is used, check the [example from \@Post]{@link Post}.
*
* @static
* @return {any}
* @method Domain
* @memberof module:Router
* @param {!string} name The name of the domain (This will have as prefix ``Domain.``)
* @example <caption>Example usage of [\@Domain]{@link Domain}.</caption>
* [\@Inject]{@link Inject}
* [\@Domain]{@link Domain}('Name') // This will be accessed as 'Domain.Name'
* export default class DomainName {
* public async saveUser(name: string) {
* ...
* return {
* userId: '123'
* };
* }
* }
*/
exports.default = (function (name) { return function (constructor) {
if (constructor.name === '_injected') {
throw new Error('The domain must be called first!');
}
var domainHash = (0, object_hash_1.default)(constructor);
if (!ExpressTS_1.default.getData(domainHash, 'domains')) {
ExpressTS_1.default.setData(domainHash, name, 'domains');
}
return constructor;
}; });
//# sourceMappingURL=Domain.js.map