@depup/nestjs__core 11.2.3-depup.0 → 12.0.2-depup.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/README.md +2 -2
- package/adapters/http-adapter.d.ts +372 -3
- package/adapters/http-adapter.js +135 -5
- package/adapters/index.d.ts +1 -1
- package/adapters/index.js +1 -4
- package/application-config.d.ts +13 -4
- package/application-config.js +34 -15
- package/changes.json +1 -1
- 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 +25 -20
- 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 +9 -8
- package/errors/exceptions/index.js +9 -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/route-conflict.exception.d.ts +4 -0
- package/errors/exceptions/route-conflict.exception.js +7 -0
- 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 +5 -2
- package/errors/messages.js +26 -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 +46 -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 +5 -8
- 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 +21 -25
- package/helpers/safe-instance-decorator.js +3 -6
- package/hooks/before-app-shutdown.hook.d.ts +3 -3
- package/hooks/before-app-shutdown.hook.js +25 -23
- 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 +25 -23
- package/hooks/on-module-destroy.hook.d.ts +3 -3
- package/hooks/on-module-destroy.hook.js +25 -23
- 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/is-debug-mode.util.d.ts +1 -0
- package/injector/helpers/is-debug-mode.util.js +3 -0
- 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 -7
- package/injector/injector.js +104 -93
- 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 +17 -11
- package/injector/instance-wrapper.d.ts +8 -6
- package/injector/instance-wrapper.js +98 -81
- 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 +36 -27
- package/injector/module-ref.d.ts +7 -7
- package/injector/module-ref.js +30 -35
- package/injector/module.d.ts +5 -5
- package/injector/module.js +97 -83
- 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 +14 -18
- 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 +42 -0
- package/internal.js +50 -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 +82 -80
- 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 +49 -46
- 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 +26 -11
- package/nest-application-context.js +79 -67
- package/nest-application.d.ts +19 -11
- package/nest-application.js +168 -65
- package/nest-factory.d.ts +4 -5
- package/nest-factory.js +61 -68
- package/package.json +17 -9
- 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 +4 -1
- package/router/interfaces/index.js +4 -4
- package/router/interfaces/resolved-route.interface.d.ts +32 -0
- package/router/interfaces/resolved-route.interface.js +1 -0
- package/router/interfaces/resolver.interface.d.ts +5 -1
- package/router/interfaces/resolver.interface.js +1 -2
- package/router/interfaces/route-conflict.interface.d.ts +14 -0
- package/router/interfaces/route-conflict.interface.js +1 -0
- 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/route-resolution-options.interface.d.ts +24 -0
- package/router/interfaces/route-resolution-options.interface.js +1 -0
- 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-conflict-detector.d.ts +71 -0
- package/router/route-conflict-detector.js +276 -0
- 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/route-specificity-sorter.d.ts +23 -0
- package/router/route-specificity-sorter.js +59 -0
- 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 +62 -55
- package/router/router-explorer.d.ts +25 -18
- package/router/router-explorer.js +116 -73
- 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 +23 -27
- package/router/routes-resolver.d.ts +13 -11
- package/router/routes-resolver.js +42 -55
- package/router/sse-stream.d.ts +2 -1
- package/router/sse-stream.js +29 -24
- 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 +66 -67
- 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
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/nestjs__core
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@nestjs/core](https://www.npmjs.com/package/@nestjs/core) @
|
|
17
|
-
| Processed | 2026-
|
|
16
|
+
| Original | [@nestjs/core](https://www.npmjs.com/package/@nestjs/core) @ 12.0.2 |
|
|
17
|
+
| Processed | 2026-09-14 |
|
|
18
18
|
| Smoke test | failed |
|
|
19
19
|
| Deps updated | 0 |
|
|
20
20
|
|
|
@@ -1,82 +1,451 @@
|
|
|
1
|
-
import { HttpServer, RequestMethod, VersioningOptions } from '@nestjs/common';
|
|
2
|
-
import { RequestHandler, VersionValue } from '@nestjs/common/
|
|
3
|
-
import { NestApplicationOptions } from '@nestjs/common
|
|
1
|
+
import type { HttpServer, RequestMethod, VersioningOptions } from '@nestjs/common';
|
|
2
|
+
import type { RequestHandler, VersionValue } from '@nestjs/common/internal';
|
|
3
|
+
import type { NestApplicationOptions } from '@nestjs/common';
|
|
4
4
|
/**
|
|
5
|
+
* Base class for HTTP platform adapters (see `ExpressAdapter` and
|
|
6
|
+
* `FastifyAdapter` for reference implementations).
|
|
7
|
+
*
|
|
8
|
+
* It implements the {@link HttpServer} contract that the Nest core relies on,
|
|
9
|
+
* and that interface is where each method's calling conventions are
|
|
10
|
+
* documented: when the core invokes it, with which arguments, and what it
|
|
11
|
+
* expects back. This class only adds:
|
|
12
|
+
*
|
|
13
|
+
* - default implementations that delegate to the wrapped framework
|
|
14
|
+
* `instance` (`use()`, the HTTP-verb methods, `listen()`) or are inert
|
|
15
|
+
* (`init()`, `normalizePath()`, `mapException()`, `beforeClose()`, the
|
|
16
|
+
* `setOn*Hook()` setters);
|
|
17
|
+
* - storage for the native server (`httpServer`) and the framework instance
|
|
18
|
+
* (`instance`), with their accessors;
|
|
19
|
+
* - the introspection hooks used by instrumentation tooling.
|
|
20
|
+
*
|
|
21
|
+
* Every remaining {@link HttpServer} member is declared abstract here, even
|
|
22
|
+
* the ones the interface marks optional, so subclasses cannot forget them.
|
|
23
|
+
* `setBaseViewsDir()`, `useBodyParser()` and `isRouteOrderSensitive()` are
|
|
24
|
+
* not declared on this class; implement them when the platform supports
|
|
25
|
+
* them (see {@link HttpServer} for what the core does when they are absent).
|
|
26
|
+
*
|
|
27
|
+
* Keep in mind that the core also reads and writes properties of the request
|
|
28
|
+
* object (`body`, `params`, `query`, `headers`, ...), that Server-Sent Events
|
|
29
|
+
* write directly to the Node.js response, and that `app.listen()` and the
|
|
30
|
+
* WebSocket adapters use the value returned by
|
|
31
|
+
* {@link AbstractHttpAdapter.getHttpServer} as a Node.js `net.Server`; see the
|
|
32
|
+
* {@link HttpServer} documentation for details.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam TServer - Type of the native HTTP server stored in `httpServer`
|
|
35
|
+
* (e.g. `http.Server | https.Server`).
|
|
36
|
+
* @typeParam TRequest - Type of the framework request object.
|
|
37
|
+
* @typeParam TResponse - Type of the framework response object.
|
|
38
|
+
*
|
|
39
|
+
* @see [HTTP adapter](https://docs.nestjs.com/faq/http-adapter)
|
|
40
|
+
*
|
|
5
41
|
* @publicApi
|
|
6
42
|
*/
|
|
7
43
|
export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any, TResponse = any> implements HttpServer<TRequest, TResponse> {
|
|
8
44
|
protected instance?: any | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Native HTTP server created by {@link AbstractHttpAdapter.initHttpServer}
|
|
47
|
+
* and returned by {@link AbstractHttpAdapter.getHttpServer}.
|
|
48
|
+
*/
|
|
9
49
|
protected httpServer: TServer;
|
|
50
|
+
/**
|
|
51
|
+
* Callback registered through
|
|
52
|
+
* {@link AbstractHttpAdapter.setOnRouteTriggered}, if any.
|
|
53
|
+
*/
|
|
10
54
|
protected onRouteTriggered: ((requestMethod: RequestMethod, path: string) => void) | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* @param instance The framework application instance to delegate to (e.g.
|
|
57
|
+
* an Express `Application`). Subclasses typically create a default one
|
|
58
|
+
* when none is given.
|
|
59
|
+
*/
|
|
11
60
|
constructor(instance?: any | undefined);
|
|
61
|
+
/**
|
|
62
|
+
* Asynchronous setup hook, awaited by `NestFactory.create()` and again by
|
|
63
|
+
* `app.init()`, so overrides must be idempotent. No-op by default.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link HttpServer.init}
|
|
66
|
+
*/
|
|
12
67
|
init(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Registers a global middleware by delegating to `instance.use(...args)`.
|
|
70
|
+
*
|
|
71
|
+
* @see {@link HttpServer.use}
|
|
72
|
+
*/
|
|
13
73
|
use(...args: any[]): any;
|
|
74
|
+
/**
|
|
75
|
+
* Registers a `GET` route by delegating to `instance.get(...args)`.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link HttpServer.get}
|
|
78
|
+
*/
|
|
14
79
|
get(handler: RequestHandler): any;
|
|
15
80
|
get(path: any, handler: RequestHandler): any;
|
|
81
|
+
/**
|
|
82
|
+
* Registers a `POST` route by delegating to `instance.post(...args)`.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link HttpServer.post}
|
|
85
|
+
*/
|
|
16
86
|
post(handler: RequestHandler): any;
|
|
17
87
|
post(path: any, handler: RequestHandler): any;
|
|
88
|
+
/**
|
|
89
|
+
* Registers a `HEAD` route by delegating to `instance.head(...args)`.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link HttpServer.head}
|
|
92
|
+
*/
|
|
18
93
|
head(handler: RequestHandler): any;
|
|
19
94
|
head(path: any, handler: RequestHandler): any;
|
|
95
|
+
/**
|
|
96
|
+
* Registers a `DELETE` route by delegating to `instance.delete(...args)`.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link HttpServer.delete}
|
|
99
|
+
*/
|
|
20
100
|
delete(handler: RequestHandler): any;
|
|
21
101
|
delete(path: any, handler: RequestHandler): any;
|
|
102
|
+
/**
|
|
103
|
+
* Registers a `PUT` route by delegating to `instance.put(...args)`.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link HttpServer.put}
|
|
106
|
+
*/
|
|
22
107
|
put(handler: RequestHandler): any;
|
|
23
108
|
put(path: any, handler: RequestHandler): any;
|
|
109
|
+
/**
|
|
110
|
+
* Registers a `PATCH` route by delegating to `instance.patch(...args)`.
|
|
111
|
+
*
|
|
112
|
+
* @see {@link HttpServer.patch}
|
|
113
|
+
*/
|
|
24
114
|
patch(handler: RequestHandler): any;
|
|
25
115
|
patch(path: any, handler: RequestHandler): any;
|
|
116
|
+
/**
|
|
117
|
+
* Registers a WebDAV `PROPFIND` route by delegating to
|
|
118
|
+
* `instance.propfind(...args)`. Override when the framework exposes the
|
|
119
|
+
* verb under a different API.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link HttpServer.propfind}
|
|
122
|
+
*/
|
|
26
123
|
propfind(handler: RequestHandler): any;
|
|
27
124
|
propfind(path: any, handler: RequestHandler): any;
|
|
125
|
+
/**
|
|
126
|
+
* Registers a WebDAV `PROPPATCH` route by delegating to
|
|
127
|
+
* `instance.proppatch(...args)`. Override when the framework exposes the
|
|
128
|
+
* verb under a different API.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link HttpServer.proppatch}
|
|
131
|
+
*/
|
|
28
132
|
proppatch(handler: RequestHandler): any;
|
|
29
133
|
proppatch(path: any, handler: RequestHandler): any;
|
|
134
|
+
/**
|
|
135
|
+
* Registers a WebDAV `MKCOL` route by delegating to
|
|
136
|
+
* `instance.mkcol(...args)`. Override when the framework exposes the verb
|
|
137
|
+
* under a different API.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link HttpServer.mkcol}
|
|
140
|
+
*/
|
|
30
141
|
mkcol(handler: RequestHandler): any;
|
|
31
142
|
mkcol(path: any, handler: RequestHandler): any;
|
|
143
|
+
/**
|
|
144
|
+
* Registers a WebDAV `COPY` route by delegating to
|
|
145
|
+
* `instance.copy(...args)`. Override when the framework exposes the verb
|
|
146
|
+
* under a different API.
|
|
147
|
+
*
|
|
148
|
+
* @see {@link HttpServer.copy}
|
|
149
|
+
*/
|
|
32
150
|
copy(handler: RequestHandler): any;
|
|
33
151
|
copy(path: any, handler: RequestHandler): any;
|
|
152
|
+
/**
|
|
153
|
+
* Registers a WebDAV `MOVE` route by delegating to
|
|
154
|
+
* `instance.move(...args)`. Override when the framework exposes the verb
|
|
155
|
+
* under a different API.
|
|
156
|
+
*
|
|
157
|
+
* @see {@link HttpServer.move}
|
|
158
|
+
*/
|
|
34
159
|
move(handler: RequestHandler): any;
|
|
35
160
|
move(path: any, handler: RequestHandler): any;
|
|
161
|
+
/**
|
|
162
|
+
* Registers a WebDAV `LOCK` route by delegating to
|
|
163
|
+
* `instance.lock(...args)`. Override when the framework exposes the verb
|
|
164
|
+
* under a different API.
|
|
165
|
+
*
|
|
166
|
+
* @see {@link HttpServer.lock}
|
|
167
|
+
*/
|
|
36
168
|
lock(handler: RequestHandler): any;
|
|
37
169
|
lock(path: any, handler: RequestHandler): any;
|
|
170
|
+
/**
|
|
171
|
+
* Registers a WebDAV `UNLOCK` route by delegating to
|
|
172
|
+
* `instance.unlock(...args)`. Override when the framework exposes the verb
|
|
173
|
+
* under a different API.
|
|
174
|
+
*
|
|
175
|
+
* @see {@link HttpServer.unlock}
|
|
176
|
+
*/
|
|
38
177
|
unlock(handler: RequestHandler): any;
|
|
39
178
|
unlock(path: any, handler: RequestHandler): any;
|
|
179
|
+
/**
|
|
180
|
+
* Registers a route for every HTTP method by delegating to
|
|
181
|
+
* `instance.all(...args)`.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link HttpServer.all}
|
|
184
|
+
*/
|
|
40
185
|
all(handler: RequestHandler): any;
|
|
41
186
|
all(path: any, handler: RequestHandler): any;
|
|
187
|
+
/**
|
|
188
|
+
* Registers a `SEARCH` route by delegating to `instance.search(...args)`.
|
|
189
|
+
* Override when the framework exposes the verb under a different API.
|
|
190
|
+
*
|
|
191
|
+
* @see {@link HttpServer.search}
|
|
192
|
+
*/
|
|
42
193
|
search(handler: RequestHandler): any;
|
|
43
194
|
search(path: any, handler: RequestHandler): any;
|
|
195
|
+
/**
|
|
196
|
+
* Registers a `QUERY` route by delegating to `instance.query(...args)`.
|
|
197
|
+
* Override when the framework exposes the verb under a different API.
|
|
198
|
+
*
|
|
199
|
+
* @see {@link HttpServer.query}
|
|
200
|
+
*/
|
|
44
201
|
query(handler: RequestHandler): any;
|
|
45
202
|
query(path: any, handler: RequestHandler): any;
|
|
203
|
+
/**
|
|
204
|
+
* Registers an `OPTIONS` route by delegating to
|
|
205
|
+
* `instance.options(...args)`.
|
|
206
|
+
*
|
|
207
|
+
* @see {@link HttpServer.options}
|
|
208
|
+
*/
|
|
46
209
|
options(handler: RequestHandler): any;
|
|
47
210
|
options(path: any, handler: RequestHandler): any;
|
|
211
|
+
/**
|
|
212
|
+
* Starts listening by delegating to
|
|
213
|
+
* `instance.listen(port, hostname, callback)`. The core always passes its
|
|
214
|
+
* own callback as the last argument and expects it to be invoked once the
|
|
215
|
+
* server is bound, or with an `Error` on failure. Override when the
|
|
216
|
+
* framework instance does not expose a Node-style `listen()`, e.g. to call
|
|
217
|
+
* `httpServer.listen()` instead.
|
|
218
|
+
*
|
|
219
|
+
* @see {@link HttpServer.listen}
|
|
220
|
+
*/
|
|
48
221
|
listen(port: string | number, callback?: () => void): any;
|
|
49
222
|
listen(port: string | number, hostname: string, callback?: () => void): any;
|
|
223
|
+
/**
|
|
224
|
+
* Returns the native HTTP server stored by
|
|
225
|
+
* {@link AbstractHttpAdapter.initHttpServer} (or
|
|
226
|
+
* {@link AbstractHttpAdapter.setHttpServer}).
|
|
227
|
+
*
|
|
228
|
+
* @see {@link HttpServer.getHttpServer}
|
|
229
|
+
*/
|
|
50
230
|
getHttpServer(): TServer;
|
|
231
|
+
/**
|
|
232
|
+
* Replaces the native HTTP server returned by
|
|
233
|
+
* {@link AbstractHttpAdapter.getHttpServer}. Mostly useful for tests and
|
|
234
|
+
* for adapters that obtain the server from elsewhere.
|
|
235
|
+
*/
|
|
51
236
|
setHttpServer(httpServer: TServer): void;
|
|
237
|
+
/**
|
|
238
|
+
* Replaces the framework application instance that the default method
|
|
239
|
+
* implementations delegate to.
|
|
240
|
+
*/
|
|
52
241
|
setInstance<T = any>(instance: T): void;
|
|
242
|
+
/**
|
|
243
|
+
* Returns the framework application instance passed to the constructor
|
|
244
|
+
* (or set through {@link AbstractHttpAdapter.setInstance}).
|
|
245
|
+
*
|
|
246
|
+
* @see {@link HttpServer.getInstance}
|
|
247
|
+
*/
|
|
53
248
|
getInstance<T = any>(): T;
|
|
249
|
+
/**
|
|
250
|
+
* Converts and validates a route path before registration. Returns the
|
|
251
|
+
* path unchanged by default; override to translate Nest's path syntax to
|
|
252
|
+
* the router's and to throw on invalid paths.
|
|
253
|
+
*
|
|
254
|
+
* @see {@link HttpServer.normalizePath}
|
|
255
|
+
*/
|
|
54
256
|
normalizePath(path: string): string;
|
|
257
|
+
/**
|
|
258
|
+
* Registers a callback that the router invokes right before each route
|
|
259
|
+
* handler runs, with the resolved `RequestMethod` and the route path as
|
|
260
|
+
* declared (before {@link AbstractHttpAdapter.normalizePath}). The router
|
|
261
|
+
* wraps every handler at registration time, so the callback must be set
|
|
262
|
+
* before `app.init()` to take effect. Intended for instrumentation and
|
|
263
|
+
* devtools; there is no need to override it.
|
|
264
|
+
*/
|
|
55
265
|
setOnRouteTriggered(onRouteTriggered: (requestMethod: RequestMethod, path: string) => void): void;
|
|
266
|
+
/**
|
|
267
|
+
* Returns the callback registered through
|
|
268
|
+
* {@link AbstractHttpAdapter.setOnRouteTriggered}, if any. Read by the
|
|
269
|
+
* router when registering routes.
|
|
270
|
+
*/
|
|
56
271
|
getOnRouteTriggered(): ((requestMethod: RequestMethod, path: string) => void) | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* Registers a hook to run at the start of every request. No-op by default;
|
|
274
|
+
* the built-in adapters accept a `(req, res, done) => void | Promise<void>`
|
|
275
|
+
* function and call `done()` to continue processing. Intended for
|
|
276
|
+
* instrumentation and devtools.
|
|
277
|
+
*/
|
|
57
278
|
setOnRequestHook(onRequestHook: Function): void;
|
|
279
|
+
/**
|
|
280
|
+
* Registers a hook to run once a response has been sent. No-op by default;
|
|
281
|
+
* the built-in adapters accept a `(req, res) => void | Promise<void>`
|
|
282
|
+
* function. Intended for instrumentation and devtools.
|
|
283
|
+
*/
|
|
58
284
|
setOnResponseHook(onResponseHook: Function): void;
|
|
285
|
+
/**
|
|
286
|
+
* Called by `app.close()` before the shutdown hooks run. No-op by default;
|
|
287
|
+
* override to enter a "shutting down" state.
|
|
288
|
+
*
|
|
289
|
+
* @see {@link HttpServer.beforeClose}
|
|
290
|
+
*/
|
|
291
|
+
beforeClose(): void;
|
|
292
|
+
/**
|
|
293
|
+
* Translates a framework-native error into something the exception filters
|
|
294
|
+
* understand. Invoked by the global exception layer with every error it
|
|
295
|
+
* receives, before it reaches the filters; the returned value is what the
|
|
296
|
+
* filters see. Returns the error unchanged by default. The built-in
|
|
297
|
+
* adapters map, for instance, body-parser `SyntaxError`s to
|
|
298
|
+
* `BadRequestException`.
|
|
299
|
+
*/
|
|
300
|
+
mapException(error: unknown): unknown;
|
|
301
|
+
/**
|
|
302
|
+
* Stops the server; called by `app.close()`. May return a promise.
|
|
303
|
+
*
|
|
304
|
+
* @see {@link HttpServer.close}
|
|
305
|
+
*/
|
|
59
306
|
abstract close(): any;
|
|
307
|
+
/**
|
|
308
|
+
* Creates the native server and stores it in `httpServer`, honoring the
|
|
309
|
+
* `httpsOptions`, `forceCloseConnections` and `return503OnClosing`
|
|
310
|
+
* application options. Called once when the application is constructed.
|
|
311
|
+
*
|
|
312
|
+
* @see {@link HttpServer.initHttpServer}
|
|
313
|
+
*/
|
|
60
314
|
abstract initHttpServer(options: NestApplicationOptions): any;
|
|
315
|
+
/**
|
|
316
|
+
* Serves static files; pass-through for `app.useStaticAssets()`.
|
|
317
|
+
*
|
|
318
|
+
* @see {@link HttpServer.useStaticAssets}
|
|
319
|
+
*/
|
|
61
320
|
abstract useStaticAssets(...args: any[]): any;
|
|
321
|
+
/**
|
|
322
|
+
* Configures the template engine used by
|
|
323
|
+
* {@link AbstractHttpAdapter.render}; pass-through for
|
|
324
|
+
* `app.setViewEngine()`.
|
|
325
|
+
*
|
|
326
|
+
* @see {@link HttpServer.setViewEngine}
|
|
327
|
+
*/
|
|
62
328
|
abstract setViewEngine(engine: string): any;
|
|
329
|
+
/**
|
|
330
|
+
* Returns the request host name, used for `@Controller({ host })`.
|
|
331
|
+
*
|
|
332
|
+
* @see {@link HttpServer.getRequestHostname}
|
|
333
|
+
*/
|
|
63
334
|
abstract getRequestHostname(request: any): any;
|
|
335
|
+
/**
|
|
336
|
+
* Returns the upper-case request method (`'GET'`, `'POST'`, ...).
|
|
337
|
+
*
|
|
338
|
+
* @see {@link HttpServer.getRequestMethod}
|
|
339
|
+
*/
|
|
64
340
|
abstract getRequestMethod(request: any): any;
|
|
341
|
+
/**
|
|
342
|
+
* Returns the original request URL, including the query string.
|
|
343
|
+
*
|
|
344
|
+
* @see {@link HttpServer.getRequestUrl}
|
|
345
|
+
*/
|
|
65
346
|
abstract getRequestUrl(request: any): any;
|
|
347
|
+
/**
|
|
348
|
+
* Sets the status code without sending the response.
|
|
349
|
+
*
|
|
350
|
+
* @see {@link HttpServer.status}
|
|
351
|
+
*/
|
|
66
352
|
abstract status(response: any, statusCode: number): any;
|
|
353
|
+
/**
|
|
354
|
+
* Sends the response body, handling empty bodies, `StreamableFile`,
|
|
355
|
+
* objects (as JSON) and primitives.
|
|
356
|
+
*
|
|
357
|
+
* @see {@link HttpServer.reply}
|
|
358
|
+
*/
|
|
67
359
|
abstract reply(response: any, body: any, statusCode?: number): any;
|
|
360
|
+
/**
|
|
361
|
+
* Terminates the response, optionally writing `message` first.
|
|
362
|
+
*
|
|
363
|
+
* @see {@link HttpServer.end}
|
|
364
|
+
*/
|
|
68
365
|
abstract end(response: any, message?: string): any;
|
|
366
|
+
/**
|
|
367
|
+
* Renders a view template (`@Render()`).
|
|
368
|
+
*
|
|
369
|
+
* @see {@link HttpServer.render}
|
|
370
|
+
*/
|
|
69
371
|
abstract render(response: any, view: string, options: any): any;
|
|
372
|
+
/**
|
|
373
|
+
* Issues a redirect (`@Redirect()`).
|
|
374
|
+
*
|
|
375
|
+
* @see {@link HttpServer.redirect}
|
|
376
|
+
*/
|
|
70
377
|
abstract redirect(response: any, statusCode: number, url: string): any;
|
|
378
|
+
/**
|
|
379
|
+
* Installs the global exception layer.
|
|
380
|
+
*
|
|
381
|
+
* @see {@link HttpServer.setErrorHandler}
|
|
382
|
+
*/
|
|
71
383
|
abstract setErrorHandler(handler: Function, prefix?: string): any;
|
|
384
|
+
/**
|
|
385
|
+
* Installs the catch-all handler for unmatched requests.
|
|
386
|
+
*
|
|
387
|
+
* @see {@link HttpServer.setNotFoundHandler}
|
|
388
|
+
*/
|
|
72
389
|
abstract setNotFoundHandler(handler: Function, prefix?: string): any;
|
|
390
|
+
/**
|
|
391
|
+
* Reports whether response headers have already been flushed. Must return
|
|
392
|
+
* synchronously.
|
|
393
|
+
*
|
|
394
|
+
* @see {@link HttpServer.isHeadersSent}
|
|
395
|
+
*/
|
|
73
396
|
abstract isHeadersSent(response: any): any;
|
|
397
|
+
/**
|
|
398
|
+
* Reads a response header that was set earlier. Not used by the core
|
|
399
|
+
* router; part of the base class so ecosystem packages can read headers
|
|
400
|
+
* through the adapter regardless of the platform.
|
|
401
|
+
*/
|
|
74
402
|
abstract getHeader(response: any, name: string): any;
|
|
403
|
+
/**
|
|
404
|
+
* Sets (replaces) a response header (`@Header()`).
|
|
405
|
+
*
|
|
406
|
+
* @see {@link HttpServer.setHeader}
|
|
407
|
+
*/
|
|
75
408
|
abstract setHeader(response: any, name: string, value: string): any;
|
|
409
|
+
/**
|
|
410
|
+
* Appends a value to a response header, turning it into a multi-value
|
|
411
|
+
* header (e.g. several `Set-Cookie` entries) instead of replacing it. Not
|
|
412
|
+
* used by the core router; part of the base class so ecosystem packages
|
|
413
|
+
* can append headers through the adapter regardless of the platform.
|
|
414
|
+
*/
|
|
76
415
|
abstract appendHeader(response: any, name: string, value: string): any;
|
|
416
|
+
/**
|
|
417
|
+
* Registers the default JSON and URL-encoded body parsers, exposing
|
|
418
|
+
* `req.rawBody` when `rawBody` is `true`.
|
|
419
|
+
*
|
|
420
|
+
* @see {@link HttpServer.registerParserMiddleware}
|
|
421
|
+
*/
|
|
77
422
|
abstract registerParserMiddleware(prefix?: string, rawBody?: boolean): any;
|
|
423
|
+
/**
|
|
424
|
+
* Enables CORS. The core currently calls this with `options` only; the
|
|
425
|
+
* `prefix` parameter is reserved.
|
|
426
|
+
*
|
|
427
|
+
* @see {@link HttpServer.enableCors}
|
|
428
|
+
*/
|
|
78
429
|
abstract enableCors(options?: any, prefix?: string): any;
|
|
430
|
+
/**
|
|
431
|
+
* Returns the function used to mount Nest middleware for one HTTP method.
|
|
432
|
+
* May be asynchronous.
|
|
433
|
+
*
|
|
434
|
+
* @see {@link HttpServer.createMiddlewareFactory}
|
|
435
|
+
*/
|
|
79
436
|
abstract createMiddlewareFactory(requestMethod: RequestMethod): ((path: string, callback: Function) => any) | Promise<(path: string, callback: Function) => any>;
|
|
437
|
+
/**
|
|
438
|
+
* Returns the platform identifier (`'express'`, `'fastify'`) that
|
|
439
|
+
* ecosystem packages branch on.
|
|
440
|
+
*
|
|
441
|
+
* @see {@link HttpServer.getType}
|
|
442
|
+
*/
|
|
80
443
|
abstract getType(): string;
|
|
444
|
+
/**
|
|
445
|
+
* Guards a route handler by request version for header, media-type and
|
|
446
|
+
* custom versioning.
|
|
447
|
+
*
|
|
448
|
+
* @see {@link HttpServer.applyVersionFilter}
|
|
449
|
+
*/
|
|
81
450
|
abstract applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): (req: TRequest, res: TResponse, next: () => void) => Function;
|
|
82
451
|
}
|
package/adapters/http-adapter.js
CHANGED
|
@@ -1,14 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractHttpAdapter = void 0;
|
|
4
1
|
/**
|
|
2
|
+
* Base class for HTTP platform adapters (see `ExpressAdapter` and
|
|
3
|
+
* `FastifyAdapter` for reference implementations).
|
|
4
|
+
*
|
|
5
|
+
* It implements the {@link HttpServer} contract that the Nest core relies on,
|
|
6
|
+
* and that interface is where each method's calling conventions are
|
|
7
|
+
* documented: when the core invokes it, with which arguments, and what it
|
|
8
|
+
* expects back. This class only adds:
|
|
9
|
+
*
|
|
10
|
+
* - default implementations that delegate to the wrapped framework
|
|
11
|
+
* `instance` (`use()`, the HTTP-verb methods, `listen()`) or are inert
|
|
12
|
+
* (`init()`, `normalizePath()`, `mapException()`, `beforeClose()`, the
|
|
13
|
+
* `setOn*Hook()` setters);
|
|
14
|
+
* - storage for the native server (`httpServer`) and the framework instance
|
|
15
|
+
* (`instance`), with their accessors;
|
|
16
|
+
* - the introspection hooks used by instrumentation tooling.
|
|
17
|
+
*
|
|
18
|
+
* Every remaining {@link HttpServer} member is declared abstract here, even
|
|
19
|
+
* the ones the interface marks optional, so subclasses cannot forget them.
|
|
20
|
+
* `setBaseViewsDir()`, `useBodyParser()` and `isRouteOrderSensitive()` are
|
|
21
|
+
* not declared on this class; implement them when the platform supports
|
|
22
|
+
* them (see {@link HttpServer} for what the core does when they are absent).
|
|
23
|
+
*
|
|
24
|
+
* Keep in mind that the core also reads and writes properties of the request
|
|
25
|
+
* object (`body`, `params`, `query`, `headers`, ...), that Server-Sent Events
|
|
26
|
+
* write directly to the Node.js response, and that `app.listen()` and the
|
|
27
|
+
* WebSocket adapters use the value returned by
|
|
28
|
+
* {@link AbstractHttpAdapter.getHttpServer} as a Node.js `net.Server`; see the
|
|
29
|
+
* {@link HttpServer} documentation for details.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam TServer - Type of the native HTTP server stored in `httpServer`
|
|
32
|
+
* (e.g. `http.Server | https.Server`).
|
|
33
|
+
* @typeParam TRequest - Type of the framework request object.
|
|
34
|
+
* @typeParam TResponse - Type of the framework response object.
|
|
35
|
+
*
|
|
36
|
+
* @see [HTTP adapter](https://docs.nestjs.com/faq/http-adapter)
|
|
37
|
+
*
|
|
5
38
|
* @publicApi
|
|
6
39
|
*/
|
|
7
|
-
class AbstractHttpAdapter {
|
|
40
|
+
export class AbstractHttpAdapter {
|
|
41
|
+
instance;
|
|
42
|
+
/**
|
|
43
|
+
* Native HTTP server created by {@link AbstractHttpAdapter.initHttpServer}
|
|
44
|
+
* and returned by {@link AbstractHttpAdapter.getHttpServer}.
|
|
45
|
+
*/
|
|
46
|
+
httpServer;
|
|
47
|
+
/**
|
|
48
|
+
* Callback registered through
|
|
49
|
+
* {@link AbstractHttpAdapter.setOnRouteTriggered}, if any.
|
|
50
|
+
*/
|
|
51
|
+
onRouteTriggered;
|
|
52
|
+
/**
|
|
53
|
+
* @param instance The framework application instance to delegate to (e.g.
|
|
54
|
+
* an Express `Application`). Subclasses typically create a default one
|
|
55
|
+
* when none is given.
|
|
56
|
+
*/
|
|
8
57
|
constructor(instance) {
|
|
9
58
|
this.instance = instance;
|
|
10
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Asynchronous setup hook, awaited by `NestFactory.create()` and again by
|
|
62
|
+
* `app.init()`, so overrides must be idempotent. No-op by default.
|
|
63
|
+
*
|
|
64
|
+
* @see {@link HttpServer.init}
|
|
65
|
+
*/
|
|
11
66
|
async init() { }
|
|
67
|
+
/**
|
|
68
|
+
* Registers a global middleware by delegating to `instance.use(...args)`.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link HttpServer.use}
|
|
71
|
+
*/
|
|
12
72
|
use(...args) {
|
|
13
73
|
return this.instance.use(...args);
|
|
14
74
|
}
|
|
@@ -66,28 +126,98 @@ class AbstractHttpAdapter {
|
|
|
66
126
|
listen(port, hostname, callback) {
|
|
67
127
|
return this.instance.listen(port, hostname, callback);
|
|
68
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns the native HTTP server stored by
|
|
131
|
+
* {@link AbstractHttpAdapter.initHttpServer} (or
|
|
132
|
+
* {@link AbstractHttpAdapter.setHttpServer}).
|
|
133
|
+
*
|
|
134
|
+
* @see {@link HttpServer.getHttpServer}
|
|
135
|
+
*/
|
|
69
136
|
getHttpServer() {
|
|
70
137
|
return this.httpServer;
|
|
71
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Replaces the native HTTP server returned by
|
|
141
|
+
* {@link AbstractHttpAdapter.getHttpServer}. Mostly useful for tests and
|
|
142
|
+
* for adapters that obtain the server from elsewhere.
|
|
143
|
+
*/
|
|
72
144
|
setHttpServer(httpServer) {
|
|
73
145
|
this.httpServer = httpServer;
|
|
74
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Replaces the framework application instance that the default method
|
|
149
|
+
* implementations delegate to.
|
|
150
|
+
*/
|
|
75
151
|
setInstance(instance) {
|
|
76
152
|
this.instance = instance;
|
|
77
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Returns the framework application instance passed to the constructor
|
|
156
|
+
* (or set through {@link AbstractHttpAdapter.setInstance}).
|
|
157
|
+
*
|
|
158
|
+
* @see {@link HttpServer.getInstance}
|
|
159
|
+
*/
|
|
78
160
|
getInstance() {
|
|
79
161
|
return this.instance;
|
|
80
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Converts and validates a route path before registration. Returns the
|
|
165
|
+
* path unchanged by default; override to translate Nest's path syntax to
|
|
166
|
+
* the router's and to throw on invalid paths.
|
|
167
|
+
*
|
|
168
|
+
* @see {@link HttpServer.normalizePath}
|
|
169
|
+
*/
|
|
81
170
|
normalizePath(path) {
|
|
82
171
|
return path;
|
|
83
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Registers a callback that the router invokes right before each route
|
|
175
|
+
* handler runs, with the resolved `RequestMethod` and the route path as
|
|
176
|
+
* declared (before {@link AbstractHttpAdapter.normalizePath}). The router
|
|
177
|
+
* wraps every handler at registration time, so the callback must be set
|
|
178
|
+
* before `app.init()` to take effect. Intended for instrumentation and
|
|
179
|
+
* devtools; there is no need to override it.
|
|
180
|
+
*/
|
|
84
181
|
setOnRouteTriggered(onRouteTriggered) {
|
|
85
182
|
this.onRouteTriggered = onRouteTriggered;
|
|
86
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Returns the callback registered through
|
|
186
|
+
* {@link AbstractHttpAdapter.setOnRouteTriggered}, if any. Read by the
|
|
187
|
+
* router when registering routes.
|
|
188
|
+
*/
|
|
87
189
|
getOnRouteTriggered() {
|
|
88
190
|
return this.onRouteTriggered;
|
|
89
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Registers a hook to run at the start of every request. No-op by default;
|
|
194
|
+
* the built-in adapters accept a `(req, res, done) => void | Promise<void>`
|
|
195
|
+
* function and call `done()` to continue processing. Intended for
|
|
196
|
+
* instrumentation and devtools.
|
|
197
|
+
*/
|
|
90
198
|
setOnRequestHook(onRequestHook) { }
|
|
199
|
+
/**
|
|
200
|
+
* Registers a hook to run once a response has been sent. No-op by default;
|
|
201
|
+
* the built-in adapters accept a `(req, res) => void | Promise<void>`
|
|
202
|
+
* function. Intended for instrumentation and devtools.
|
|
203
|
+
*/
|
|
91
204
|
setOnResponseHook(onResponseHook) { }
|
|
205
|
+
/**
|
|
206
|
+
* Called by `app.close()` before the shutdown hooks run. No-op by default;
|
|
207
|
+
* override to enter a "shutting down" state.
|
|
208
|
+
*
|
|
209
|
+
* @see {@link HttpServer.beforeClose}
|
|
210
|
+
*/
|
|
211
|
+
beforeClose() { }
|
|
212
|
+
/**
|
|
213
|
+
* Translates a framework-native error into something the exception filters
|
|
214
|
+
* understand. Invoked by the global exception layer with every error it
|
|
215
|
+
* receives, before it reaches the filters; the returned value is what the
|
|
216
|
+
* filters see. Returns the error unchanged by default. The built-in
|
|
217
|
+
* adapters map, for instance, body-parser `SyntaxError`s to
|
|
218
|
+
* `BadRequestException`.
|
|
219
|
+
*/
|
|
220
|
+
mapException(error) {
|
|
221
|
+
return error;
|
|
222
|
+
}
|
|
92
223
|
}
|
|
93
|
-
exports.AbstractHttpAdapter = AbstractHttpAdapter;
|
package/adapters/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './http-adapter';
|
|
1
|
+
export * from './http-adapter.js';
|
package/adapters/index.js
CHANGED
package/application-config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, VersioningOptions, WebSocketAdapter } from '@nestjs/common';
|
|
2
|
-
import { GlobalPrefixOptions } from '@nestjs/common/
|
|
3
|
-
import { InstanceWrapper } from './injector/instance-wrapper';
|
|
4
|
-
import { ExcludeRouteMetadata } from './router/interfaces/exclude-route-metadata.interface';
|
|
1
|
+
import type { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, PreRequestHook, RouteConflictPolicy, RouteResolutionStrategy, VersioningOptions, WebSocketAdapter } from '@nestjs/common';
|
|
2
|
+
import type { GlobalPrefixOptions } from '@nestjs/common/internal';
|
|
3
|
+
import { InstanceWrapper } from './injector/instance-wrapper.js';
|
|
4
|
+
import { ExcludeRouteMetadata } from './router/interfaces/exclude-route-metadata.interface.js';
|
|
5
5
|
export declare class ApplicationConfig {
|
|
6
6
|
private ioAdapter;
|
|
7
7
|
private globalPrefix;
|
|
@@ -10,7 +10,10 @@ export declare class ApplicationConfig {
|
|
|
10
10
|
private globalFilters;
|
|
11
11
|
private globalInterceptors;
|
|
12
12
|
private globalGuards;
|
|
13
|
+
private globalPreRequestHooks;
|
|
13
14
|
private versioningOptions;
|
|
15
|
+
private routeConflictPolicy;
|
|
16
|
+
private routeResolutionStrategy;
|
|
14
17
|
private readonly globalRequestPipes;
|
|
15
18
|
private readonly globalRequestFilters;
|
|
16
19
|
private readonly globalRequestInterceptors;
|
|
@@ -42,6 +45,12 @@ export declare class ApplicationConfig {
|
|
|
42
45
|
getGlobalRequestFilters(): InstanceWrapper<ExceptionFilter>[];
|
|
43
46
|
addGlobalRequestGuard(wrapper: InstanceWrapper<CanActivate>): void;
|
|
44
47
|
getGlobalRequestGuards(): InstanceWrapper<CanActivate>[];
|
|
48
|
+
registerPreRequestHook(...hooks: PreRequestHook[]): void;
|
|
49
|
+
getGlobalPreRequestHooks(): PreRequestHook[];
|
|
45
50
|
enableVersioning(options: VersioningOptions): void;
|
|
46
51
|
getVersioning(): VersioningOptions | undefined;
|
|
52
|
+
setRouteConflictPolicy(policy: RouteConflictPolicy | undefined): void;
|
|
53
|
+
getRouteConflictPolicy(): RouteConflictPolicy | undefined;
|
|
54
|
+
setRouteResolutionStrategy(strategy: RouteResolutionStrategy | undefined): void;
|
|
55
|
+
getRouteResolutionStrategy(): RouteResolutionStrategy | undefined;
|
|
47
56
|
}
|