@nestjs/core 8.3.0 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +1 -0
- package/adapters/index.js +1 -1
- package/discovery/discovery-module.js +2 -2
- package/discovery/discovery-service.js +5 -5
- package/discovery/index.js +2 -2
- package/errors/exceptions/invalid-class-module.exception.js +1 -1
- package/errors/exceptions/invalid-class-scope.exception.js +2 -2
- package/errors/exceptions/invalid-class.exception.js +1 -1
- package/errors/exceptions/invalid-middleware.exception.js +1 -1
- package/errors/exceptions/invalid-module.exception.js +1 -1
- package/errors/exceptions/undefined-dependency.exception.js +1 -1
- package/errors/exceptions/undefined-forwardref.exception.js +1 -1
- package/errors/exceptions/undefined-module.exception.js +1 -1
- package/errors/exceptions/unknown-dependencies.exception.js +1 -1
- package/errors/exceptions/unknown-export.exception.js +1 -1
- package/errors/messages.js +3 -3
- package/exceptions/base-exception-filter-context.js +3 -3
- package/exceptions/base-exception-filter.js +6 -6
- package/exceptions/exceptions-handler.js +1 -1
- package/exceptions/external-exception-filter-context.js +2 -2
- package/exceptions/external-exceptions-handler.js +1 -1
- package/exceptions/index.js +1 -1
- package/guards/guards-consumer.js +2 -2
- package/guards/guards-context-creator.js +4 -4
- package/helpers/context-utils.js +1 -1
- package/helpers/external-context-creator.js +3 -3
- package/helpers/index.js +2 -2
- package/helpers/interfaces/index.js +2 -2
- package/hooks/before-app-shutdown.hook.js +5 -5
- package/hooks/index.js +5 -5
- package/hooks/on-app-bootstrap.hook.js +5 -5
- package/hooks/on-app-shutdown.hook.js +5 -5
- package/hooks/on-module-destroy.hook.js +5 -5
- package/hooks/on-module-init.hook.js +5 -5
- package/index.js +12 -12
- package/injector/compiler.js +1 -1
- package/injector/helpers/transient-instances.js +2 -2
- package/injector/index.js +5 -5
- package/injector/injector.js +13 -13
- package/injector/inquirer/index.js +1 -1
- package/injector/instance-links-host.js +1 -1
- package/injector/instance-loader.js +1 -1
- package/injector/instance-wrapper.js +7 -7
- package/injector/internal-core-module.js +3 -3
- package/injector/module-ref.js +1 -1
- package/injector/module-token-factory.js +4 -4
- package/injector/module.js +18 -18
- package/injector/modules-container.js +1 -1
- package/interceptors/interceptors-consumer.js +4 -4
- package/interceptors/interceptors-context-creator.js +4 -4
- package/metadata-scanner.js +4 -4
- package/middleware/builder.js +3 -3
- package/middleware/container.js +1 -1
- package/middleware/index.js +1 -1
- package/middleware/middleware-module.js +6 -6
- package/middleware/routes-mapper.js +6 -6
- package/middleware/utils.js +6 -6
- package/nest-application-context.js +8 -8
- package/nest-application.js +13 -13
- package/nest-factory.js +6 -6
- package/package.json +2 -2
- package/pipes/pipes-context-creator.js +4 -4
- package/router/index.js +2 -2
- package/router/interfaces/index.js +1 -1
- package/router/route-path-factory.js +8 -8
- package/router/router-exception-filters.js +2 -2
- package/router/router-execution-context.js +4 -4
- package/router/router-explorer.js +12 -12
- package/router/router-module.js +6 -6
- package/router/router-response-controller.js +6 -6
- package/router/routes-resolver.js +2 -2
- package/router/sse-stream.js +1 -1
- package/router/utils/exclude-route.util.js +1 -1
- package/router/utils/flatten-route-paths.util.js +2 -2
- package/router/utils/index.js +2 -2
- package/scanner.js +9 -9
- package/services/index.js +1 -1
- package/services/reflector.service.js +2 -2
package/injector/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./container"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./inquirer"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lazy-module-loader"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./module-ref"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./modules-container"), exports);
|
package/injector/injector.js
CHANGED
|
@@ -37,7 +37,7 @@ class Injector {
|
|
|
37
37
|
const token = wrapper.token || wrapper.name;
|
|
38
38
|
const { inject } = wrapper;
|
|
39
39
|
const targetWrapper = collection.get(token);
|
|
40
|
-
if (
|
|
40
|
+
if (shared_utils_1.isUndefined(targetWrapper)) {
|
|
41
41
|
throw new runtime_exception_1.RuntimeException();
|
|
42
42
|
}
|
|
43
43
|
if (instanceHost.isResolved) {
|
|
@@ -54,7 +54,7 @@ class Injector {
|
|
|
54
54
|
async loadMiddleware(wrapper, collection, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
55
55
|
const { metatype, token } = wrapper;
|
|
56
56
|
const targetWrapper = collection.get(token);
|
|
57
|
-
if (!
|
|
57
|
+
if (!shared_utils_1.isUndefined(targetWrapper.instance)) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
targetWrapper.instance = Object.create(metatype.prototype);
|
|
@@ -89,10 +89,10 @@ class Injector {
|
|
|
89
89
|
const deps = await this.loadCtorMetadata(metadata, contextId, inquirer, parentInquirer);
|
|
90
90
|
return callback(deps);
|
|
91
91
|
}
|
|
92
|
-
const dependencies =
|
|
92
|
+
const dependencies = shared_utils_1.isNil(inject)
|
|
93
93
|
? this.reflectConstructorParams(wrapper.metatype)
|
|
94
94
|
: inject;
|
|
95
|
-
const optionalDependenciesIds =
|
|
95
|
+
const optionalDependenciesIds = shared_utils_1.isNil(inject)
|
|
96
96
|
? this.reflectOptionalParams(wrapper.metatype)
|
|
97
97
|
: [];
|
|
98
98
|
let isResolved = true;
|
|
@@ -136,7 +136,7 @@ class Injector {
|
|
|
136
136
|
return Reflect.getMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, type) || [];
|
|
137
137
|
}
|
|
138
138
|
async resolveSingleParam(wrapper, param, dependencyContext, moduleRef, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
139
|
-
if (
|
|
139
|
+
if (shared_utils_1.isUndefined(param)) {
|
|
140
140
|
this.logger.log('Nest encountered an undefined dependency. This may be due to a circular import or a missing dependency declaration.');
|
|
141
141
|
throw new undefined_dependency_exception_1.UndefinedDependencyException(wrapper.name, dependencyContext, moduleRef);
|
|
142
142
|
}
|
|
@@ -198,7 +198,7 @@ class Injector {
|
|
|
198
198
|
}
|
|
199
199
|
async lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
|
|
200
200
|
const instanceWrapper = await this.lookupComponentInImports(moduleRef, dependencyContext.name, wrapper, [], contextId, inquirer, keyOrIndex);
|
|
201
|
-
if (
|
|
201
|
+
if (shared_utils_1.isNil(instanceWrapper)) {
|
|
202
202
|
throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef);
|
|
203
203
|
}
|
|
204
204
|
return instanceWrapper;
|
|
@@ -240,7 +240,7 @@ class Injector {
|
|
|
240
240
|
return instanceWrapperRef;
|
|
241
241
|
}
|
|
242
242
|
async resolveProperties(wrapper, moduleRef, inject, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
|
|
243
|
-
if (!
|
|
243
|
+
if (!shared_utils_1.isNil(inject)) {
|
|
244
244
|
return [];
|
|
245
245
|
}
|
|
246
246
|
const metadata = wrapper.getPropertiesMetadata();
|
|
@@ -280,11 +280,11 @@ class Injector {
|
|
|
280
280
|
return properties.map((item) => (Object.assign(Object.assign({}, item), { name: item.type, isOptional: optionalKeys.includes(item.key) })));
|
|
281
281
|
}
|
|
282
282
|
applyProperties(instance, properties) {
|
|
283
|
-
if (!
|
|
283
|
+
if (!shared_utils_1.isObject(instance)) {
|
|
284
284
|
return undefined;
|
|
285
285
|
}
|
|
286
|
-
|
|
287
|
-
.filter(item => !
|
|
286
|
+
iterare_1.iterate(properties)
|
|
287
|
+
.filter(item => !shared_utils_1.isNil(item.instance))
|
|
288
288
|
.forEach(item => (instance[item.key] = item.instance));
|
|
289
289
|
}
|
|
290
290
|
async instantiateClass(instances, wrapper, targetMetatype, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
@@ -295,7 +295,7 @@ class Injector {
|
|
|
295
295
|
wrapper.isInRequestScope(contextId, inquirer) ||
|
|
296
296
|
wrapper.isLazyTransient(contextId, inquirer) ||
|
|
297
297
|
wrapper.isExplicitlyRequested(contextId, inquirer);
|
|
298
|
-
if (
|
|
298
|
+
if (shared_utils_1.isNil(inject) && isInContext) {
|
|
299
299
|
instanceHost.instance = wrapper.forwardRef
|
|
300
300
|
? Object.assign(instanceHost.instance, new metatype(...instances))
|
|
301
301
|
: new metatype(...instances);
|
|
@@ -357,12 +357,12 @@ class Injector {
|
|
|
357
357
|
return param === inquirer_1.INQUIRER && parentInquirer;
|
|
358
358
|
}
|
|
359
359
|
addDependencyMetadata(keyOrIndex, hostWrapper, instanceWrapper) {
|
|
360
|
-
|
|
360
|
+
shared_utils_1.isString(keyOrIndex)
|
|
361
361
|
? hostWrapper.addPropertiesMetadata(keyOrIndex, instanceWrapper)
|
|
362
362
|
: hostWrapper.addCtorMetadata(keyOrIndex, instanceWrapper);
|
|
363
363
|
}
|
|
364
364
|
getTokenName(token) {
|
|
365
|
-
return
|
|
365
|
+
return shared_utils_1.isFunction(token) ? token.name : token.toString();
|
|
366
366
|
}
|
|
367
367
|
printResolvingDependenciesLog(token, inquirer) {
|
|
368
368
|
var _a, _b, _c;
|
|
@@ -48,7 +48,7 @@ class InstanceLinksHost {
|
|
|
48
48
|
}
|
|
49
49
|
getInstanceNameByToken(token) {
|
|
50
50
|
var _a;
|
|
51
|
-
return
|
|
51
|
+
return shared_utils_1.isFunction(token) ? (_a = token) === null || _a === void 0 ? void 0 : _a.name : token;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
exports.InstanceLinksHost = InstanceLinksHost;
|
|
@@ -31,7 +31,7 @@ class InstanceLoader {
|
|
|
31
31
|
await this.createInstancesOfControllers(moduleRef);
|
|
32
32
|
const { name } = moduleRef.metatype;
|
|
33
33
|
this.isModuleWhitelisted(name) &&
|
|
34
|
-
this.logger.log(
|
|
34
|
+
this.logger.log(messages_1.MODULE_INIT_MESSAGE `${name}`);
|
|
35
35
|
}));
|
|
36
36
|
}
|
|
37
37
|
createPrototypesOfProviders(moduleRef) {
|
|
@@ -16,7 +16,7 @@ class InstanceWrapper {
|
|
|
16
16
|
this.scope = common_1.Scope.DEFAULT;
|
|
17
17
|
this.values = new WeakMap();
|
|
18
18
|
this[_a] = {};
|
|
19
|
-
this[exports.INSTANCE_ID_SYMBOL] =
|
|
19
|
+
this[exports.INSTANCE_ID_SYMBOL] = random_string_generator_util_1.randomStringGenerator();
|
|
20
20
|
this.initialize(metadata);
|
|
21
21
|
}
|
|
22
22
|
get id() {
|
|
@@ -30,7 +30,7 @@ class InstanceWrapper {
|
|
|
30
30
|
return instancePerContext.instance;
|
|
31
31
|
}
|
|
32
32
|
get isNotMetatype() {
|
|
33
|
-
const isFactory = this.metatype && !
|
|
33
|
+
const isFactory = this.metatype && !shared_utils_1.isNil(this.inject);
|
|
34
34
|
return !this.metatype || isFactory;
|
|
35
35
|
}
|
|
36
36
|
get isTransient() {
|
|
@@ -101,7 +101,7 @@ class InstanceWrapper {
|
|
|
101
101
|
return this[exports.INSTANCE_METADATA_SYMBOL].enhancers;
|
|
102
102
|
}
|
|
103
103
|
isDependencyTreeStatic(lookupRegistry = []) {
|
|
104
|
-
if (!
|
|
104
|
+
if (!shared_utils_1.isUndefined(this.isTreeStatic)) {
|
|
105
105
|
return this.isTreeStatic;
|
|
106
106
|
}
|
|
107
107
|
if (this.scope === common_1.Scope.REQUEST) {
|
|
@@ -190,13 +190,13 @@ class InstanceWrapper {
|
|
|
190
190
|
return [];
|
|
191
191
|
}
|
|
192
192
|
const instances = [...this.transientMap.values()];
|
|
193
|
-
return
|
|
193
|
+
return iterare_1.iterate(instances)
|
|
194
194
|
.map(item => item.get(constants_1.STATIC_CONTEXT))
|
|
195
195
|
.filter(item => !!item)
|
|
196
196
|
.toArray();
|
|
197
197
|
}
|
|
198
198
|
mergeWith(provider) {
|
|
199
|
-
if (!
|
|
199
|
+
if (!shared_utils_1.isUndefined(provider.useValue)) {
|
|
200
200
|
this.metatype = null;
|
|
201
201
|
this.inject = null;
|
|
202
202
|
this.scope = common_1.Scope.DEFAULT;
|
|
@@ -216,13 +216,13 @@ class InstanceWrapper {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
isNewable() {
|
|
219
|
-
return
|
|
219
|
+
return shared_utils_1.isNil(this.inject) && this.metatype && this.metatype.prototype;
|
|
220
220
|
}
|
|
221
221
|
isWrapperListStatic(tree, lookupRegistry) {
|
|
222
222
|
return tree.every((item) => item.isDependencyTreeStatic(lookupRegistry));
|
|
223
223
|
}
|
|
224
224
|
initialize(metadata) {
|
|
225
|
-
const { instance, isResolved } = metadata, wrapperPartial =
|
|
225
|
+
const { instance, isResolved } = metadata, wrapperPartial = tslib_1.__rest(metadata, ["instance", "isResolved"]);
|
|
226
226
|
Object.assign(this, wrapperPartial);
|
|
227
227
|
this.setInstanceByContextId(constants_1.STATIC_CONTEXT, {
|
|
228
228
|
instance,
|
|
@@ -20,9 +20,9 @@ let InternalCoreModule = InternalCoreModule_1 = class InternalCoreModule {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
InternalCoreModule = InternalCoreModule_1 =
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
InternalCoreModule = InternalCoreModule_1 = tslib_1.__decorate([
|
|
24
|
+
common_1.Global(),
|
|
25
|
+
common_1.Module({
|
|
26
26
|
providers: [
|
|
27
27
|
services_1.Reflector,
|
|
28
28
|
ReflectorAliasProvider,
|
package/injector/module-ref.js
CHANGED
|
@@ -63,7 +63,7 @@ class ModuleRef {
|
|
|
63
63
|
name: type && type.name,
|
|
64
64
|
metatype: type,
|
|
65
65
|
isResolved: false,
|
|
66
|
-
scope:
|
|
66
|
+
scope: get_class_scope_1.getClassScope(type),
|
|
67
67
|
host: moduleRef,
|
|
68
68
|
});
|
|
69
69
|
return new Promise(async (resolve, reject) => {
|
|
@@ -23,7 +23,7 @@ class ModuleTokenFactory {
|
|
|
23
23
|
// The replacer function is also required in order to obtain real class names
|
|
24
24
|
// instead of the unified "Function" key
|
|
25
25
|
return dynamicModuleMetadata
|
|
26
|
-
?
|
|
26
|
+
? fast_safe_stringify_1.default(dynamicModuleMetadata, this.replacer)
|
|
27
27
|
: '';
|
|
28
28
|
}
|
|
29
29
|
getModuleId(metatype) {
|
|
@@ -31,7 +31,7 @@ class ModuleTokenFactory {
|
|
|
31
31
|
if (moduleId) {
|
|
32
32
|
return moduleId;
|
|
33
33
|
}
|
|
34
|
-
moduleId =
|
|
34
|
+
moduleId = random_string_generator_util_1.randomStringGenerator();
|
|
35
35
|
this.moduleIdsCache.set(metatype, moduleId);
|
|
36
36
|
return moduleId;
|
|
37
37
|
}
|
|
@@ -39,7 +39,7 @@ class ModuleTokenFactory {
|
|
|
39
39
|
return metatype.name;
|
|
40
40
|
}
|
|
41
41
|
replacer(key, value) {
|
|
42
|
-
if (
|
|
42
|
+
if (shared_utils_1.isFunction(value)) {
|
|
43
43
|
const funcAsString = value.toString();
|
|
44
44
|
const isClass = /^class\s/.test(funcAsString);
|
|
45
45
|
if (isClass) {
|
|
@@ -47,7 +47,7 @@ class ModuleTokenFactory {
|
|
|
47
47
|
}
|
|
48
48
|
return hash(funcAsString, { ignoreUnknown: true });
|
|
49
49
|
}
|
|
50
|
-
if (
|
|
50
|
+
if (shared_utils_1.isSymbol(value)) {
|
|
51
51
|
return value.toString();
|
|
52
52
|
}
|
|
53
53
|
return value;
|
package/injector/module.js
CHANGED
|
@@ -25,7 +25,7 @@ class Module {
|
|
|
25
25
|
this._exports = new Set();
|
|
26
26
|
this._distance = 0;
|
|
27
27
|
this.addCoreProviders();
|
|
28
|
-
this._id =
|
|
28
|
+
this._id = random_string_generator_util_1.randomStringGenerator();
|
|
29
29
|
}
|
|
30
30
|
get id() {
|
|
31
31
|
return this._id;
|
|
@@ -135,7 +135,7 @@ class Module {
|
|
|
135
135
|
metatype: injectable,
|
|
136
136
|
instance: null,
|
|
137
137
|
isResolved: false,
|
|
138
|
-
scope:
|
|
138
|
+
scope: get_class_scope_1.getClassScope(injectable),
|
|
139
139
|
host: this,
|
|
140
140
|
});
|
|
141
141
|
this._injectables.set(injectable, instanceWrapper);
|
|
@@ -155,13 +155,13 @@ class Module {
|
|
|
155
155
|
metatype: provider,
|
|
156
156
|
instance: null,
|
|
157
157
|
isResolved: false,
|
|
158
|
-
scope:
|
|
158
|
+
scope: get_class_scope_1.getClassScope(provider),
|
|
159
159
|
host: this,
|
|
160
160
|
}));
|
|
161
161
|
return provider;
|
|
162
162
|
}
|
|
163
163
|
isCustomProvider(provider) {
|
|
164
|
-
return !
|
|
164
|
+
return !shared_utils_1.isNil(provider.provide);
|
|
165
165
|
}
|
|
166
166
|
addCustomProvider(provider, collection) {
|
|
167
167
|
if (this.isCustomClass(provider)) {
|
|
@@ -179,16 +179,16 @@ class Module {
|
|
|
179
179
|
return provider.provide;
|
|
180
180
|
}
|
|
181
181
|
isCustomClass(provider) {
|
|
182
|
-
return !
|
|
182
|
+
return !shared_utils_1.isUndefined(provider.useClass);
|
|
183
183
|
}
|
|
184
184
|
isCustomValue(provider) {
|
|
185
|
-
return !
|
|
185
|
+
return !shared_utils_1.isUndefined(provider.useValue);
|
|
186
186
|
}
|
|
187
187
|
isCustomFactory(provider) {
|
|
188
|
-
return !
|
|
188
|
+
return !shared_utils_1.isUndefined(provider.useFactory);
|
|
189
189
|
}
|
|
190
190
|
isCustomUseExisting(provider) {
|
|
191
|
-
return !
|
|
191
|
+
return !shared_utils_1.isUndefined(provider.useExisting);
|
|
192
192
|
}
|
|
193
193
|
isDynamicModule(exported) {
|
|
194
194
|
return exported && exported.module;
|
|
@@ -196,8 +196,8 @@ class Module {
|
|
|
196
196
|
addCustomClass(provider, collection) {
|
|
197
197
|
let { scope } = provider;
|
|
198
198
|
const { useClass } = provider;
|
|
199
|
-
if (
|
|
200
|
-
scope =
|
|
199
|
+
if (shared_utils_1.isUndefined(scope)) {
|
|
200
|
+
scope = get_class_scope_1.getClassScope(useClass);
|
|
201
201
|
}
|
|
202
202
|
collection.set(provider.provide, new instance_wrapper_1.InstanceWrapper({
|
|
203
203
|
token: provider.provide,
|
|
@@ -255,7 +255,7 @@ class Module {
|
|
|
255
255
|
if (this.isCustomProvider(provider)) {
|
|
256
256
|
return this.addCustomExportedProvider(provider);
|
|
257
257
|
}
|
|
258
|
-
else if (
|
|
258
|
+
else if (shared_utils_1.isString(provider) || shared_utils_1.isSymbol(provider)) {
|
|
259
259
|
return addExportedUnit(provider);
|
|
260
260
|
}
|
|
261
261
|
else if (this.isDynamicModule(provider)) {
|
|
@@ -266,7 +266,7 @@ class Module {
|
|
|
266
266
|
}
|
|
267
267
|
addCustomExportedProvider(provider) {
|
|
268
268
|
const provide = provider.provide;
|
|
269
|
-
if (
|
|
269
|
+
if (shared_utils_1.isString(provide) || shared_utils_1.isSymbol(provide)) {
|
|
270
270
|
return this._exports.add(this.validateExportedProvider(provide));
|
|
271
271
|
}
|
|
272
272
|
this._exports.add(this.validateExportedProvider(provide));
|
|
@@ -275,14 +275,14 @@ class Module {
|
|
|
275
275
|
if (this._providers.has(token)) {
|
|
276
276
|
return token;
|
|
277
277
|
}
|
|
278
|
-
const imports =
|
|
278
|
+
const imports = iterare_1.iterate(this._imports.values())
|
|
279
279
|
.filter(item => !!item)
|
|
280
280
|
.map(({ metatype }) => metatype)
|
|
281
281
|
.filter(metatype => !!metatype)
|
|
282
282
|
.toArray();
|
|
283
283
|
if (!imports.includes(token)) {
|
|
284
284
|
const { name } = this.metatype;
|
|
285
|
-
const providerName =
|
|
285
|
+
const providerName = shared_utils_1.isFunction(token) ? token.name : token;
|
|
286
286
|
throw new unknown_export_exception_1.UnknownExportException(providerName, name);
|
|
287
287
|
}
|
|
288
288
|
return token;
|
|
@@ -294,7 +294,7 @@ class Module {
|
|
|
294
294
|
metatype: controller,
|
|
295
295
|
instance: null,
|
|
296
296
|
isResolved: false,
|
|
297
|
-
scope:
|
|
297
|
+
scope: get_class_scope_1.getClassScope(controller),
|
|
298
298
|
host: this,
|
|
299
299
|
}));
|
|
300
300
|
this.assignControllerUniqueId(controller);
|
|
@@ -304,7 +304,7 @@ class Module {
|
|
|
304
304
|
enumerable: false,
|
|
305
305
|
writable: false,
|
|
306
306
|
configurable: true,
|
|
307
|
-
value:
|
|
307
|
+
value: random_string_generator_util_1.randomStringGenerator(),
|
|
308
308
|
});
|
|
309
309
|
}
|
|
310
310
|
addRelatedModule(module) {
|
|
@@ -344,11 +344,11 @@ class Module {
|
|
|
344
344
|
? this.find(typeOrToken)
|
|
345
345
|
: this.find(typeOrToken, self);
|
|
346
346
|
}
|
|
347
|
-
resolve(typeOrToken, contextId =
|
|
347
|
+
resolve(typeOrToken, contextId = context_id_factory_1.createContextId(), options = { strict: true }) {
|
|
348
348
|
return this.resolvePerContext(typeOrToken, self, contextId, options);
|
|
349
349
|
}
|
|
350
350
|
async create(type) {
|
|
351
|
-
if (!(type &&
|
|
351
|
+
if (!(type && shared_utils_1.isFunction(type) && type.prototype)) {
|
|
352
352
|
throw new invalid_class_exception_1.InvalidClassException(type);
|
|
353
353
|
}
|
|
354
354
|
return this.instantiateClass(type, self);
|
|
@@ -7,18 +7,18 @@ const operators_1 = require("rxjs/operators");
|
|
|
7
7
|
const execution_context_host_1 = require("../helpers/execution-context-host");
|
|
8
8
|
class InterceptorsConsumer {
|
|
9
9
|
async intercept(interceptors, args, instance, callback, next, type) {
|
|
10
|
-
if (
|
|
10
|
+
if (shared_utils_1.isEmpty(interceptors)) {
|
|
11
11
|
return next();
|
|
12
12
|
}
|
|
13
13
|
const context = this.createContext(args, instance, callback);
|
|
14
14
|
context.setType(type);
|
|
15
|
-
const start$ =
|
|
15
|
+
const start$ = rxjs_1.defer(() => this.transformDeferred(next));
|
|
16
16
|
const nextFn = (i = 0) => async () => {
|
|
17
17
|
if (i >= interceptors.length) {
|
|
18
18
|
return start$;
|
|
19
19
|
}
|
|
20
20
|
const handler = {
|
|
21
|
-
handle: () =>
|
|
21
|
+
handle: () => rxjs_1.from(nextFn(i + 1)()).pipe(operators_1.mergeAll()),
|
|
22
22
|
};
|
|
23
23
|
return interceptors[i].intercept(context, handler);
|
|
24
24
|
};
|
|
@@ -28,7 +28,7 @@ class InterceptorsConsumer {
|
|
|
28
28
|
return new execution_context_host_1.ExecutionContextHost(args, instance.constructor, callback);
|
|
29
29
|
}
|
|
30
30
|
transformDeferred(next) {
|
|
31
|
-
return
|
|
31
|
+
return rxjs_1.from(next()).pipe(operators_1.switchMap(res => {
|
|
32
32
|
const isDeferred = res instanceof Promise || res instanceof rxjs_1.Observable;
|
|
33
33
|
return isDeferred ? res : Promise.resolve(res);
|
|
34
34
|
}));
|
|
@@ -17,13 +17,13 @@ class InterceptorsContextCreator extends context_creator_1.ContextCreator {
|
|
|
17
17
|
return this.createContext(instance, callback, constants_1.INTERCEPTORS_METADATA, contextId, inquirerId);
|
|
18
18
|
}
|
|
19
19
|
createConcreteContext(metadata, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
|
20
|
-
if (
|
|
20
|
+
if (shared_utils_1.isEmpty(metadata)) {
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return iterare_1.iterate(metadata)
|
|
24
24
|
.filter(interceptor => interceptor && (interceptor.name || interceptor.intercept))
|
|
25
25
|
.map(interceptor => this.getInterceptorInstance(interceptor, contextId, inquirerId))
|
|
26
|
-
.filter((interceptor) => interceptor &&
|
|
26
|
+
.filter((interceptor) => interceptor && shared_utils_1.isFunction(interceptor.intercept))
|
|
27
27
|
.toArray();
|
|
28
28
|
}
|
|
29
29
|
getInterceptorInstance(metatype, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
|
@@ -58,7 +58,7 @@ class InterceptorsContextCreator extends context_creator_1.ContextCreator {
|
|
|
58
58
|
return globalInterceptors;
|
|
59
59
|
}
|
|
60
60
|
const scopedInterceptorWrappers = this.config.getGlobalRequestInterceptors();
|
|
61
|
-
const scopedInterceptors =
|
|
61
|
+
const scopedInterceptors = iterare_1.iterate(scopedInterceptorWrappers)
|
|
62
62
|
.map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
|
|
63
63
|
.filter(host => !!host)
|
|
64
64
|
.map(host => host.instance)
|
package/metadata-scanner.js
CHANGED
|
@@ -6,9 +6,9 @@ const iterare_1 = require("iterare");
|
|
|
6
6
|
class MetadataScanner {
|
|
7
7
|
scanFromPrototype(instance, prototype, callback) {
|
|
8
8
|
const methodNames = new Set(this.getAllFilteredMethodNames(prototype));
|
|
9
|
-
return
|
|
9
|
+
return iterare_1.iterate(methodNames)
|
|
10
10
|
.map(callback)
|
|
11
|
-
.filter(metadata => !
|
|
11
|
+
.filter(metadata => !shared_utils_1.isNil(metadata))
|
|
12
12
|
.toArray();
|
|
13
13
|
}
|
|
14
14
|
*getAllFilteredMethodNames(prototype) {
|
|
@@ -17,10 +17,10 @@ class MetadataScanner {
|
|
|
17
17
|
if (descriptor.set || descriptor.get) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
return !
|
|
20
|
+
return !shared_utils_1.isConstructor(prop) && shared_utils_1.isFunction(prototype[prop]);
|
|
21
21
|
};
|
|
22
22
|
do {
|
|
23
|
-
yield*
|
|
23
|
+
yield* iterare_1.iterate(Object.getOwnPropertyNames(prototype))
|
|
24
24
|
.filter(isMethod)
|
|
25
25
|
.toArray();
|
|
26
26
|
} while ((prototype = Reflect.getPrototypeOf(prototype)) &&
|
package/middleware/builder.js
CHANGED
|
@@ -11,7 +11,7 @@ class MiddlewareBuilder {
|
|
|
11
11
|
this.middlewareCollection = new Set();
|
|
12
12
|
}
|
|
13
13
|
apply(...middleware) {
|
|
14
|
-
return new MiddlewareBuilder.ConfigProxy(this,
|
|
14
|
+
return new MiddlewareBuilder.ConfigProxy(this, dependencies_decorator_1.flatten(middleware));
|
|
15
15
|
}
|
|
16
16
|
build() {
|
|
17
17
|
return [...this.middlewareCollection];
|
|
@@ -38,7 +38,7 @@ MiddlewareBuilder.ConfigProxy = class {
|
|
|
38
38
|
const { middlewareCollection } = this.builder;
|
|
39
39
|
const forRoutes = this.getRoutesFlatList(routes);
|
|
40
40
|
const configuration = {
|
|
41
|
-
middleware:
|
|
41
|
+
middleware: utils_1.filterMiddleware(this.middleware, this.excludedRoutes, this.builder.getHttpAdapter()),
|
|
42
42
|
forRoutes,
|
|
43
43
|
};
|
|
44
44
|
middlewareCollection.add(configuration);
|
|
@@ -46,7 +46,7 @@ MiddlewareBuilder.ConfigProxy = class {
|
|
|
46
46
|
}
|
|
47
47
|
getRoutesFlatList(routes) {
|
|
48
48
|
const { routesMapper } = this.builder;
|
|
49
|
-
return
|
|
49
|
+
return iterare_1.iterate(routes)
|
|
50
50
|
.map(route => routesMapper.mapRouteToRouteInfo(route))
|
|
51
51
|
.flatten()
|
|
52
52
|
.toArray();
|
package/middleware/container.js
CHANGED
|
@@ -26,7 +26,7 @@ class MiddlewareContainer {
|
|
|
26
26
|
const insertMiddleware = (metatype) => {
|
|
27
27
|
const token = metatype;
|
|
28
28
|
middleware.set(token, new instance_wrapper_1.InstanceWrapper({
|
|
29
|
-
scope:
|
|
29
|
+
scope: get_class_scope_1.getClassScope(metatype),
|
|
30
30
|
name: token,
|
|
31
31
|
metatype,
|
|
32
32
|
token,
|
package/middleware/index.js
CHANGED
|
@@ -80,7 +80,7 @@ class MiddlewareModule {
|
|
|
80
80
|
for (const metatype of middlewareCollection) {
|
|
81
81
|
const collection = middlewareContainer.getMiddlewareCollection(moduleKey);
|
|
82
82
|
const instanceWrapper = collection.get(metatype);
|
|
83
|
-
if (
|
|
83
|
+
if (shared_utils_1.isUndefined(instanceWrapper)) {
|
|
84
84
|
throw new runtime_exception_1.RuntimeException();
|
|
85
85
|
}
|
|
86
86
|
if (instanceWrapper.isTransient) {
|
|
@@ -91,7 +91,7 @@ class MiddlewareModule {
|
|
|
91
91
|
}
|
|
92
92
|
async bindHandler(wrapper, applicationRef, method, path, moduleRef, collection) {
|
|
93
93
|
const { instance, metatype } = wrapper;
|
|
94
|
-
if (
|
|
94
|
+
if (shared_utils_1.isUndefined(instance === null || instance === void 0 ? void 0 : instance.use)) {
|
|
95
95
|
throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
|
|
96
96
|
}
|
|
97
97
|
const isStatic = wrapper.isDependencyTreeStatic();
|
|
@@ -135,11 +135,11 @@ class MiddlewareModule {
|
|
|
135
135
|
const prefix = this.config.getGlobalPrefix();
|
|
136
136
|
const excludedRoutes = this.config.getGlobalPrefixOptions().exclude;
|
|
137
137
|
if (Array.isArray(excludedRoutes) &&
|
|
138
|
-
|
|
139
|
-
path =
|
|
138
|
+
utils_1.isRouteExcluded(excludedRoutes, path, method)) {
|
|
139
|
+
path = shared_utils_1.addLeadingSlash(path);
|
|
140
140
|
}
|
|
141
141
|
else {
|
|
142
|
-
const basePath =
|
|
142
|
+
const basePath = shared_utils_1.addLeadingSlash(prefix);
|
|
143
143
|
if ((basePath === null || basePath === void 0 ? void 0 : basePath.endsWith('/')) && (path === null || path === void 0 ? void 0 : path.startsWith('/'))) {
|
|
144
144
|
// strip slash when a wildcard is being used
|
|
145
145
|
// and global prefix has been set
|
|
@@ -147,7 +147,7 @@ class MiddlewareModule {
|
|
|
147
147
|
}
|
|
148
148
|
path = basePath + path;
|
|
149
149
|
}
|
|
150
|
-
const isMethodAll =
|
|
150
|
+
const isMethodAll = utils_1.isRequestMethodAll(method);
|
|
151
151
|
const requestMethod = request_method_enum_1.RequestMethod[method];
|
|
152
152
|
const router = await applicationRef.createMiddlewareFactory(method);
|
|
153
153
|
router(path, isMethodAll
|
|
@@ -12,11 +12,11 @@ class RoutesMapper {
|
|
|
12
12
|
this.routerExplorer = new router_explorer_1.RouterExplorer(new metadata_scanner_1.MetadataScanner(), container);
|
|
13
13
|
}
|
|
14
14
|
mapRouteToRouteInfo(route) {
|
|
15
|
-
if (
|
|
15
|
+
if (shared_utils_1.isString(route)) {
|
|
16
16
|
const defaultRequestMethod = -1;
|
|
17
17
|
return [
|
|
18
18
|
{
|
|
19
|
-
path:
|
|
19
|
+
path: shared_utils_1.addLeadingSlash(route),
|
|
20
20
|
method: defaultRequestMethod,
|
|
21
21
|
},
|
|
22
22
|
];
|
|
@@ -25,7 +25,7 @@ class RoutesMapper {
|
|
|
25
25
|
if (this.isRouteInfo(routePathOrPaths, route)) {
|
|
26
26
|
return [
|
|
27
27
|
{
|
|
28
|
-
path:
|
|
28
|
+
path: shared_utils_1.addLeadingSlash(route.path),
|
|
29
29
|
method: route.method,
|
|
30
30
|
},
|
|
31
31
|
];
|
|
@@ -41,7 +41,7 @@ class RoutesMapper {
|
|
|
41
41
|
var _a;
|
|
42
42
|
return (_a = item.path) === null || _a === void 0 ? void 0 : _a.map(p => {
|
|
43
43
|
let path = modulePath !== null && modulePath !== void 0 ? modulePath : '';
|
|
44
|
-
path += this.normalizeGlobalPath(routePath) +
|
|
44
|
+
path += this.normalizeGlobalPath(routePath) + shared_utils_1.addLeadingSlash(p);
|
|
45
45
|
return {
|
|
46
46
|
path,
|
|
47
47
|
method: item.requestMethod,
|
|
@@ -52,10 +52,10 @@ class RoutesMapper {
|
|
|
52
52
|
.reduce(concatPaths, []);
|
|
53
53
|
}
|
|
54
54
|
isRouteInfo(path, objectOrClass) {
|
|
55
|
-
return
|
|
55
|
+
return shared_utils_1.isUndefined(path);
|
|
56
56
|
}
|
|
57
57
|
normalizeGlobalPath(path) {
|
|
58
|
-
const prefix =
|
|
58
|
+
const prefix = shared_utils_1.addLeadingSlash(path);
|
|
59
59
|
return prefix === '/' ? '' : prefix;
|
|
60
60
|
}
|
|
61
61
|
getRoutePath(route) {
|
package/middleware/utils.js
CHANGED
|
@@ -15,11 +15,11 @@ const mapToExcludeRoute = (routes) => {
|
|
|
15
15
|
};
|
|
16
16
|
exports.mapToExcludeRoute = mapToExcludeRoute;
|
|
17
17
|
const filterMiddleware = (middleware, routes, httpAdapter) => {
|
|
18
|
-
const excludedRoutes =
|
|
19
|
-
return
|
|
18
|
+
const excludedRoutes = exports.mapToExcludeRoute(routes);
|
|
19
|
+
return iterare_1.iterate([])
|
|
20
20
|
.concat(middleware)
|
|
21
21
|
.filter(shared_utils_1.isFunction)
|
|
22
|
-
.map((item) =>
|
|
22
|
+
.map((item) => exports.mapToClass(item, excludedRoutes, httpAdapter))
|
|
23
23
|
.toArray();
|
|
24
24
|
};
|
|
25
25
|
exports.filterMiddleware = filterMiddleware;
|
|
@@ -63,10 +63,10 @@ function isMiddlewareClass(middleware) {
|
|
|
63
63
|
const middlewareArr = middlewareStr.split(' ');
|
|
64
64
|
return (middlewareArr[0] === 'function' &&
|
|
65
65
|
/[A-Z]/.test((_a = middlewareArr[1]) === null || _a === void 0 ? void 0 : _a[0]) &&
|
|
66
|
-
|
|
66
|
+
shared_utils_1.isFunction((_b = middleware.prototype) === null || _b === void 0 ? void 0 : _b.use));
|
|
67
67
|
}
|
|
68
68
|
exports.isMiddlewareClass = isMiddlewareClass;
|
|
69
|
-
function assignToken(metatype, token =
|
|
69
|
+
function assignToken(metatype, token = uuid_1.v4()) {
|
|
70
70
|
Object.defineProperty(metatype, 'name', { value: token });
|
|
71
71
|
return metatype;
|
|
72
72
|
}
|
|
@@ -81,6 +81,6 @@ function isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter) {
|
|
|
81
81
|
const pathname = queryParamsIndex >= 0
|
|
82
82
|
? originalUrl.slice(0, queryParamsIndex)
|
|
83
83
|
: originalUrl;
|
|
84
|
-
return
|
|
84
|
+
return utils_1.isRouteExcluded(excludedRoutes, pathname, common_1.RequestMethod[reqMethod]);
|
|
85
85
|
}
|
|
86
86
|
exports.isMiddlewareRouteExcluded = isMiddlewareRouteExcluded;
|