UNPKG

7.34 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = exports.INVALID_EXCEPTION_FILTER = exports.UNHANDLED_RUNTIME_EXCEPTION = exports.UNKNOWN_REQUEST_MAPPING = exports.INVALID_MIDDLEWARE_CONFIGURATION = exports.INVALID_CLASS_SCOPE_MESSAGE = exports.INVALID_CLASS_MESSAGE = exports.UNKNOWN_EXPORT_MESSAGE = exports.UNDEFINED_MODULE_MESSAGE = exports.USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = exports.INVALID_MODULE_MESSAGE = exports.UNDEFINED_FORWARDREF_MESSAGE = exports.INVALID_MIDDLEWARE_MESSAGE = exports.UNKNOWN_DEPENDENCIES_MESSAGE = void 0;
4const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5/**
6 * Returns the name of an instance or `undefined`
7 * @param instance The instance which should get the name from
8 */
9const getInstanceName = (instance) => {
10 var _a, _b;
11 if (instance === null || instance === void 0 ? void 0 : instance.forwardRef) {
12 return (_a = instance.forwardRef()) === null || _a === void 0 ? void 0 : _a.name;
13 }
14 if (instance === null || instance === void 0 ? void 0 : instance.module) {
15 return (_b = instance.module) === null || _b === void 0 ? void 0 : _b.name;
16 }
17 return instance === null || instance === void 0 ? void 0 : instance.name;
18};
19/**
20 * Returns the name of the dependency
21 * Tries to get the class name, otherwise the string value
22 * (= injection token). As fallback it returns '+'
23 * @param dependency The dependency whichs name should get displayed
24 */
25const getDependencyName = (dependency) =>
26// use class name
27getInstanceName(dependency) ||
28 // use injection token (symbol)
29 ((0, shared_utils_1.isSymbol)(dependency) && dependency.toString()) ||
30 // use string directly
31 dependency ||
32 // otherwise
33 '+';
34/**
35 * Returns the name of the module
36 * Tries to get the class name. As fallback it returns 'current'.
37 * @param module The module which should get displayed
38 */
39const getModuleName = (module) => (module && getInstanceName(module.metatype)) || 'current';
40const stringifyScope = (scope) => (scope || []).map(getInstanceName).join(' -> ');
41const UNKNOWN_DEPENDENCIES_MESSAGE = (type, unknownDependencyContext, module) => {
42 const { index, name = 'dependency', dependencies, key, } = unknownDependencyContext;
43 const moduleName = getModuleName(module) || 'Module';
44 const dependencyName = getDependencyName(name);
45 let message = `Nest can't resolve dependencies of the ${type.toString()}`;
46 const potentialSolutions = `\n
47Potential solutions:
48- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
49- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
50 @Module({
51 imports: [ /* the Module containing ${dependencyName} */ ]
52 })
53`;
54 if ((0, shared_utils_1.isNil)(index)) {
55 message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
56 return message;
57 }
58 const dependenciesName = (dependencies || []).map(getDependencyName);
59 dependenciesName[index] = '?';
60 message += ` (`;
61 message += dependenciesName.join(', ');
62 message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${getModuleName(module)} context.`;
63 message += potentialSolutions;
64 return message;
65};
66exports.UNKNOWN_DEPENDENCIES_MESSAGE = UNKNOWN_DEPENDENCIES_MESSAGE;
67const INVALID_MIDDLEWARE_MESSAGE = (text, name) => `The middleware doesn't provide the 'use' method (${name})`;
68exports.INVALID_MIDDLEWARE_MESSAGE = INVALID_MIDDLEWARE_MESSAGE;
69const UNDEFINED_FORWARDREF_MESSAGE = (scope) => `Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it.
70
71(Read more: https://docs.nestjs.com/fundamentals/circular-dependency)
72Scope [${stringifyScope(scope)}]
73`;
74exports.UNDEFINED_FORWARDREF_MESSAGE = UNDEFINED_FORWARDREF_MESSAGE;
75const INVALID_MODULE_MESSAGE = (parentModule, index, scope) => {
76 const parentModuleName = (parentModule === null || parentModule === void 0 ? void 0 : parentModule.name) || 'module';
77 return `Nest cannot create the ${parentModuleName} instance.
78Received an unexpected value at index [${index}] of the ${parentModuleName} "imports" array.
79
80Scope [${stringifyScope(scope)}]`;
81};
82exports.INVALID_MODULE_MESSAGE = INVALID_MODULE_MESSAGE;
83const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = (metatypeUsedAsAModule, scope) => {
84 const metatypeName = getInstanceName(metatypeUsedAsAModule) || 'found';
85 // TODO(v9): Edit the message below:
86 return `In the next major version, Nest will not allow classes annotated with @Injectable(), @Catch(), and @Controller() decorators to appear in the "imports" array of a module.
87Please remove "${metatypeName}" (including forwarded occurrences, if any) from all of the "imports" arrays.
88
89Scope [${stringifyScope(scope)}]
90`;
91};
92exports.USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = USING_INVALID_CLASS_AS_A_MODULE_MESSAGE;
93const UNDEFINED_MODULE_MESSAGE = (parentModule, index, scope) => {
94 const parentModuleName = (parentModule === null || parentModule === void 0 ? void 0 : parentModule.name) || 'module';
95 return `Nest cannot create the ${parentModuleName} instance.
96The module at index [${index}] of the ${parentModuleName} "imports" array is undefined.
97
98Potential causes:
99- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
100- The module at index [${index}] is of type "undefined". Check your import statements and the type of the module.
101
102Scope [${stringifyScope(scope)}]`;
103};
104exports.UNDEFINED_MODULE_MESSAGE = UNDEFINED_MODULE_MESSAGE;
105const UNKNOWN_EXPORT_MESSAGE = (token = 'item', module) => {
106 token = (0, shared_utils_1.isSymbol)(token) ? token.toString() : token;
107 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.
108
109Possible Solutions:
110- Is ${token} part of the relevant providers/imports within ${module}?
111`;
112};
113exports.UNKNOWN_EXPORT_MESSAGE = UNKNOWN_EXPORT_MESSAGE;
114const INVALID_CLASS_MESSAGE = (text, value) => `ModuleRef cannot instantiate class (${value} is not constructable).`;
115exports.INVALID_CLASS_MESSAGE = INVALID_CLASS_MESSAGE;
116const 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.`;
117exports.INVALID_CLASS_SCOPE_MESSAGE = INVALID_CLASS_SCOPE_MESSAGE;
118exports.INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
119exports.UNKNOWN_REQUEST_MAPPING = `An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.`;
120exports.UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
121exports.INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
122exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = `Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)`;