@nestjs/core
Version:
Nest - modern, fast, powerful node.js web framework (@core)
56 lines (55 loc) • 3.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
// TODO: Replace `any` with `unknown` type when TS 3.0.0 is supported
/**
* Returns the name of an instance
* @param instance The instance which should get the name from
*/
const getInstanceName = (instance) => instance && instance.name;
/**
* Returns the name of the dependency
* Tries to get the class name, otherwise the string value
* (= injection token). As fallback it returns '+'
* @param dependency The dependency whichs name should get displayed
*/
const getDependencyName = (dependency) =>
// use class name
getInstanceName(dependency) ||
// use injection token (symbol)
(shared_utils_1.isSymbol(dependency) && dependency.toString()) ||
// use string directly
dependency ||
// otherwise
'+';
/**
* Returns the name of the module
* Tries to get the class name. As fallback it returns 'current'.
* @param module The module which should get displayed
*/
const getModuleName = (module) => (module && getInstanceName(module.metatype)) || 'current';
exports.UNKNOWN_DEPENDENCIES_MESSAGE = (type, unknownDependencyContext, module) => {
const { index, dependencies, key } = unknownDependencyContext;
let message = `Nest can't resolve dependencies of the ${type.toString()}`;
if (shared_utils_1.isNil(index)) {
message += `. Please make sure that the "${key.toString()}" property is available in the current context.`;
return message;
}
const dependenciesName = (dependencies || []).map(getDependencyName);
dependenciesName[index] = '?';
message += ` (`;
message += dependenciesName.join(', ');
message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(module)} context.`;
return message;
};
exports.INVALID_MIDDLEWARE_MESSAGE = (text, name) => `The middleware doesn't provide the 'use' method (${name})`;
exports.INVALID_MODULE_MESSAGE = (text, scope) => `Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it. (Read more: https://docs.nestjs.com/fundamentals/circular-dependency.) Scope [${scope}]`;
exports.UNKNOWN_EXPORT_MESSAGE = (text, module) => `Nest cannot export a provider/module that is not a part of the currently processed module (${module}). Please verify whether each exported unit is available in this particular context.`;
exports.INVALID_CLASS_MESSAGE = (text, value) => `ModuleRef cannot instantiate class (${value} is not constructable).`;
exports.INVALID_CLASS_SCOPE_MESSAGE = (text, name) => `${name ||
'This class'} is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead.`;
exports.INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
exports.UNKNOWN_REQUEST_MAPPING = `An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.`;
exports.UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
exports.INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = `Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)`;