@nestjs/core 11.1.15 → 12.0.0-alpha.0
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/adapters/http-adapter.d.ts +5 -3
- package/adapters/http-adapter.js +8 -5
- package/adapters/index.d.ts +1 -1
- package/adapters/index.js +1 -4
- package/application-config.d.ts +7 -4
- package/application-config.js +20 -15
- package/constants.d.ts +1 -1
- package/constants.js +10 -13
- package/discovery/discoverable-meta-host-collection.d.ts +3 -3
- package/discovery/discoverable-meta-host-collection.js +15 -19
- package/discovery/discovery-module.js +9 -12
- package/discovery/discovery-service.d.ts +4 -4
- package/discovery/discovery-service.js +17 -19
- package/discovery/index.d.ts +2 -2
- package/discovery/index.js +2 -5
- package/errors/exception-handler.js +3 -7
- package/errors/exceptions/circular-dependency.exception.d.ts +1 -1
- package/errors/exceptions/circular-dependency.exception.js +2 -6
- package/errors/exceptions/index.d.ts +8 -8
- package/errors/exceptions/index.js +8 -11
- package/errors/exceptions/invalid-class-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class-module.exception.js +4 -8
- package/errors/exceptions/invalid-class-scope.exception.d.ts +2 -2
- package/errors/exceptions/invalid-class-scope.exception.js +6 -10
- package/errors/exceptions/invalid-class.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class.exception.js +4 -8
- package/errors/exceptions/invalid-exception-filter.exception.d.ts +1 -1
- package/errors/exceptions/invalid-exception-filter.exception.js +4 -8
- package/errors/exceptions/invalid-middleware-configuration.exception.d.ts +1 -1
- package/errors/exceptions/invalid-middleware-configuration.exception.js +4 -8
- package/errors/exceptions/invalid-middleware.exception.d.ts +1 -1
- package/errors/exceptions/invalid-middleware.exception.js +4 -8
- package/errors/exceptions/invalid-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-module.exception.js +4 -8
- package/errors/exceptions/runtime.exception.js +1 -5
- package/errors/exceptions/undefined-dependency.exception.d.ts +3 -3
- package/errors/exceptions/undefined-dependency.exception.js +4 -8
- package/errors/exceptions/undefined-forwardref.exception.d.ts +2 -2
- package/errors/exceptions/undefined-forwardref.exception.js +4 -8
- package/errors/exceptions/undefined-module.exception.d.ts +1 -1
- package/errors/exceptions/undefined-module.exception.js +4 -8
- package/errors/exceptions/unknown-dependencies.exception.d.ts +3 -3
- package/errors/exceptions/unknown-dependencies.exception.js +8 -8
- package/errors/exceptions/unknown-element.exception.d.ts +1 -1
- package/errors/exceptions/unknown-element.exception.js +2 -6
- package/errors/exceptions/unknown-export.exception.d.ts +1 -1
- package/errors/exceptions/unknown-export.exception.js +4 -8
- package/errors/exceptions/unknown-module.exception.d.ts +1 -1
- package/errors/exceptions/unknown-module.exception.js +2 -6
- package/errors/exceptions/unknown-request-mapping.exception.d.ts +1 -1
- package/errors/exceptions/unknown-request-mapping.exception.js +4 -8
- package/errors/exceptions-zone.js +6 -10
- package/errors/messages.d.ts +2 -2
- package/errors/messages.js +19 -32
- package/exceptions/base-exception-filter-context.d.ts +6 -7
- package/exceptions/base-exception-filter-context.js +13 -16
- package/exceptions/base-exception-filter.d.ts +4 -4
- package/exceptions/base-exception-filter.js +33 -23
- package/exceptions/exceptions-handler.d.ts +4 -4
- package/exceptions/exceptions-handler.js +8 -16
- package/exceptions/external-exception-filter-context.d.ts +8 -8
- package/exceptions/external-exception-filter-context.js +14 -18
- package/exceptions/external-exception-filter.d.ts +1 -1
- package/exceptions/external-exception-filter.js +4 -8
- package/exceptions/external-exceptions-handler.d.ts +3 -3
- package/exceptions/external-exceptions-handler.js +8 -16
- package/exceptions/index.d.ts +1 -1
- package/exceptions/index.js +1 -4
- package/guards/constants.js +1 -4
- package/guards/guards-consumer.d.ts +4 -3
- package/guards/guards-consumer.js +8 -12
- package/guards/guards-context-creator.d.ts +11 -10
- package/guards/guards-context-creator.js +18 -20
- package/guards/index.d.ts +3 -3
- package/guards/index.js +3 -6
- package/helpers/barrier.js +5 -5
- package/helpers/context-creator.d.ts +2 -2
- package/helpers/context-creator.js +3 -7
- package/helpers/context-id-factory.d.ts +1 -1
- package/helpers/context-id-factory.js +10 -14
- package/helpers/context-utils.d.ts +6 -3
- package/helpers/context-utils.js +7 -12
- package/helpers/execution-context-host.d.ts +3 -3
- package/helpers/execution-context-host.js +5 -6
- package/helpers/external-context-creator.d.ts +15 -18
- package/helpers/external-context-creator.js +54 -43
- package/helpers/external-proxy.d.ts +2 -2
- package/helpers/external-proxy.js +3 -7
- package/helpers/get-class-scope.d.ts +2 -2
- package/helpers/get-class-scope.js +3 -6
- package/helpers/handler-metadata-storage.d.ts +4 -4
- package/helpers/handler-metadata-storage.js +7 -15
- package/helpers/http-adapter-host.d.ts +1 -1
- package/helpers/http-adapter-host.js +6 -11
- package/helpers/index.d.ts +3 -3
- package/helpers/index.js +3 -6
- package/helpers/interfaces/external-handler-metadata.interface.d.ts +2 -2
- package/helpers/interfaces/external-handler-metadata.interface.js +1 -2
- package/helpers/interfaces/index.d.ts +2 -2
- package/helpers/interfaces/index.js +2 -5
- package/helpers/interfaces/params-metadata.interface.d.ts +1 -1
- package/helpers/interfaces/params-metadata.interface.js +1 -2
- package/helpers/is-durable.d.ts +1 -1
- package/helpers/is-durable.js +3 -6
- package/helpers/load-adapter.d.ts +1 -1
- package/helpers/load-adapter.js +4 -7
- package/helpers/messages.d.ts +1 -1
- package/helpers/messages.js +10 -20
- package/helpers/optional-require.d.ts +1 -1
- package/helpers/optional-require.js +2 -5
- package/helpers/rethrow.js +1 -5
- package/helpers/router-method-factory.d.ts +2 -2
- package/helpers/router-method-factory.js +20 -24
- package/hooks/before-app-shutdown.hook.d.ts +3 -3
- package/hooks/before-app-shutdown.hook.js +15 -22
- package/hooks/index.d.ts +5 -5
- package/hooks/index.js +5 -8
- package/hooks/on-app-bootstrap.hook.d.ts +3 -3
- package/hooks/on-app-bootstrap.hook.js +15 -22
- package/hooks/on-app-shutdown.hook.d.ts +3 -3
- package/hooks/on-app-shutdown.hook.js +15 -22
- package/hooks/on-module-destroy.hook.d.ts +3 -3
- package/hooks/on-module-destroy.hook.js +15 -22
- package/hooks/on-module-init.hook.d.ts +3 -3
- package/hooks/on-module-init.hook.js +15 -22
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.d.ts +3 -0
- package/hooks/utils/get-instances-grouped-by-hierarchy-level.js +27 -0
- package/hooks/utils/get-sorted-hierarchy-levels.d.ts +1 -0
- package/hooks/utils/get-sorted-hierarchy-levels.js +7 -0
- package/index.d.ts +16 -16
- package/index.js +17 -26
- package/injector/abstract-instance-resolver.d.ts +6 -6
- package/injector/abstract-instance-resolver.js +7 -11
- package/injector/compiler.d.ts +2 -2
- package/injector/compiler.js +2 -5
- package/injector/constants.d.ts +1 -1
- package/injector/constants.js +2 -5
- package/injector/container.d.ts +13 -14
- package/injector/container.js +40 -40
- package/injector/helpers/provider-classifier.d.ts +1 -1
- package/injector/helpers/provider-classifier.js +5 -10
- package/injector/helpers/silent-logger.js +9 -16
- package/injector/index.d.ts +6 -6
- package/injector/index.js +5 -8
- package/injector/injector.d.ts +7 -6
- package/injector/injector.js +78 -78
- package/injector/inquirer/index.d.ts +1 -1
- package/injector/inquirer/index.js +1 -4
- package/injector/inquirer/inquirer-constants.js +1 -4
- package/injector/inquirer/inquirer-providers.d.ts +1 -1
- package/injector/inquirer/inquirer-providers.js +5 -8
- package/injector/instance-links-host.d.ts +3 -3
- package/injector/instance-links-host.js +8 -11
- package/injector/instance-loader.d.ts +5 -5
- package/injector/instance-loader.js +11 -11
- package/injector/instance-wrapper.d.ts +8 -5
- package/injector/instance-wrapper.js +93 -74
- package/injector/internal-core-module/index.d.ts +1 -1
- package/injector/internal-core-module/index.js +1 -4
- package/injector/internal-core-module/internal-core-module-factory.d.ts +6 -6
- package/injector/internal-core-module/internal-core-module-factory.js +23 -27
- package/injector/internal-core-module/internal-core-module.d.ts +2 -2
- package/injector/internal-core-module/internal-core-module.js +17 -20
- package/injector/internal-providers-storage.d.ts +2 -2
- package/injector/internal-providers-storage.js +4 -9
- package/injector/lazy-module-loader/lazy-module-loader-options.interface.js +1 -2
- package/injector/lazy-module-loader/lazy-module-loader.d.ts +8 -8
- package/injector/lazy-module-loader/lazy-module-loader.js +10 -9
- package/injector/module-ref.d.ts +7 -7
- package/injector/module-ref.js +19 -20
- package/injector/module.d.ts +5 -5
- package/injector/module.js +93 -79
- package/injector/modules-container.d.ts +1 -1
- package/injector/modules-container.js +5 -12
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +2 -4
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +6 -9
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +2 -3
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +17 -22
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +1 -3
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +1 -2
- package/injector/settlement-signal.js +5 -7
- package/injector/topology-tree/topology-tree.d.ts +1 -1
- package/injector/topology-tree/topology-tree.js +6 -9
- package/injector/topology-tree/tree-node.js +4 -6
- package/inspector/deterministic-uuid-registry.js +2 -6
- package/inspector/graph-inspector.d.ts +7 -7
- package/inspector/graph-inspector.js +10 -12
- package/inspector/index.d.ts +4 -4
- package/inspector/index.js +4 -7
- package/inspector/initialize-on-preview.allowlist.d.ts +1 -1
- package/inspector/initialize-on-preview.allowlist.js +2 -6
- package/inspector/interfaces/edge.interface.d.ts +1 -1
- package/inspector/interfaces/edge.interface.js +1 -2
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.d.ts +3 -3
- package/inspector/interfaces/enhancer-metadata-cache-entry.interface.js +1 -2
- package/inspector/interfaces/entrypoint.interface.d.ts +2 -2
- package/inspector/interfaces/entrypoint.interface.js +1 -2
- package/inspector/interfaces/extras.interface.d.ts +1 -1
- package/inspector/interfaces/extras.interface.js +1 -2
- package/inspector/interfaces/node.interface.d.ts +2 -2
- package/inspector/interfaces/node.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-json.interface.d.ts +6 -6
- package/inspector/interfaces/serialized-graph-json.interface.js +1 -2
- package/inspector/interfaces/serialized-graph-metadata.interface.d.ts +1 -1
- package/inspector/interfaces/serialized-graph-metadata.interface.js +1 -2
- package/inspector/noop-graph-inspector.d.ts +1 -1
- package/inspector/noop-graph-inspector.js +2 -5
- package/inspector/partial-graph.host.d.ts +2 -2
- package/inspector/partial-graph.host.js +2 -5
- package/inspector/serialized-graph.d.ts +7 -7
- package/inspector/serialized-graph.js +35 -40
- package/inspector/uuid-factory.js +8 -12
- package/interceptors/index.d.ts +2 -2
- package/interceptors/index.js +2 -5
- package/interceptors/interceptors-consumer.d.ts +4 -3
- package/interceptors/interceptors-consumer.js +13 -17
- package/interceptors/interceptors-context-creator.d.ts +10 -9
- package/interceptors/interceptors-context-creator.js +18 -20
- package/interfaces/index.d.ts +2 -0
- package/interfaces/index.js +2 -0
- package/interfaces/module-definition.interface.d.ts +2 -2
- package/interfaces/module-definition.interface.js +1 -2
- package/interfaces/module-override.interface.d.ts +1 -1
- package/interfaces/module-override.interface.js +1 -2
- package/internal.d.ts +38 -0
- package/internal.js +46 -0
- package/metadata-scanner.d.ts +1 -1
- package/metadata-scanner.js +8 -14
- package/middleware/builder.d.ts +4 -4
- package/middleware/builder.js +78 -76
- package/middleware/container.d.ts +4 -4
- package/middleware/container.js +10 -13
- package/middleware/index.d.ts +1 -1
- package/middleware/index.js +1 -4
- package/middleware/middleware-module.d.ts +8 -9
- package/middleware/middleware-module.js +47 -44
- package/middleware/resolver.d.ts +3 -3
- package/middleware/resolver.js +3 -5
- package/middleware/route-info-path-extractor.d.ts +2 -2
- package/middleware/route-info-path-extractor.js +26 -25
- package/middleware/routes-mapper.d.ts +4 -3
- package/middleware/routes-mapper.js +22 -24
- package/middleware/utils.d.ts +3 -2
- package/middleware/utils.js +34 -45
- package/nest-application-context.d.ts +10 -9
- package/nest-application-context.js +50 -47
- package/nest-application.d.ts +18 -10
- package/nest-application.js +87 -55
- package/nest-factory.d.ts +4 -5
- package/nest-factory.js +61 -68
- package/package.json +32 -3
- package/pipes/index.d.ts +3 -3
- package/pipes/index.js +3 -6
- package/pipes/params-token-factory.d.ts +2 -2
- package/pipes/params-token-factory.js +5 -9
- package/pipes/pipes-consumer.d.ts +3 -7
- package/pipes/pipes-consumer.js +17 -18
- package/pipes/pipes-context-creator.d.ts +10 -9
- package/pipes/pipes-context-creator.js +18 -20
- package/repl/assign-to-object.util.js +1 -4
- package/repl/constants.js +1 -4
- package/repl/index.d.ts +1 -1
- package/repl/index.js +1 -4
- package/repl/native-functions/debug-repl-fn.d.ts +2 -2
- package/repl/native-functions/debug-repl-fn.js +14 -21
- package/repl/native-functions/get-repl-fn.d.ts +2 -2
- package/repl/native-functions/get-repl-fn.js +8 -15
- package/repl/native-functions/help-repl-fn.d.ts +2 -2
- package/repl/native-functions/help-repl-fn.js +13 -20
- package/repl/native-functions/index.d.ts +6 -6
- package/repl/native-functions/index.js +6 -9
- package/repl/native-functions/methods-repl-fn.d.ts +2 -2
- package/repl/native-functions/methods-repl-fn.js +12 -19
- package/repl/native-functions/resolve-repl-fn.d.ts +2 -2
- package/repl/native-functions/resolve-repl-fn.js +7 -14
- package/repl/native-functions/select-relp-fn.d.ts +2 -2
- package/repl/native-functions/select-relp-fn.js +7 -14
- package/repl/repl-context.d.ts +3 -3
- package/repl/repl-context.js +21 -23
- package/repl/repl-function.d.ts +3 -3
- package/repl/repl-function.js +5 -7
- package/repl/repl-logger.js +10 -14
- package/repl/repl-native-commands.js +1 -4
- package/repl/repl.d.ts +1 -1
- package/repl/repl.interfaces.d.ts +2 -2
- package/repl/repl.interfaces.js +1 -2
- package/repl/repl.js +17 -20
- package/router/index.d.ts +3 -3
- package/router/index.js +3 -8
- package/router/interfaces/exceptions-filter.interface.d.ts +3 -3
- package/router/interfaces/exceptions-filter.interface.js +1 -2
- package/router/interfaces/exclude-route-metadata.interface.d.ts +1 -1
- package/router/interfaces/exclude-route-metadata.interface.js +1 -2
- package/router/interfaces/index.d.ts +1 -1
- package/router/interfaces/index.js +1 -4
- package/router/interfaces/resolver.interface.js +1 -2
- package/router/interfaces/route-params-factory.interface.d.ts +1 -1
- package/router/interfaces/route-params-factory.interface.js +1 -2
- package/router/interfaces/route-path-metadata.interface.d.ts +2 -2
- package/router/interfaces/route-path-metadata.interface.js +1 -2
- package/router/interfaces/routes.interface.d.ts +1 -1
- package/router/interfaces/routes.interface.js +1 -2
- package/router/legacy-route-converter.js +3 -7
- package/router/paths-explorer.d.ts +4 -5
- package/router/paths-explorer.js +11 -15
- package/router/request/index.d.ts +1 -1
- package/router/request/index.js +1 -5
- package/router/request/request-constants.js +2 -5
- package/router/request/request-providers.d.ts +1 -1
- package/router/request/request-providers.js +5 -8
- package/router/route-params-factory.d.ts +2 -2
- package/router/route-params-factory.js +15 -19
- package/router/route-path-factory.d.ts +4 -4
- package/router/route-path-factory.js +19 -22
- package/router/router-exception-filters.d.ts +9 -9
- package/router/router-exception-filters.js +15 -18
- package/router/router-execution-context.d.ts +17 -20
- package/router/router-execution-context.js +57 -49
- package/router/router-explorer.d.ts +14 -16
- package/router/router-explorer.js +55 -54
- package/router/router-module.d.ts +4 -4
- package/router/router-module.js +21 -23
- package/router/router-proxy.d.ts +1 -1
- package/router/router-proxy.js +4 -8
- package/router/router-response-controller.d.ts +2 -2
- package/router/router-response-controller.js +20 -23
- package/router/routes-resolver.d.ts +8 -9
- package/router/routes-resolver.js +36 -51
- package/router/sse-stream.d.ts +1 -1
- package/router/sse-stream.js +5 -9
- package/router/utils/exclude-route.util.d.ts +1 -1
- package/router/utils/exclude-route.util.js +7 -12
- package/router/utils/flatten-route-paths.util.d.ts +2 -2
- package/router/utils/flatten-route-paths.util.js +4 -7
- package/router/utils/index.d.ts +2 -2
- package/router/utils/index.js +2 -5
- package/scanner.d.ts +11 -11
- package/scanner.js +64 -65
- package/services/index.d.ts +1 -1
- package/services/index.js +1 -4
- package/services/reflector.service.d.ts +1 -1
- package/services/reflector.service.js +9 -13
- package/tsconfig.build.json +1 -9
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class RouterResponseController {
|
|
1
|
+
import { HttpStatus, Logger, RequestMethod, } from '@nestjs/common';
|
|
2
|
+
import { EMPTY, lastValueFrom, isObservable } from 'rxjs';
|
|
3
|
+
import { catchError, concatMap, map } from 'rxjs/operators';
|
|
4
|
+
import { SseStream, } from './sse-stream.js';
|
|
5
|
+
import { isObject } from '@nestjs/common/internal';
|
|
6
|
+
export class RouterResponseController {
|
|
7
|
+
applicationRef;
|
|
8
|
+
logger = new Logger(RouterResponseController.name);
|
|
10
9
|
constructor(applicationRef) {
|
|
11
10
|
this.applicationRef = applicationRef;
|
|
12
|
-
this.logger = new common_1.Logger(RouterResponseController.name);
|
|
13
11
|
}
|
|
14
12
|
async apply(result, response, httpStatusCode) {
|
|
15
13
|
return this.applicationRef.reply(response, result, httpStatusCode);
|
|
@@ -20,7 +18,7 @@ class RouterResponseController {
|
|
|
20
18
|
? result.statusCode
|
|
21
19
|
: redirectResponse.statusCode
|
|
22
20
|
? redirectResponse.statusCode
|
|
23
|
-
:
|
|
21
|
+
: HttpStatus.FOUND;
|
|
24
22
|
const url = result && result.url ? result.url : redirectResponse.url;
|
|
25
23
|
this.applicationRef.redirect(response, statusCode, url);
|
|
26
24
|
}
|
|
@@ -29,17 +27,17 @@ class RouterResponseController {
|
|
|
29
27
|
return this.applicationRef.render(response, template, result);
|
|
30
28
|
}
|
|
31
29
|
async transformToResult(resultOrDeferred) {
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
30
|
+
if (isObservable(resultOrDeferred)) {
|
|
31
|
+
return lastValueFrom(resultOrDeferred);
|
|
34
32
|
}
|
|
35
33
|
return resultOrDeferred;
|
|
36
34
|
}
|
|
37
35
|
getStatusByMethod(requestMethod) {
|
|
38
36
|
switch (requestMethod) {
|
|
39
|
-
case
|
|
40
|
-
return
|
|
37
|
+
case RequestMethod.POST:
|
|
38
|
+
return HttpStatus.CREATED;
|
|
41
39
|
default:
|
|
42
|
-
return
|
|
40
|
+
return HttpStatus.OK;
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
setHeaders(response, headers) {
|
|
@@ -55,7 +53,7 @@ class RouterResponseController {
|
|
|
55
53
|
}
|
|
56
54
|
const observableResult = await Promise.resolve(result);
|
|
57
55
|
this.assertObservable(observableResult);
|
|
58
|
-
const stream = new
|
|
56
|
+
const stream = new SseStream(request);
|
|
59
57
|
// Extract custom status code from response if it was set
|
|
60
58
|
const customStatusCode = response.statusCode;
|
|
61
59
|
const pipeOptions = typeof customStatusCode !== 'undefined'
|
|
@@ -63,19 +61,19 @@ class RouterResponseController {
|
|
|
63
61
|
: options;
|
|
64
62
|
stream.pipe(response, pipeOptions);
|
|
65
63
|
const subscription = observableResult
|
|
66
|
-
.pipe(
|
|
67
|
-
if (
|
|
64
|
+
.pipe(map((message) => {
|
|
65
|
+
if (isObject(message)) {
|
|
68
66
|
return message;
|
|
69
67
|
}
|
|
70
68
|
return { data: message };
|
|
71
|
-
}),
|
|
69
|
+
}), concatMap(message => new Promise(resolve => stream.writeMessage(message, () => resolve()))), catchError(err => {
|
|
72
70
|
const data = err instanceof Error ? err.message : err;
|
|
73
71
|
stream.writeMessage({ type: 'error', data }, writeError => {
|
|
74
72
|
if (writeError) {
|
|
75
73
|
this.logger.error(writeError);
|
|
76
74
|
}
|
|
77
75
|
});
|
|
78
|
-
return
|
|
76
|
+
return EMPTY;
|
|
79
77
|
}))
|
|
80
78
|
.subscribe({
|
|
81
79
|
complete: () => {
|
|
@@ -90,9 +88,8 @@ class RouterResponseController {
|
|
|
90
88
|
});
|
|
91
89
|
}
|
|
92
90
|
assertObservable(value) {
|
|
93
|
-
if (!
|
|
91
|
+
if (!isObservable(value)) {
|
|
94
92
|
throw new ReferenceError('You must return an Observable stream to use Server-Sent Events (SSE).');
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
|
-
exports.RouterResponseController = RouterResponseController;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { ApplicationConfig } from '../application-config.js';
|
|
2
|
+
import { NestContainer } from '../injector/container.js';
|
|
3
|
+
import { Injector } from '../injector/injector.js';
|
|
4
|
+
import { InstanceWrapper } from '../injector/instance-wrapper.js';
|
|
5
|
+
import { GraphInspector } from '../inspector/graph-inspector.js';
|
|
6
|
+
import { Resolver } from './interfaces/resolver.interface.js';
|
|
7
|
+
import { type Controller } from '@nestjs/common/internal';
|
|
8
|
+
import { type HttpServer } from '@nestjs/common';
|
|
8
9
|
export declare class RoutesResolver implements Resolver {
|
|
9
10
|
private readonly container;
|
|
10
11
|
private readonly applicationConfig;
|
|
@@ -19,8 +20,6 @@ export declare class RoutesResolver implements Resolver {
|
|
|
19
20
|
registerRouters(routes: Map<string | symbol | Function, InstanceWrapper<Controller>>, moduleName: string, globalPrefix: string, modulePath: string, applicationRef: HttpServer): void;
|
|
20
21
|
registerNotFoundHandler(): void;
|
|
21
22
|
registerExceptionHandler(): void;
|
|
22
|
-
mapExternalException(err: any): any;
|
|
23
|
-
private isHttpFastifyError;
|
|
24
23
|
private getModulePathMetadata;
|
|
25
24
|
private getHostMetadata;
|
|
26
25
|
private getVersionMetadata;
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { NotFoundException, } from '@nestjs/common';
|
|
2
|
+
import { CONTROLLER_MAPPING_MESSAGE, VERSIONED_CONTROLLER_MAPPING_MESSAGE, } from '../helpers/messages.js';
|
|
3
|
+
import { MetadataScanner } from '../metadata-scanner.js';
|
|
4
|
+
import { RoutePathFactory } from './route-path-factory.js';
|
|
5
|
+
import { RouterExceptionFilters } from './router-exception-filters.js';
|
|
6
|
+
import { RouterExplorer } from './router-explorer.js';
|
|
7
|
+
import { RouterProxy } from './router-proxy.js';
|
|
8
|
+
import { HOST_METADATA, MODULE_PATH, VERSION_METADATA, } from '@nestjs/common/internal';
|
|
9
|
+
import { Logger } from '@nestjs/common';
|
|
10
|
+
export class RoutesResolver {
|
|
11
|
+
container;
|
|
12
|
+
applicationConfig;
|
|
13
|
+
injector;
|
|
14
|
+
logger = new Logger(RoutesResolver.name, {
|
|
15
|
+
timestamp: true,
|
|
16
|
+
});
|
|
17
|
+
routerProxy = new RouterProxy();
|
|
18
|
+
routePathFactory;
|
|
19
|
+
routerExceptionsFilter;
|
|
20
|
+
routerExplorer;
|
|
14
21
|
constructor(container, applicationConfig, injector, graphInspector) {
|
|
15
22
|
this.container = container;
|
|
16
23
|
this.applicationConfig = applicationConfig;
|
|
17
24
|
this.injector = injector;
|
|
18
|
-
this.logger = new logger_service_1.Logger(RoutesResolver.name, {
|
|
19
|
-
timestamp: true,
|
|
20
|
-
});
|
|
21
|
-
this.routerProxy = new router_proxy_1.RouterProxy();
|
|
22
25
|
const httpAdapterRef = container.getHttpAdapterRef();
|
|
23
|
-
this.routerExceptionsFilter = new
|
|
24
|
-
this.routePathFactory = new
|
|
25
|
-
const metadataScanner = new
|
|
26
|
-
this.routerExplorer = new
|
|
26
|
+
this.routerExceptionsFilter = new RouterExceptionFilters(container, applicationConfig, httpAdapterRef);
|
|
27
|
+
this.routePathFactory = new RoutePathFactory(this.applicationConfig);
|
|
28
|
+
const metadataScanner = new MetadataScanner();
|
|
29
|
+
this.routerExplorer = new RouterExplorer(metadataScanner, this.container, this.injector, this.routerProxy, this.routerExceptionsFilter, this.applicationConfig, this.routePathFactory, graphInspector);
|
|
27
30
|
}
|
|
28
31
|
resolve(applicationRef, globalPrefix) {
|
|
29
32
|
const modules = this.container.getModules();
|
|
@@ -47,13 +50,13 @@ class RoutesResolver {
|
|
|
47
50
|
});
|
|
48
51
|
if (!controllerVersion) {
|
|
49
52
|
pathsToLog.forEach(path => {
|
|
50
|
-
const logMessage =
|
|
53
|
+
const logMessage = CONTROLLER_MAPPING_MESSAGE(controllerName, path);
|
|
51
54
|
this.logger.log(logMessage);
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
55
58
|
pathsToLog.forEach(path => {
|
|
56
|
-
const logMessage =
|
|
59
|
+
const logMessage = VERSIONED_CONTROLLER_MAPPING_MESSAGE(controllerName, path, controllerVersion);
|
|
57
60
|
this.logger.log(logMessage);
|
|
58
61
|
});
|
|
59
62
|
}
|
|
@@ -74,56 +77,38 @@ class RoutesResolver {
|
|
|
74
77
|
const callback = (req, res) => {
|
|
75
78
|
const method = applicationRef.getRequestMethod(req);
|
|
76
79
|
const url = applicationRef.getRequestUrl(req);
|
|
77
|
-
throw new
|
|
80
|
+
throw new NotFoundException(`Cannot ${method} ${url}`);
|
|
78
81
|
};
|
|
79
82
|
const handler = this.routerExceptionsFilter.create({}, callback, undefined);
|
|
80
83
|
const proxy = this.routerProxy.createProxy(callback, handler);
|
|
84
|
+
const prefix = this.applicationConfig.getGlobalPrefix();
|
|
81
85
|
applicationRef.setNotFoundHandler &&
|
|
82
|
-
applicationRef.setNotFoundHandler(proxy,
|
|
86
|
+
applicationRef.setNotFoundHandler(proxy, prefix);
|
|
83
87
|
}
|
|
84
88
|
registerExceptionHandler() {
|
|
85
89
|
const callback = (err, req, res, next) => {
|
|
86
|
-
throw this.
|
|
90
|
+
throw this.container.getHttpAdapterRef().mapException(err);
|
|
87
91
|
};
|
|
88
92
|
const handler = this.routerExceptionsFilter.create({}, callback, undefined);
|
|
89
93
|
const proxy = this.routerProxy.createExceptionLayerProxy(callback, handler);
|
|
90
94
|
const applicationRef = this.container.getHttpAdapterRef();
|
|
95
|
+
const prefix = this.applicationConfig.getGlobalPrefix();
|
|
91
96
|
applicationRef.setErrorHandler &&
|
|
92
|
-
applicationRef.setErrorHandler(proxy,
|
|
93
|
-
}
|
|
94
|
-
mapExternalException(err) {
|
|
95
|
-
switch (true) {
|
|
96
|
-
// SyntaxError is thrown by Express body-parser when given invalid JSON (#422, #430)
|
|
97
|
-
// URIError is thrown by Express when given a path parameter with an invalid percentage
|
|
98
|
-
// encoding, e.g. '%FF' (#8915)
|
|
99
|
-
case err instanceof SyntaxError || err instanceof URIError:
|
|
100
|
-
return new common_1.BadRequestException(err.message);
|
|
101
|
-
case this.isHttpFastifyError(err):
|
|
102
|
-
return new common_1.HttpException(err.message, err.statusCode);
|
|
103
|
-
default:
|
|
104
|
-
return err;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
isHttpFastifyError(error) {
|
|
108
|
-
// condition based on this code - https://github.com/fastify/fastify-error/blob/d669b150a82968322f9f7be992b2f6b463272de3/index.js#L22
|
|
109
|
-
return (error.statusCode !== undefined &&
|
|
110
|
-
error instanceof Error &&
|
|
111
|
-
error.name === 'FastifyError');
|
|
97
|
+
applicationRef.setErrorHandler(proxy, prefix);
|
|
112
98
|
}
|
|
113
99
|
getModulePathMetadata(metatype) {
|
|
114
100
|
const modulesContainer = this.container.getModules();
|
|
115
|
-
const modulePath = Reflect.getMetadata(
|
|
116
|
-
return modulePath ?? Reflect.getMetadata(
|
|
101
|
+
const modulePath = Reflect.getMetadata(MODULE_PATH + modulesContainer.applicationId, metatype);
|
|
102
|
+
return modulePath ?? Reflect.getMetadata(MODULE_PATH, metatype);
|
|
117
103
|
}
|
|
118
104
|
getHostMetadata(metatype) {
|
|
119
|
-
return Reflect.getMetadata(
|
|
105
|
+
return Reflect.getMetadata(HOST_METADATA, metatype);
|
|
120
106
|
}
|
|
121
107
|
getVersionMetadata(metatype) {
|
|
122
108
|
const versioningConfig = this.applicationConfig.getVersioning();
|
|
123
109
|
if (versioningConfig) {
|
|
124
|
-
return (Reflect.getMetadata(
|
|
110
|
+
return (Reflect.getMetadata(VERSION_METADATA, metatype) ??
|
|
125
111
|
versioningConfig.defaultVersion);
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
|
-
exports.RoutesResolver = RoutesResolver;
|
package/router/sse-stream.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MessageEvent } from '@nestjs/common/interfaces';
|
|
2
1
|
import { IncomingMessage, OutgoingHttpHeaders } from 'http';
|
|
3
2
|
import { Transform } from 'stream';
|
|
3
|
+
import type { MessageEvent } from '@nestjs/common';
|
|
4
4
|
export type AdditionalHeaders = Record<string, string[] | string | number | undefined>;
|
|
5
5
|
interface ReadHeaders {
|
|
6
6
|
getHeaders?(): AdditionalHeaders;
|
package/router/sse-stream.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SseStream = void 0;
|
|
4
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
|
-
const stream_1 = require("stream");
|
|
1
|
+
import { Transform } from 'stream';
|
|
2
|
+
import { isObject } from '@nestjs/common/internal';
|
|
6
3
|
function toDataString(data) {
|
|
7
|
-
if (
|
|
4
|
+
if (isObject(data)) {
|
|
8
5
|
return toDataString(JSON.stringify(data));
|
|
9
6
|
}
|
|
10
7
|
return data
|
|
@@ -25,10 +22,10 @@ function toDataString(data) {
|
|
|
25
22
|
* If constructed with a HTTP Request, it will optimise the socket for streaming.
|
|
26
23
|
* If this stream is piped to an HTTP Response, it will set appropriate headers.
|
|
27
24
|
*/
|
|
28
|
-
class SseStream extends
|
|
25
|
+
export class SseStream extends Transform {
|
|
26
|
+
lastEventId = null;
|
|
29
27
|
constructor(req) {
|
|
30
28
|
super({ objectMode: true });
|
|
31
|
-
this.lastEventId = null;
|
|
32
29
|
if (req && req.socket) {
|
|
33
30
|
req.socket.setKeepAlive(true);
|
|
34
31
|
req.socket.setNoDelay(true);
|
|
@@ -80,4 +77,3 @@ class SseStream extends stream_1.Transform {
|
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
exports.SseStream = SseStream;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { RequestMethod } from '@nestjs/common';
|
|
2
|
-
import { ExcludeRouteMetadata } from '../interfaces/exclude-route-metadata.interface';
|
|
2
|
+
import { ExcludeRouteMetadata } from '../interfaces/exclude-route-metadata.interface.js';
|
|
3
3
|
export declare const isRequestMethodAll: (method: RequestMethod) => boolean;
|
|
4
4
|
export declare function isRouteExcluded(excludedRoutes: ExcludeRouteMetadata[], path: string, requestMethod?: RequestMethod): boolean;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
|
-
const isRequestMethodAll = (method) => {
|
|
8
|
-
return common_1.RequestMethod.ALL === method || method === -1;
|
|
1
|
+
import { RequestMethod } from '@nestjs/common';
|
|
2
|
+
import { addLeadingSlash } from '@nestjs/common/internal';
|
|
3
|
+
export const isRequestMethodAll = (method) => {
|
|
4
|
+
return RequestMethod.ALL === method || method === -1;
|
|
9
5
|
};
|
|
10
|
-
|
|
11
|
-
function isRouteExcluded(excludedRoutes, path, requestMethod) {
|
|
6
|
+
export function isRouteExcluded(excludedRoutes, path, requestMethod) {
|
|
12
7
|
return excludedRoutes.some(route => {
|
|
13
|
-
if (
|
|
8
|
+
if (isRequestMethodAll(route.requestMethod) ||
|
|
14
9
|
route.requestMethod === requestMethod) {
|
|
15
|
-
return route.pathRegex.exec(
|
|
10
|
+
return route.pathRegex.exec(addLeadingSlash(path));
|
|
16
11
|
}
|
|
17
12
|
return false;
|
|
18
13
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from '@nestjs/common';
|
|
2
|
-
import { Routes } from '../interfaces/routes.interface';
|
|
1
|
+
import type { Type } from '@nestjs/common';
|
|
2
|
+
import { Routes } from '../interfaces/routes.interface.js';
|
|
3
3
|
export declare function flattenRoutePaths(routes: Routes): {
|
|
4
4
|
module: Type;
|
|
5
5
|
path: string;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.flattenRoutePaths = flattenRoutePaths;
|
|
4
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
|
-
function flattenRoutePaths(routes) {
|
|
1
|
+
import { isString, normalizePath } from '@nestjs/common/internal';
|
|
2
|
+
export function flattenRoutePaths(routes) {
|
|
6
3
|
const result = [];
|
|
7
4
|
routes.forEach(item => {
|
|
8
5
|
if (item.module && item.path) {
|
|
@@ -11,8 +8,8 @@ function flattenRoutePaths(routes) {
|
|
|
11
8
|
if (item.children) {
|
|
12
9
|
const childrenRef = item.children;
|
|
13
10
|
childrenRef.forEach(child => {
|
|
14
|
-
if (!
|
|
15
|
-
child.path =
|
|
11
|
+
if (!isString(child) && isString(child.path)) {
|
|
12
|
+
child.path = normalizePath(normalizePath(item.path) + normalizePath(child.path));
|
|
16
13
|
}
|
|
17
14
|
else {
|
|
18
15
|
result.push({ path: item.path, module: child });
|
package/router/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './exclude-route.util';
|
|
2
|
-
export * from './flatten-route-paths.util';
|
|
1
|
+
export * from './exclude-route.util.js';
|
|
2
|
+
export * from './flatten-route-paths.util.js';
|
package/router/utils/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./exclude-route.util"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./flatten-route-paths.util"), exports);
|
|
1
|
+
export * from './exclude-route.util.js';
|
|
2
|
+
export * from './flatten-route-paths.util.js';
|
package/scanner.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DynamicModule, ForwardReference, Provider } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import type { DynamicModule, ForwardReference, Provider } from '@nestjs/common';
|
|
2
|
+
import { ApplicationConfig } from './application-config.js';
|
|
3
|
+
import { NestContainer } from './injector/container.js';
|
|
4
|
+
import { InstanceWrapper } from './injector/instance-wrapper.js';
|
|
5
|
+
import { Module } from './injector/module.js';
|
|
6
|
+
import { GraphInspector } from './inspector/graph-inspector.js';
|
|
7
|
+
import { ModuleDefinition } from './interfaces/module-definition.interface.js';
|
|
8
|
+
import { ModuleOverride } from './interfaces/module-override.interface.js';
|
|
9
|
+
import { MetadataScanner } from './metadata-scanner.js';
|
|
10
|
+
import { type EnhancerSubtype, type Controller, type Injectable } from '@nestjs/common/internal';
|
|
11
|
+
import { type ClassProvider, type ExistingProvider, type FactoryProvider, type Type, type ValueProvider } from '@nestjs/common';
|
|
12
12
|
interface ModulesScanParameters {
|
|
13
13
|
moduleDefinition: ModuleDefinition;
|
|
14
14
|
scope?: Type<unknown>[];
|