@nestjs/common
Version:
Nest - modern, fast, powerful node.js web framework (@common)
46 lines (45 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const invalid_module_config_exception_1 = require("./exceptions/invalid-module-config.exception");
const metadataKeys = [
constants_1.METADATA.IMPORTS,
constants_1.METADATA.EXPORTS,
constants_1.METADATA.CONTROLLERS,
constants_1.METADATA.PROVIDERS,
];
const validateKeys = (keys) => {
const validateKey = (key) => {
if (metadataKeys.includes(key)) {
return;
}
throw new invalid_module_config_exception_1.InvalidModuleConfigException(key);
};
keys.forEach(validateKey);
};
/**
* Decorator that marks a class as a [module](https://docs.nestjs.com/modules).
*
* Modules are used by Nest to organize the application structure into scopes. Controllers
* and Providers are scoped by the module they are declared in. Modules and their
* classes (Controllers and Providers) form a graph that determines how Nest
* performs [Dependency Injection (DI)](https://docs.nestjs.com/providers#dependency-injection).
*
* @param metadata module configuration metadata
*
* @see [Modules](https://docs.nestjs.com/modules)
*
* @publicApi
*/
function Module(metadata) {
const propsKeys = Object.keys(metadata);
validateKeys(propsKeys);
return (target) => {
for (const property in metadata) {
if (metadata.hasOwnProperty(property)) {
Reflect.defineMetadata(property, metadata[property], target);
}
}
};
}
exports.Module = Module;