UNPKG

7.99 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.INVALID_MIDDLEWARE_CONFIGURATION = exports.UNKNOWN_REQUEST_MAPPING = 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 name of the dependency to be 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);
44 const dependencyName = getDependencyName(name);
45 const potentialSolutions =
46 // If module's name is well defined
47 moduleName !== 'current'
48 ? `\n
49Potential solutions:
50- Is ${moduleName} a valid NestJS module?
51- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
52- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
53 @Module({
54 imports: [ /* the Module containing ${dependencyName} */ ]
55 })
56`
57 : `\n
58Potential solutions:
59- If ${dependencyName} is a provider, is it part of the current Module?
60- If ${dependencyName} is exported from a separate @Module, is that module imported within Module?
61 @Module({
62 imports: [ /* the Module containing ${dependencyName} */ ]
63 })
64`;
65 let message = `Nest can't resolve dependencies of the ${type.toString()}`;
66 if ((0, shared_utils_1.isNil)(index)) {
67 message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
68 return message;
69 }
70 const dependenciesName = (dependencies || []).map(getDependencyName);
71 dependenciesName[index] = '?';
72 message += ` (`;
73 message += dependenciesName.join(', ');
74 message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${moduleName} context.`;
75 message += potentialSolutions;
76 return message;
77};
78exports.UNKNOWN_DEPENDENCIES_MESSAGE = UNKNOWN_DEPENDENCIES_MESSAGE;
79const INVALID_MIDDLEWARE_MESSAGE = (text, name) => `The middleware doesn't provide the 'use' method (${name})`;
80exports.INVALID_MIDDLEWARE_MESSAGE = INVALID_MIDDLEWARE_MESSAGE;
81const 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.
82
83(Read more: https://docs.nestjs.com/fundamentals/circular-dependency)
84Scope [${stringifyScope(scope)}]
85`;
86exports.UNDEFINED_FORWARDREF_MESSAGE = UNDEFINED_FORWARDREF_MESSAGE;
87const INVALID_MODULE_MESSAGE = (parentModule, index, scope) => {
88 const parentModuleName = (parentModule === null || parentModule === void 0 ? void 0 : parentModule.name) || 'module';
89 return `Nest cannot create the ${parentModuleName} instance.
90Received an unexpected value at index [${index}] of the ${parentModuleName} "imports" array.
91
92Scope [${stringifyScope(scope)}]`;
93};
94exports.INVALID_MODULE_MESSAGE = INVALID_MODULE_MESSAGE;
95const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = (metatypeUsedAsAModule, scope) => {
96 const metatypeNameQuote = `"${getInstanceName(metatypeUsedAsAModule)}"` || 'that class';
97 return `Classes annotated with @Injectable(), @Catch(), and @Controller() decorators must not appear in the "imports" array of a module.
98Please remove ${metatypeNameQuote} (including forwarded occurrences, if any) from all of the "imports" arrays.
99
100Scope [${stringifyScope(scope)}]
101`;
102};
103exports.USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = USING_INVALID_CLASS_AS_A_MODULE_MESSAGE;
104const UNDEFINED_MODULE_MESSAGE = (parentModule, index, scope) => {
105 const parentModuleName = (parentModule === null || parentModule === void 0 ? void 0 : parentModule.name) || 'module';
106 return `Nest cannot create the ${parentModuleName} instance.
107The module at index [${index}] of the ${parentModuleName} "imports" array is undefined.
108
109Potential causes:
110- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
111- The module at index [${index}] is of type "undefined". Check your import statements and the type of the module.
112
113Scope [${stringifyScope(scope)}]`;
114};
115exports.UNDEFINED_MODULE_MESSAGE = UNDEFINED_MODULE_MESSAGE;
116const UNKNOWN_EXPORT_MESSAGE = (token = 'item', module) => {
117 token = (0, shared_utils_1.isSymbol)(token) ? token.toString() : token;
118 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.
119
120Possible Solutions:
121- Is ${token} part of the relevant providers/imports within ${module}?
122`;
123};
124exports.UNKNOWN_EXPORT_MESSAGE = UNKNOWN_EXPORT_MESSAGE;
125const INVALID_CLASS_MESSAGE = (text, value) => `ModuleRef cannot instantiate class (${value} is not constructable).`;
126exports.INVALID_CLASS_MESSAGE = INVALID_CLASS_MESSAGE;
127const 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.`;
128exports.INVALID_CLASS_SCOPE_MESSAGE = INVALID_CLASS_SCOPE_MESSAGE;
129const UNKNOWN_REQUEST_MAPPING = (metatype) => {
130 const className = metatype.name;
131 return className
132 ? `An invalid controller has been detected. "${className}" does not have the @Controller() decorator but it is being listed in the "controllers" array of some module.`
133 : `An invalid controller has been detected. Perhaps, one of your controllers is missing the @Controller() decorator.`;
134};
135exports.UNKNOWN_REQUEST_MAPPING = UNKNOWN_REQUEST_MAPPING;
136exports.INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
137exports.UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
138exports.INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
139exports.MICROSERVICES_PACKAGE_NOT_FOUND_EXCEPTION = `Unable to load @nestjs/microservices package. (Please make sure that it's already installed.)`;