@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,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const invalid_exception_filter_exception_1 = require("../errors/exceptions/invalid-exception-filter.exception");
|
|
7
|
-
const base_exception_filter_1 = require("./base-exception-filter");
|
|
8
|
-
class ExceptionsHandler extends base_exception_filter_1.BaseExceptionFilter {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.filters = [];
|
|
12
|
-
}
|
|
1
|
+
import { InvalidExceptionFilterException } from '../errors/exceptions/invalid-exception-filter.exception.js';
|
|
2
|
+
import { BaseExceptionFilter } from './base-exception-filter.js';
|
|
3
|
+
import { selectExceptionFilterMetadata, isEmptyArray, } from '@nestjs/common/internal';
|
|
4
|
+
export class ExceptionsHandler extends BaseExceptionFilter {
|
|
5
|
+
filters = [];
|
|
13
6
|
next(exception, ctx) {
|
|
14
7
|
if (this.invokeCustomFilters(exception, ctx)) {
|
|
15
8
|
return;
|
|
@@ -18,17 +11,16 @@ class ExceptionsHandler extends base_exception_filter_1.BaseExceptionFilter {
|
|
|
18
11
|
}
|
|
19
12
|
setCustomFilters(filters) {
|
|
20
13
|
if (!Array.isArray(filters)) {
|
|
21
|
-
throw new
|
|
14
|
+
throw new InvalidExceptionFilterException();
|
|
22
15
|
}
|
|
23
16
|
this.filters = filters;
|
|
24
17
|
}
|
|
25
18
|
invokeCustomFilters(exception, ctx) {
|
|
26
|
-
if ((
|
|
19
|
+
if (isEmptyArray(this.filters)) {
|
|
27
20
|
return false;
|
|
28
21
|
}
|
|
29
|
-
const filter =
|
|
22
|
+
const filter = selectExceptionFilterMetadata(this.filters, exception);
|
|
30
23
|
filter && filter.func(exception, ctx);
|
|
31
24
|
return !!filter;
|
|
32
25
|
}
|
|
33
26
|
}
|
|
34
|
-
exports.ExceptionsHandler = ExceptionsHandler;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { ApplicationConfig } from '../application-config.js';
|
|
2
|
+
import { NestContainer } from '../injector/container.js';
|
|
3
|
+
import { RouterProxyCallback } from '../router/router-proxy.js';
|
|
4
|
+
import { BaseExceptionFilterContext } from './base-exception-filter-context.js';
|
|
5
|
+
import { ExternalExceptionsHandler } from './external-exceptions-handler.js';
|
|
6
|
+
import { type Controller } from '@nestjs/common/internal';
|
|
7
7
|
export declare class ExternalExceptionFilterContext extends BaseExceptionFilterContext {
|
|
8
8
|
private readonly config?;
|
|
9
9
|
constructor(container: NestContainer, config?: ApplicationConfig | undefined);
|
|
10
|
-
create(instance: Controller, callback: RouterProxyCallback, module: string, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): ExternalExceptionsHandler;
|
|
11
|
-
getGlobalMetadata<T extends any[]>(contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): T;
|
|
10
|
+
create(instance: Controller, callback: RouterProxyCallback, module: string, contextId?: import("../injector/instance-wrapper.js").ContextId, inquirerId?: string): ExternalExceptionsHandler;
|
|
11
|
+
getGlobalMetadata<T extends any[]>(contextId?: import("../injector/instance-wrapper.js").ContextId, inquirerId?: string): T;
|
|
12
12
|
}
|
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const base_exception_filter_context_1 = require("./base-exception-filter-context");
|
|
9
|
-
const external_exceptions_handler_1 = require("./external-exceptions-handler");
|
|
10
|
-
class ExternalExceptionFilterContext extends base_exception_filter_context_1.BaseExceptionFilterContext {
|
|
1
|
+
import { iterate } from 'iterare';
|
|
2
|
+
import { STATIC_CONTEXT } from '../injector/constants.js';
|
|
3
|
+
import { BaseExceptionFilterContext } from './base-exception-filter-context.js';
|
|
4
|
+
import { ExternalExceptionsHandler } from './external-exceptions-handler.js';
|
|
5
|
+
import { EXCEPTION_FILTERS_METADATA, isEmptyArray, } from '@nestjs/common/internal';
|
|
6
|
+
export class ExternalExceptionFilterContext extends BaseExceptionFilterContext {
|
|
7
|
+
config;
|
|
11
8
|
constructor(container, config) {
|
|
12
9
|
super(container);
|
|
13
10
|
this.config = config;
|
|
14
11
|
}
|
|
15
|
-
create(instance, callback, module, contextId =
|
|
12
|
+
create(instance, callback, module, contextId = STATIC_CONTEXT, inquirerId) {
|
|
16
13
|
this.moduleContext = module;
|
|
17
|
-
const exceptionHandler = new
|
|
18
|
-
const filters = this.createContext(instance, callback,
|
|
19
|
-
if ((
|
|
14
|
+
const exceptionHandler = new ExternalExceptionsHandler();
|
|
15
|
+
const filters = this.createContext(instance, callback, EXCEPTION_FILTERS_METADATA, contextId, inquirerId);
|
|
16
|
+
if (isEmptyArray(filters)) {
|
|
20
17
|
return exceptionHandler;
|
|
21
18
|
}
|
|
22
19
|
exceptionHandler.setCustomFilters(filters.reverse());
|
|
23
20
|
return exceptionHandler;
|
|
24
21
|
}
|
|
25
|
-
getGlobalMetadata(contextId =
|
|
22
|
+
getGlobalMetadata(contextId = STATIC_CONTEXT, inquirerId) {
|
|
26
23
|
if (!this.config) {
|
|
27
24
|
return [];
|
|
28
25
|
}
|
|
29
26
|
const globalFilters = this.config.getGlobalFilters();
|
|
30
|
-
if (contextId ===
|
|
27
|
+
if (contextId === STATIC_CONTEXT && !inquirerId) {
|
|
31
28
|
return globalFilters;
|
|
32
29
|
}
|
|
33
30
|
const scopedFilterWrappers = this.config.getGlobalRequestFilters();
|
|
34
|
-
const scopedFilters =
|
|
31
|
+
const scopedFilters = iterate(scopedFilterWrappers)
|
|
35
32
|
.map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
|
|
36
33
|
.filter(host => !!host)
|
|
37
34
|
.map(host => host.instance)
|
|
@@ -39,4 +36,3 @@ class ExternalExceptionFilterContext extends base_exception_filter_context_1.Bas
|
|
|
39
36
|
return globalFilters.concat(scopedFilters);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
exports.ExternalExceptionFilterContext = ExternalExceptionFilterContext;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
class ExternalExceptionFilter {
|
|
1
|
+
import { IntrinsicException, Logger } from '@nestjs/common';
|
|
2
|
+
export class ExternalExceptionFilter {
|
|
3
|
+
static logger = new Logger('ExceptionsHandler');
|
|
6
4
|
catch(exception, host) {
|
|
7
5
|
if (exception instanceof Error &&
|
|
8
|
-
!(exception instanceof
|
|
6
|
+
!(exception instanceof IntrinsicException)) {
|
|
9
7
|
ExternalExceptionFilter.logger.error(exception);
|
|
10
8
|
}
|
|
11
9
|
throw exception;
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
exports.ExternalExceptionFilter = ExternalExceptionFilter;
|
|
15
|
-
ExternalExceptionFilter.logger = new common_1.Logger('ExceptionsHandler');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ExternalExceptionFilter } from './external-exception-filter.js';
|
|
2
|
+
import { type ExceptionFilterMetadata } from '@nestjs/common/internal';
|
|
3
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
4
4
|
export declare class ExternalExceptionsHandler extends ExternalExceptionFilter {
|
|
5
5
|
private filters;
|
|
6
6
|
next(exception: Error, host: ArgumentsHost): Promise<any>;
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const invalid_exception_filter_exception_1 = require("../errors/exceptions/invalid-exception-filter.exception");
|
|
7
|
-
const external_exception_filter_1 = require("./external-exception-filter");
|
|
8
|
-
class ExternalExceptionsHandler extends external_exception_filter_1.ExternalExceptionFilter {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.filters = [];
|
|
12
|
-
}
|
|
1
|
+
import { InvalidExceptionFilterException } from '../errors/exceptions/invalid-exception-filter.exception.js';
|
|
2
|
+
import { ExternalExceptionFilter } from './external-exception-filter.js';
|
|
3
|
+
import { selectExceptionFilterMetadata, isEmptyArray, } from '@nestjs/common/internal';
|
|
4
|
+
export class ExternalExceptionsHandler extends ExternalExceptionFilter {
|
|
5
|
+
filters = [];
|
|
13
6
|
next(exception, host) {
|
|
14
7
|
const result = this.invokeCustomFilters(exception, host);
|
|
15
8
|
if (result) {
|
|
@@ -19,16 +12,15 @@ class ExternalExceptionsHandler extends external_exception_filter_1.ExternalExce
|
|
|
19
12
|
}
|
|
20
13
|
setCustomFilters(filters) {
|
|
21
14
|
if (!Array.isArray(filters)) {
|
|
22
|
-
throw new
|
|
15
|
+
throw new InvalidExceptionFilterException();
|
|
23
16
|
}
|
|
24
17
|
this.filters = filters;
|
|
25
18
|
}
|
|
26
19
|
invokeCustomFilters(exception, host) {
|
|
27
|
-
if ((
|
|
20
|
+
if (isEmptyArray(this.filters)) {
|
|
28
21
|
return null;
|
|
29
22
|
}
|
|
30
|
-
const filter =
|
|
23
|
+
const filter = selectExceptionFilterMetadata(this.filters, exception);
|
|
31
24
|
return filter ? filter.func(exception, host) : null;
|
|
32
25
|
}
|
|
33
26
|
}
|
|
34
|
-
exports.ExternalExceptionsHandler = ExternalExceptionsHandler;
|
package/exceptions/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './base-exception-filter';
|
|
1
|
+
export * from './base-exception-filter.js';
|
package/exceptions/index.js
CHANGED
package/guards/constants.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { CanActivate } from '@nestjs/common';
|
|
2
|
-
import { ContextType, Controller } from '@nestjs/common/interfaces';
|
|
1
|
+
import type { CanActivate } from '@nestjs/common';
|
|
3
2
|
import { Observable } from 'rxjs';
|
|
4
|
-
import { ExecutionContextHost } from '../helpers/execution-context-host';
|
|
3
|
+
import { ExecutionContextHost } from '../helpers/execution-context-host.js';
|
|
4
|
+
import type { ContextType } from '@nestjs/common';
|
|
5
|
+
import { type Controller } from '@nestjs/common/internal';
|
|
5
6
|
export declare class GuardsConsumer {
|
|
6
7
|
tryActivate<TContext extends string = ContextType>(guards: CanActivate[], args: unknown[], instance: Controller, callback: (...args: unknown[]) => unknown, type?: TContext): Promise<boolean>;
|
|
7
8
|
createContext(args: unknown[], instance: Controller, callback: (...args: unknown[]) => unknown): ExecutionContextHost;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
|
-
const execution_context_host_1 = require("../helpers/execution-context-host");
|
|
7
|
-
class GuardsConsumer {
|
|
1
|
+
import { lastValueFrom, Observable } from 'rxjs';
|
|
2
|
+
import { ExecutionContextHost } from '../helpers/execution-context-host.js';
|
|
3
|
+
import { isEmptyArray } from '@nestjs/common/internal';
|
|
4
|
+
export class GuardsConsumer {
|
|
8
5
|
async tryActivate(guards, args, instance, callback, type) {
|
|
9
|
-
if (!guards || (
|
|
6
|
+
if (!guards || isEmptyArray(guards)) {
|
|
10
7
|
return true;
|
|
11
8
|
}
|
|
12
9
|
const context = this.createContext(args, instance, callback);
|
|
@@ -27,13 +24,12 @@ class GuardsConsumer {
|
|
|
27
24
|
return true;
|
|
28
25
|
}
|
|
29
26
|
createContext(args, instance, callback) {
|
|
30
|
-
return new
|
|
27
|
+
return new ExecutionContextHost(args, instance.constructor, callback);
|
|
31
28
|
}
|
|
32
29
|
async pickResult(result) {
|
|
33
|
-
if (result instanceof
|
|
34
|
-
return
|
|
30
|
+
if (result instanceof Observable) {
|
|
31
|
+
return lastValueFrom(result);
|
|
35
32
|
}
|
|
36
33
|
return result;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
exports.GuardsConsumer = GuardsConsumer;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { CanActivate } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import type { CanActivate } from '@nestjs/common';
|
|
2
|
+
import { ApplicationConfig } from '../application-config.js';
|
|
3
|
+
import { ContextCreator } from '../helpers/context-creator.js';
|
|
4
|
+
import { NestContainer } from '../injector/container.js';
|
|
5
|
+
import { InstanceWrapper } from '../injector/instance-wrapper.js';
|
|
6
|
+
import { type Controller } from '@nestjs/common/internal';
|
|
7
|
+
import type { Type } from '@nestjs/common';
|
|
7
8
|
export declare class GuardsContextCreator extends ContextCreator {
|
|
8
9
|
private readonly container;
|
|
9
10
|
private readonly config?;
|
|
10
11
|
private moduleContext;
|
|
11
12
|
constructor(container: NestContainer, config?: ApplicationConfig | undefined);
|
|
12
|
-
create(instance: Controller, callback: (...args: unknown[]) => unknown, module: string, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): CanActivate[];
|
|
13
|
-
createConcreteContext<T extends unknown[], R extends unknown[]>(metadata: T, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): R;
|
|
14
|
-
getGuardInstance(metatype: Function | CanActivate, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): CanActivate | null;
|
|
13
|
+
create(instance: Controller, callback: (...args: unknown[]) => unknown, module: string, contextId?: import("../injector/instance-wrapper.js").ContextId, inquirerId?: string): CanActivate[];
|
|
14
|
+
createConcreteContext<T extends unknown[], R extends unknown[]>(metadata: T, contextId?: import("../injector/instance-wrapper.js").ContextId, inquirerId?: string): R;
|
|
15
|
+
getGuardInstance(metatype: Function | CanActivate, contextId?: import("../injector/instance-wrapper.js").ContextId, inquirerId?: string): CanActivate | null;
|
|
15
16
|
getInstanceByMetatype(metatype: Type<unknown>): InstanceWrapper | undefined;
|
|
16
|
-
getGlobalMetadata<T extends unknown[]>(contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): T;
|
|
17
|
+
getGlobalMetadata<T extends unknown[]>(contextId?: import("../injector/instance-wrapper.js").ContextId, inquirerId?: string): T;
|
|
17
18
|
}
|
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class GuardsContextCreator extends context_creator_1.ContextCreator {
|
|
1
|
+
import { iterate } from 'iterare';
|
|
2
|
+
import { ContextCreator } from '../helpers/context-creator.js';
|
|
3
|
+
import { STATIC_CONTEXT } from '../injector/constants.js';
|
|
4
|
+
import { GUARDS_METADATA, isEmpty, isFunction, } from '@nestjs/common/internal';
|
|
5
|
+
export class GuardsContextCreator extends ContextCreator {
|
|
6
|
+
container;
|
|
7
|
+
config;
|
|
8
|
+
moduleContext;
|
|
10
9
|
constructor(container, config) {
|
|
11
10
|
super();
|
|
12
11
|
this.container = container;
|
|
13
12
|
this.config = config;
|
|
14
13
|
}
|
|
15
|
-
create(instance, callback, module, contextId =
|
|
14
|
+
create(instance, callback, module, contextId = STATIC_CONTEXT, inquirerId) {
|
|
16
15
|
this.moduleContext = module;
|
|
17
|
-
return this.createContext(instance, callback,
|
|
16
|
+
return this.createContext(instance, callback, GUARDS_METADATA, contextId, inquirerId);
|
|
18
17
|
}
|
|
19
|
-
createConcreteContext(metadata, contextId =
|
|
20
|
-
if (
|
|
18
|
+
createConcreteContext(metadata, contextId = STATIC_CONTEXT, inquirerId) {
|
|
19
|
+
if (isEmpty(metadata)) {
|
|
21
20
|
return [];
|
|
22
21
|
}
|
|
23
|
-
return
|
|
22
|
+
return iterate(metadata)
|
|
24
23
|
.filter((guard) => guard && (guard.name || guard.canActivate))
|
|
25
24
|
.map(guard => this.getGuardInstance(guard, contextId, inquirerId))
|
|
26
|
-
.filter((guard) => !!guard &&
|
|
25
|
+
.filter((guard) => !!guard && isFunction(guard.canActivate))
|
|
27
26
|
.toArray();
|
|
28
27
|
}
|
|
29
|
-
getGuardInstance(metatype, contextId =
|
|
28
|
+
getGuardInstance(metatype, contextId = STATIC_CONTEXT, inquirerId) {
|
|
30
29
|
const isObject = !!metatype.canActivate;
|
|
31
30
|
if (isObject) {
|
|
32
31
|
return metatype;
|
|
@@ -50,16 +49,16 @@ class GuardsContextCreator extends context_creator_1.ContextCreator {
|
|
|
50
49
|
const injectables = moduleRef.injectables;
|
|
51
50
|
return injectables.get(metatype);
|
|
52
51
|
}
|
|
53
|
-
getGlobalMetadata(contextId =
|
|
52
|
+
getGlobalMetadata(contextId = STATIC_CONTEXT, inquirerId) {
|
|
54
53
|
if (!this.config) {
|
|
55
54
|
return [];
|
|
56
55
|
}
|
|
57
56
|
const globalGuards = this.config.getGlobalGuards();
|
|
58
|
-
if (contextId ===
|
|
57
|
+
if (contextId === STATIC_CONTEXT && !inquirerId) {
|
|
59
58
|
return globalGuards;
|
|
60
59
|
}
|
|
61
60
|
const scopedGuardWrappers = this.config.getGlobalRequestGuards();
|
|
62
|
-
const scopedGuards =
|
|
61
|
+
const scopedGuards = iterate(scopedGuardWrappers)
|
|
63
62
|
.map(wrapper => wrapper.getInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId))
|
|
64
63
|
.filter(host => !!host)
|
|
65
64
|
.map(host => host.instance)
|
|
@@ -67,4 +66,3 @@ class GuardsContextCreator extends context_creator_1.ContextCreator {
|
|
|
67
66
|
return globalGuards.concat(scopedGuards);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
exports.GuardsContextCreator = GuardsContextCreator;
|
package/guards/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './constants';
|
|
2
|
-
export * from './guards-consumer';
|
|
3
|
-
export * from './guards-context-creator';
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './guards-consumer.js';
|
|
3
|
+
export * from './guards-context-creator.js';
|
package/guards/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./constants"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./guards-consumer"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./guards-context-creator"), exports);
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './guards-consumer.js';
|
|
3
|
+
export * from './guards-context-creator.js';
|
package/helpers/barrier.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Barrier = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* A simple barrier to synchronize flow of multiple async operations.
|
|
6
3
|
*/
|
|
7
|
-
class Barrier {
|
|
4
|
+
export class Barrier {
|
|
5
|
+
currentCount;
|
|
6
|
+
targetCount;
|
|
7
|
+
promise;
|
|
8
|
+
resolve;
|
|
8
9
|
constructor(targetCount) {
|
|
9
10
|
this.currentCount = 0;
|
|
10
11
|
this.targetCount = targetCount;
|
|
@@ -43,4 +44,3 @@ class Barrier {
|
|
|
43
44
|
return this.wait();
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
exports.Barrier = Barrier;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ContextId, InstanceWrapper } from '../injector/instance-wrapper.js';
|
|
2
|
+
import type { Controller } from '@nestjs/common/internal';
|
|
3
3
|
export declare abstract class ContextCreator {
|
|
4
4
|
abstract createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: ContextId, inquirerId?: string): R;
|
|
5
5
|
getGlobalMetadata?<T extends any[]>(contextId?: ContextId, inquirerId?: string): T;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const constants_1 = require("../injector/constants");
|
|
5
|
-
class ContextCreator {
|
|
6
|
-
createContext(instance, callback, metadataKey, contextId = constants_1.STATIC_CONTEXT, inquirerId) {
|
|
1
|
+
import { STATIC_CONTEXT } from '../injector/constants.js';
|
|
2
|
+
export class ContextCreator {
|
|
3
|
+
createContext(instance, callback, metadataKey, contextId = STATIC_CONTEXT, inquirerId) {
|
|
7
4
|
const globalMetadata = this.getGlobalMetadata &&
|
|
8
5
|
this.getGlobalMetadata(contextId, inquirerId);
|
|
9
6
|
const classMetadata = this.reflectClassMetadata(instance, metadataKey);
|
|
@@ -30,4 +27,3 @@ class ContextCreator {
|
|
|
30
27
|
: contextId;
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.ContextCreator = ContextCreator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContextId, HostComponentInfo } from '../injector/instance-wrapper';
|
|
1
|
+
import { ContextId, HostComponentInfo } from '../injector/instance-wrapper.js';
|
|
2
2
|
export declare function createContextId(): ContextId;
|
|
3
3
|
export type ContextIdResolverFn = (info: HostComponentInfo) => ContextId;
|
|
4
4
|
export interface ContextIdResolver {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.createContextId = createContextId;
|
|
5
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
|
-
const request_constants_1 = require("../router/request/request-constants");
|
|
7
|
-
function createContextId() {
|
|
1
|
+
import { REQUEST_CONTEXT_ID } from '../router/request/request-constants.js';
|
|
2
|
+
import { isObject } from '@nestjs/common/internal';
|
|
3
|
+
export function createContextId() {
|
|
8
4
|
/**
|
|
9
5
|
* We are generating random identifier to track asynchronous
|
|
10
6
|
* execution context. An identifier does not have to be neither unique
|
|
@@ -15,7 +11,8 @@ function createContextId() {
|
|
|
15
11
|
*/
|
|
16
12
|
return { id: Math.random() };
|
|
17
13
|
}
|
|
18
|
-
class ContextIdFactory {
|
|
14
|
+
export class ContextIdFactory {
|
|
15
|
+
static strategy;
|
|
19
16
|
/**
|
|
20
17
|
* Generates a context identifier based on the request object.
|
|
21
18
|
*/
|
|
@@ -30,12 +27,12 @@ class ContextIdFactory {
|
|
|
30
27
|
if (!request) {
|
|
31
28
|
return ContextIdFactory.create();
|
|
32
29
|
}
|
|
33
|
-
if (request[
|
|
34
|
-
return request[
|
|
30
|
+
if (request[REQUEST_CONTEXT_ID]) {
|
|
31
|
+
return request[REQUEST_CONTEXT_ID];
|
|
35
32
|
}
|
|
36
33
|
for (const key of propsToInspect) {
|
|
37
|
-
if (request[key]?.[
|
|
38
|
-
return request[key][
|
|
34
|
+
if (request[key]?.[REQUEST_CONTEXT_ID]) {
|
|
35
|
+
return request[key][REQUEST_CONTEXT_ID];
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
if (!this.strategy) {
|
|
@@ -61,7 +58,6 @@ class ContextIdFactory {
|
|
|
61
58
|
this.strategy = strategy;
|
|
62
59
|
}
|
|
63
60
|
static isContextIdResolverWithPayload(resolverOrResolverFn) {
|
|
64
|
-
return
|
|
61
|
+
return isObject(resolverOrResolverFn);
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
exports.ContextIdFactory = ContextIdFactory;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { ParamData } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ParamData } from '@nestjs/common';
|
|
2
|
+
import { ExecutionContextHost } from './execution-context-host.js';
|
|
3
|
+
import { type Controller } from '@nestjs/common/internal';
|
|
4
|
+
import type { ContextType, PipeTransform } from '@nestjs/common';
|
|
5
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
6
|
export interface ParamProperties<T = any, IExtractor extends Function = any> {
|
|
5
7
|
index: number;
|
|
6
8
|
type: T | string;
|
|
7
9
|
data: ParamData;
|
|
8
10
|
pipes: PipeTransform[];
|
|
9
11
|
extractValue: IExtractor;
|
|
12
|
+
schema?: StandardSchemaV1;
|
|
10
13
|
}
|
|
11
14
|
export declare class ContextUtils {
|
|
12
15
|
mapParamType(key: string): string;
|
package/helpers/context-utils.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const constants_1 = require("@nestjs/common/constants");
|
|
5
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
|
-
const execution_context_host_1 = require("./execution-context-host");
|
|
7
|
-
class ContextUtils {
|
|
1
|
+
import { ExecutionContextHost } from './execution-context-host.js';
|
|
2
|
+
import { PARAMTYPES_METADATA, RESPONSE_PASSTHROUGH_METADATA, isFunction, } from '@nestjs/common/internal';
|
|
3
|
+
export class ContextUtils {
|
|
8
4
|
mapParamType(key) {
|
|
9
5
|
const keyPair = key.split(':');
|
|
10
6
|
return keyPair[0];
|
|
11
7
|
}
|
|
12
8
|
reflectCallbackParamtypes(instance, methodName) {
|
|
13
|
-
return Reflect.getMetadata(
|
|
9
|
+
return Reflect.getMetadata(PARAMTYPES_METADATA, instance, methodName);
|
|
14
10
|
}
|
|
15
11
|
reflectCallbackMetadata(instance, methodName, metadataKey) {
|
|
16
12
|
return Reflect.getMetadata(metadataKey, instance.constructor, methodName);
|
|
17
13
|
}
|
|
18
14
|
reflectPassthrough(instance, methodName) {
|
|
19
|
-
return Reflect.getMetadata(
|
|
15
|
+
return Reflect.getMetadata(RESPONSE_PASSTHROUGH_METADATA, instance.constructor, methodName);
|
|
20
16
|
}
|
|
21
17
|
getArgumentsLength(keys, metadata) {
|
|
22
18
|
return keys.length
|
|
@@ -39,17 +35,16 @@ class ContextUtils {
|
|
|
39
35
|
}));
|
|
40
36
|
}
|
|
41
37
|
getCustomFactory(factory, data, contextFactory) {
|
|
42
|
-
return
|
|
38
|
+
return isFunction(factory)
|
|
43
39
|
? (...args) => factory(data, contextFactory(args))
|
|
44
40
|
: () => null;
|
|
45
41
|
}
|
|
46
42
|
getContextFactory(contextType, instance, callback) {
|
|
47
43
|
const type = instance && instance.constructor;
|
|
48
44
|
return (args) => {
|
|
49
|
-
const ctx = new
|
|
45
|
+
const ctx = new ExecutionContextHost(args, type, callback);
|
|
50
46
|
ctx.setType(contextType);
|
|
51
47
|
return ctx;
|
|
52
48
|
};
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
|
-
exports.ContextUtils = ContextUtils;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
-
import { Type } from '@nestjs/common
|
|
3
|
-
import {
|
|
1
|
+
import type { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import type { Type, ContextType } from '@nestjs/common';
|
|
3
|
+
import type { HttpArgumentsHost, RpcArgumentsHost, WsArgumentsHost } from '@nestjs/common/internal';
|
|
4
4
|
export declare class ExecutionContextHost implements ExecutionContext {
|
|
5
5
|
private readonly args;
|
|
6
6
|
private readonly constructorRef;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export class ExecutionContextHost {
|
|
2
|
+
args;
|
|
3
|
+
constructorRef;
|
|
4
|
+
handler;
|
|
5
|
+
contextType = 'http';
|
|
5
6
|
constructor(args, constructorRef = null, handler = null) {
|
|
6
7
|
this.args = args;
|
|
7
8
|
this.constructorRef = constructorRef;
|
|
8
9
|
this.handler = handler;
|
|
9
|
-
this.contextType = 'http';
|
|
10
10
|
}
|
|
11
11
|
setType(type) {
|
|
12
12
|
type && (this.contextType = type);
|
|
@@ -47,4 +47,3 @@ class ExecutionContextHost {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
exports.ExecutionContextHost = ExecutionContextHost;
|