UNPKG

4.04 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
4/**
5 * Returns the name of an instance
6 * @param instance The instance which should get the name from
7 */
8const getInstanceName = (instance) => instance && instance.name;
9/**
10 * Returns the name of the dependency
11 * Tries to get the class name, otherwise the string value
12 * (= injection token). As fallback it returns '+'
13 * @param dependency The dependency whichs name should get displayed
14 */
15const getDependencyName = (dependency) =>
16// use class name
17getInstanceName(dependency) ||
18 // use injection token (symbol)
19 (shared_utils_1.isSymbol(dependency) && dependency.toString()) ||
20 // use string directly
21 dependency ||
22 // otherwise
23 '+';
24/**
25 * Returns the name of the module
26 * Tries to get the class name. As fallback it returns 'current'.
27 * @param module The module which should get displayed
28 */
29const getModuleName = (module) => (module && getInstanceName(module.metatype)) || 'current';
30exports.UNKNOWN_DEPENDENCIES_MESSAGE = (type, unknownDependencyContext, module) => {
31 const { index, name = 'dependency', dependencies, key, } = unknownDependencyContext;
32 const moduleName = getModuleName(module) || 'Module';
33 const dependencyName = getDependencyName(name);
34 let message = `Nest can't resolve dependencies of the ${type.toString()}`;
35 const potentialSolutions = `\n
36Potential solutions:
37- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
38- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
39 @Module({
40 imports: [ /* the Module containing ${dependencyName} */ ]
41 })
42`;
43 if (shared_utils_1.isNil(index)) {
44 message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
45 return message;
46 }
47 const dependenciesName = (dependencies || []).map(getDependencyName);
48 dependenciesName[index] = '?';
49 message += ` (`;
50 message += dependenciesName.join(', ');
51 message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${getModuleName(module)} context.`;
52 message += potentialSolutions;
53 return message;
54};
55exports.INVALID_MIDDLEWARE_MESSAGE = (text, name) => `The middleware doesn't provide the 'use' method (${name})`;
56exports.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.
57
58(Read more: https://docs.nestjs.com/fundamentals/circular-dependency)
59Scope [${scope}]
60`;
61exports.UNKNOWN_EXPORT_MESSAGE = (token = 'item', module) => {
62 return `Nest cannot export a provider/module that is not a part of the currently processed module (${module}). Please verify whether the exported ${token} is available in this particular context.
63
64Possible Solutions:
65- Is ${token} part of the relevant providers/imports within ${module}?
66`;
67};
68exports.INVALID_CLASS_MESSAGE = (text, value) => `ModuleRef cannot instantiate class (${value} is not constructable).`;
69exports.INVALID_CLASS_SCOPE_MESSAGE = (text, name) => `${name ||
70 '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.`;
71exports.INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
72exports.UNKNOWN_REQUEST_MAPPING = `An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.`;
73exports.UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
74exports.INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
75exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = `Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)`;