@nestjs/common 8.4.4 → 9.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/Readme.md +3 -2
  2. package/cache/cache.constants.d.ts +0 -1
  3. package/cache/cache.constants.js +1 -2
  4. package/cache/cache.module-definition.d.ts +2 -0
  5. package/cache/cache.module-definition.js +10 -0
  6. package/cache/cache.module.d.ts +2 -3
  7. package/cache/cache.module.js +6 -43
  8. package/cache/cache.providers.js +2 -1
  9. package/cache/interfaces/cache-module.interface.d.ts +6 -2
  10. package/decorators/core/controller.decorator.js +1 -1
  11. package/index.d.ts +2 -2
  12. package/index.js +1 -1
  13. package/interfaces/http/http-server.interface.d.ts +2 -2
  14. package/interfaces/http/index.d.ts +1 -0
  15. package/interfaces/http/index.js +1 -0
  16. package/interfaces/http/raw-body-request.interface.d.ts +4 -0
  17. package/{http/interfaces/http-module.interface.js → interfaces/http/raw-body-request.interface.js} +0 -0
  18. package/interfaces/modules/provider.interface.d.ts +27 -1
  19. package/interfaces/nest-application-options.interface.d.ts +4 -0
  20. package/interfaces/nest-application.interface.d.ts +0 -16
  21. package/interfaces/nest-microservice.interface.d.ts +0 -7
  22. package/interfaces/scope-options.interface.d.ts +7 -0
  23. package/module-utils/configurable-module.builder.d.ts +93 -0
  24. package/module-utils/configurable-module.builder.js +195 -0
  25. package/module-utils/constants.d.ts +4 -0
  26. package/module-utils/constants.js +7 -0
  27. package/module-utils/index.d.ts +2 -0
  28. package/{http → module-utils}/index.js +1 -2
  29. package/module-utils/interfaces/configurable-module-async-options.interface.d.ts +36 -0
  30. package/module-utils/interfaces/configurable-module-async-options.interface.js +2 -0
  31. package/module-utils/interfaces/configurable-module-cls.interface.d.ts +13 -0
  32. package/module-utils/interfaces/configurable-module-cls.interface.js +2 -0
  33. package/module-utils/interfaces/configurable-module-host.interface.d.ts +62 -0
  34. package/module-utils/interfaces/configurable-module-host.interface.js +2 -0
  35. package/module-utils/interfaces/index.d.ts +3 -0
  36. package/module-utils/interfaces/index.js +6 -0
  37. package/module-utils/utils/generate-options-injection-token.util.d.ts +1 -0
  38. package/module-utils/utils/generate-options-injection-token.util.js +9 -0
  39. package/package.json +2 -3
  40. package/pipes/parse-bool.pipe.d.ts +12 -0
  41. package/pipes/parse-bool.pipe.js +18 -2
  42. package/pipes/parse-float.pipe.d.ts +5 -0
  43. package/pipes/parse-float.pipe.js +10 -4
  44. package/pipes/parse-int.pipe.d.ts +5 -0
  45. package/pipes/parse-int.pipe.js +10 -4
  46. package/pipes/parse-uuid.pipe.d.ts +7 -0
  47. package/pipes/parse-uuid.pipe.js +19 -5
  48. package/utils/shared.utils.d.ts +0 -5
  49. package/utils/shared.utils.js +1 -6
  50. package/http/http.constants.d.ts +0 -3
  51. package/http/http.constants.js +0 -6
  52. package/http/http.module.d.ts +0 -11
  53. package/http/http.module.js +0 -88
  54. package/http/http.service.d.ts +0 -19
  55. package/http/http.service.js +0 -74
  56. package/http/index.d.ts +0 -3
  57. package/http/interfaces/http-module.interface.d.ts +0 -13
  58. package/http/interfaces/index.d.ts +0 -1
  59. package/http/interfaces/index.js +0 -4
  60. package/utils/is-uuid.d.ts +0 -1
  61. package/utils/is-uuid.js +0 -19
package/Readme.md CHANGED
@@ -72,11 +72,12 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
72
72
 
73
73
  <table style="text-align:center;"><tr><td>
74
74
  <a href="https://careers.labster.com/departments/platform" target="_blank"><img src="https://nestjs.com/img/labster-logo.png" width="170" valign="middle" /></a></td><td>
75
- <a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="150" valign="middle" /></a></td>
75
+ <a href="https://weld.app/" target="_blank"><img src="https://nestjs.com/img/weld-logo.svg" width="140" valign="middle" /></a></td>
76
76
  <td>
77
77
  <a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/intrinisic-logo.png" width="210" valign="middle" /></a></td>
78
78
  <td>
79
- <a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/jetbrains-logo.svg" width="110" valign="middle" /></a></td></</tr></table>
79
+ <a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/jetbrains-logo.svg" width="110" valign="middle" /></a></td><td>
80
+ <a href="https://snyk.co/nestjs" target="_blank"><img src="https://nestjs.com/img/snyk-logo-black.png" width="185" valign="middle" /></a></td></</tr></table>
80
81
 
81
82
  #### Silver Sponsors
82
83
 
@@ -1,4 +1,3 @@
1
1
  export declare const CACHE_MANAGER = "CACHE_MANAGER";
2
- export declare const CACHE_MODULE_OPTIONS = "CACHE_MODULE_OPTIONS";
3
2
  export declare const CACHE_KEY_METADATA = "cache_module:cache_key";
4
3
  export declare const CACHE_TTL_METADATA = "cache_module:cache_ttl";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CACHE_TTL_METADATA = exports.CACHE_KEY_METADATA = exports.CACHE_MODULE_OPTIONS = exports.CACHE_MANAGER = void 0;
3
+ exports.CACHE_TTL_METADATA = exports.CACHE_KEY_METADATA = exports.CACHE_MANAGER = void 0;
4
4
  exports.CACHE_MANAGER = 'CACHE_MANAGER';
5
- exports.CACHE_MODULE_OPTIONS = 'CACHE_MODULE_OPTIONS';
6
5
  exports.CACHE_KEY_METADATA = 'cache_module:cache_key';
7
6
  exports.CACHE_TTL_METADATA = 'cache_module:cache_ttl';
@@ -0,0 +1,2 @@
1
+ import { CacheModuleOptions } from './interfaces/cache-module.interface';
2
+ export declare const ConfigurableModuleClass: import("../module-utils").ConfigurableModuleCls<CacheModuleOptions<Record<string, any>>, "register", "createCacheOptions", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
5
+ const module_utils_1 = require("../module-utils");
6
+ _a = new module_utils_1.ConfigurableModuleBuilder({
7
+ moduleName: 'Cache',
8
+ })
9
+ .setFactoryMethodName('createCacheOptions')
10
+ .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
@@ -1,4 +1,5 @@
1
1
  import { DynamicModule } from '../interfaces';
2
+ import { ConfigurableModuleClass } from './cache.module-definition';
2
3
  import { CacheModuleAsyncOptions, CacheModuleOptions } from './interfaces/cache-module.interface';
3
4
  /**
4
5
  * Module that provides Nest cache-manager.
@@ -7,7 +8,7 @@ import { CacheModuleAsyncOptions, CacheModuleOptions } from './interfaces/cache-
7
8
  *
8
9
  * @publicApi
9
10
  */
10
- export declare class CacheModule {
11
+ export declare class CacheModule extends ConfigurableModuleClass {
11
12
  /**
12
13
  * Configure the cache manager statically.
13
14
  *
@@ -25,6 +26,4 @@ export declare class CacheModule {
25
26
  * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
26
27
  */
27
28
  static registerAsync<StoreConfig extends Record<any, any> = Record<string, any>>(options: CacheModuleAsyncOptions<StoreConfig>): DynamicModule;
28
- private static createAsyncProviders;
29
- private static createAsyncOptionsProvider;
30
29
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
- var CacheModule_1;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.CacheModule = void 0;
5
4
  const tslib_1 = require("tslib");
6
5
  const decorators_1 = require("../decorators");
7
6
  const cache_constants_1 = require("./cache.constants");
7
+ const cache_module_definition_1 = require("./cache.module-definition");
8
8
  const cache_providers_1 = require("./cache.providers");
9
9
  /**
10
10
  * Module that provides Nest cache-manager.
@@ -13,7 +13,7 @@ const cache_providers_1 = require("./cache.providers");
13
13
  *
14
14
  * @publicApi
15
15
  */
16
- let CacheModule = CacheModule_1 = class CacheModule {
16
+ let CacheModule = class CacheModule extends cache_module_definition_1.ConfigurableModuleClass {
17
17
  /**
18
18
  * Configure the cache manager statically.
19
19
  *
@@ -22,11 +22,7 @@ let CacheModule = CacheModule_1 = class CacheModule {
22
22
  * @see [Customize caching](https://docs.nestjs.com/techniques/caching#customize-caching)
23
23
  */
24
24
  static register(options = {}) {
25
- return {
26
- module: CacheModule_1,
27
- global: options.isGlobal,
28
- providers: [{ provide: cache_constants_1.CACHE_MODULE_OPTIONS, useValue: options }],
29
- };
25
+ return Object.assign({ global: options.isGlobal }, super.register(options));
30
26
  }
31
27
  /**
32
28
  * Configure the cache manager dynamically.
@@ -37,44 +33,11 @@ let CacheModule = CacheModule_1 = class CacheModule {
37
33
  * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
38
34
  */
39
35
  static registerAsync(options) {
40
- return {
41
- module: CacheModule_1,
42
- global: options.isGlobal,
43
- imports: options.imports,
44
- providers: [
45
- ...this.createAsyncProviders(options),
46
- ...(options.extraProviders || []),
47
- ],
48
- };
49
- }
50
- static createAsyncProviders(options) {
51
- if (options.useExisting || options.useFactory) {
52
- return [this.createAsyncOptionsProvider(options)];
53
- }
54
- return [
55
- this.createAsyncOptionsProvider(options),
56
- {
57
- provide: options.useClass,
58
- useClass: options.useClass,
59
- },
60
- ];
61
- }
62
- static createAsyncOptionsProvider(options) {
63
- if (options.useFactory) {
64
- return {
65
- provide: cache_constants_1.CACHE_MODULE_OPTIONS,
66
- useFactory: options.useFactory,
67
- inject: options.inject || [],
68
- };
69
- }
70
- return {
71
- provide: cache_constants_1.CACHE_MODULE_OPTIONS,
72
- useFactory: async (optionsFactory) => optionsFactory.createCacheOptions(),
73
- inject: [options.useExisting || options.useClass],
74
- };
36
+ const moduleDefinition = super.registerAsync(options);
37
+ return Object.assign(Object.assign({ global: options.isGlobal }, moduleDefinition), { providers: moduleDefinition.providers.concat(options.extraProviders) });
75
38
  }
76
39
  };
77
- CacheModule = CacheModule_1 = tslib_1.__decorate([
40
+ CacheModule = tslib_1.__decorate([
78
41
  (0, decorators_1.Module)({
79
42
  providers: [(0, cache_providers_1.createCacheManager)()],
80
43
  exports: [cache_constants_1.CACHE_MANAGER],
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCacheManager = void 0;
4
4
  const load_package_util_1 = require("../utils/load-package.util");
5
5
  const cache_constants_1 = require("./cache.constants");
6
+ const cache_module_definition_1 = require("./cache.module-definition");
6
7
  const default_options_1 = require("./default-options");
7
8
  /**
8
9
  * Creates a CacheManager Provider.
@@ -18,7 +19,7 @@ function createCacheManager() {
18
19
  ? cacheManager.multiCaching(options.map(store => cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), (store || {})))))
19
20
  : cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), (options || {})));
20
21
  },
21
- inject: [cache_constants_1.CACHE_MODULE_OPTIONS],
22
+ inject: [cache_module_definition_1.MODULE_OPTIONS_TOKEN],
22
23
  };
23
24
  }
24
25
  exports.createCacheManager = createCacheManager;
@@ -1,4 +1,5 @@
1
- import { ModuleMetadata, Provider, Type } from '../../interfaces';
1
+ import { Provider, Type } from '../../interfaces';
2
+ import { ConfigurableModuleAsyncOptions } from '../../module-utils';
2
3
  import { CacheManagerOptions } from './cache-manager.interface';
3
4
  export declare type CacheModuleOptions<StoreConfig extends Record<any, any> = Record<string, any>> = CacheManagerOptions & StoreConfig & {
4
5
  /**
@@ -24,7 +25,7 @@ export interface CacheOptionsFactory<StoreConfig extends Record<any, any> = Reco
24
25
  *
25
26
  * @publicApi
26
27
  */
27
- export interface CacheModuleAsyncOptions<StoreConfig extends Record<any, any> = Record<string, any>> extends Pick<ModuleMetadata, 'imports'> {
28
+ export interface CacheModuleAsyncOptions<StoreConfig extends Record<any, any> = Record<string, any>> extends ConfigurableModuleAsyncOptions<CacheModuleOptions<StoreConfig>, keyof CacheOptionsFactory> {
28
29
  /**
29
30
  * Injection token resolving to an existing provider. The provider must implement
30
31
  * the `CacheOptionsFactory` interface.
@@ -44,6 +45,9 @@ export interface CacheModuleAsyncOptions<StoreConfig extends Record<any, any> =
44
45
  * Dependencies that a Factory may inject.
45
46
  */
46
47
  inject?: any[];
48
+ /**
49
+ * Extra providers to be registered within a scope of this module.
50
+ */
47
51
  extraProviders?: Provider[];
48
52
  /**
49
53
  * If "true', register `CacheModule` as a global module.
@@ -46,7 +46,7 @@ function Controller(prefixOrOptions) {
46
46
  : [
47
47
  prefixOrOptions.path || defaultPath,
48
48
  prefixOrOptions.host,
49
- { scope: prefixOrOptions.scope },
49
+ { scope: prefixOrOptions.scope, durable: prefixOrOptions.durable },
50
50
  Array.isArray(prefixOrOptions.version)
51
51
  ? Array.from(new Set(prefixOrOptions.version))
52
52
  : prefixOrOptions.version,
package/index.d.ts CHANGED
@@ -4,8 +4,8 @@ export * from './decorators';
4
4
  export * from './enums';
5
5
  export * from './exceptions';
6
6
  export * from './file-stream';
7
- export * from './http';
8
- export { Abstract, ArgumentMetadata, ArgumentsHost, BeforeApplicationShutdown, CallHandler, CanActivate, ClassProvider, ContextType, DynamicModule, ExceptionFilter, ExecutionContext, ExistingProvider, FactoryProvider, ForwardReference, HttpServer, INestApplication, INestApplicationContext, INestMicroservice, InjectionToken, IntrospectionResult, MessageEvent, MiddlewareConsumer, ModuleMetadata, NestApplicationOptions, NestHybridApplicationOptions, NestInterceptor, NestMiddleware, NestModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy, OnModuleInit, OptionalFactoryDependency, Paramtype, PipeTransform, Provider, RpcExceptionFilter, Scope, ScopeOptions, Type, ValidationError, ValueProvider, VersioningOptions, VERSION_NEUTRAL, WebSocketAdapter, WsExceptionFilter, WsMessageHandler, } from './interfaces';
7
+ export { Abstract, ArgumentMetadata, ArgumentsHost, BeforeApplicationShutdown, CallHandler, CanActivate, ClassProvider, ContextType, DynamicModule, ExceptionFilter, ExecutionContext, ExistingProvider, FactoryProvider, ForwardReference, HttpServer, INestApplication, INestApplicationContext, INestMicroservice, InjectionToken, IntrospectionResult, MessageEvent, MiddlewareConsumer, ModuleMetadata, NestApplicationOptions, NestHybridApplicationOptions, NestInterceptor, NestMiddleware, NestModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy, OnModuleInit, OptionalFactoryDependency, Paramtype, PipeTransform, Provider, RawBodyRequest, RpcExceptionFilter, Scope, ScopeOptions, Type, ValidationError, ValueProvider, VersioningOptions, VERSION_NEUTRAL, WebSocketAdapter, WsExceptionFilter, WsMessageHandler, } from './interfaces';
8
+ export * from './module-utils';
9
9
  export * from './pipes';
10
10
  export * from './serializer';
11
11
  export * from './services';
package/index.js CHANGED
@@ -14,10 +14,10 @@ tslib_1.__exportStar(require("./decorators"), exports);
14
14
  tslib_1.__exportStar(require("./enums"), exports);
15
15
  tslib_1.__exportStar(require("./exceptions"), exports);
16
16
  tslib_1.__exportStar(require("./file-stream"), exports);
17
- tslib_1.__exportStar(require("./http"), exports);
18
17
  var interfaces_1 = require("./interfaces");
19
18
  Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return interfaces_1.Scope; } });
20
19
  Object.defineProperty(exports, "VERSION_NEUTRAL", { enumerable: true, get: function () { return interfaces_1.VERSION_NEUTRAL; } });
20
+ tslib_1.__exportStar(require("./module-utils"), exports);
21
21
  tslib_1.__exportStar(require("./pipes"), exports);
22
22
  tslib_1.__exportStar(require("./serializer"), exports);
23
23
  tslib_1.__exportStar(require("./services"), exports);
@@ -40,12 +40,12 @@ export interface HttpServer<TRequest = any, TResponse = any> {
40
40
  getRequestMethod?(request: TRequest): string;
41
41
  getRequestUrl?(request: TRequest): string;
42
42
  getInstance(): any;
43
- registerParserMiddleware(): any;
43
+ registerParserMiddleware(...args: any[]): any;
44
44
  enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>): any;
45
45
  getHttpServer(): any;
46
46
  initHttpServer(options: NestApplicationOptions): void;
47
47
  close(): any;
48
48
  getType(): string;
49
49
  init?(): Promise<void>;
50
- applyVersionFilter?(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
50
+ applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): (req: TRequest, res: TResponse, next: () => void) => Function;
51
51
  }
@@ -1,2 +1,3 @@
1
1
  export * from './http-server.interface';
2
2
  export * from './message-event.interface';
3
+ export * from './raw-body-request.interface';
@@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./http-server.interface"), exports);
5
5
  tslib_1.__exportStar(require("./message-event.interface"), exports);
6
+ tslib_1.__exportStar(require("./raw-body-request.interface"), exports);
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare type RawBodyRequest<T> = T & {
3
+ rawBody?: Buffer;
4
+ };
@@ -39,6 +39,19 @@ export interface ClassProvider<T = any> {
39
39
  * Optional enum defining lifetime of the provider that is injected.
40
40
  */
41
41
  scope?: Scope;
42
+ /**
43
+ * This option is only available on factory providers!
44
+ *
45
+ * @see [Use factory](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory)
46
+ */
47
+ inject?: never;
48
+ /**
49
+ * Flags provider as durable. This flag can be used in combination with custom context id
50
+ * factory strategy to construct lazy DI subtrees.
51
+ *
52
+ * This flag can be used only in conjunction with scope = Scope.REQUEST.
53
+ */
54
+ durable?: boolean;
42
55
  }
43
56
  /**
44
57
  * Interface defining a *Value* type provider.
@@ -64,6 +77,12 @@ export interface ValueProvider<T = any> {
64
77
  * Instance of a provider to be injected.
65
78
  */
66
79
  useValue: T;
80
+ /**
81
+ * This option is only available on factory providers!
82
+ *
83
+ * @see [Use factory](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory)
84
+ */
85
+ inject?: never;
67
86
  }
68
87
  /**
69
88
  * Interface defining a *Factory* type provider.
@@ -93,7 +112,7 @@ export interface FactoryProvider<T = any> {
93
112
  /**
94
113
  * Factory function that returns an instance of the provider to be injected.
95
114
  */
96
- useFactory: (...args: any[]) => T;
115
+ useFactory: (...args: any[]) => T | Promise<T>;
97
116
  /**
98
117
  * Optional list of providers to be injected into the context of the Factory function.
99
118
  */
@@ -102,6 +121,13 @@ export interface FactoryProvider<T = any> {
102
121
  * Optional enum defining lifetime of the provider that is returned by the Factory function.
103
122
  */
104
123
  scope?: Scope;
124
+ /**
125
+ * Flags provider as durable. This flag can be used in combination with custom context id
126
+ * factory strategy to construct lazy DI subtrees.
127
+ *
128
+ * This flag can be used only in conjunction with scope = Scope.REQUEST.
129
+ */
130
+ durable?: boolean;
105
131
  }
106
132
  /**
107
133
  * Interface defining an *Existing* (aliased) type provider.
@@ -17,4 +17,8 @@ export interface NestApplicationOptions extends NestApplicationContextOptions {
17
17
  * Set of configurable HTTPS options
18
18
  */
19
19
  httpsOptions?: HttpsOptions;
20
+ /**
21
+ * Whether to register the raw request body on the request. Use `req.rawBody`.
22
+ */
23
+ rawBody?: boolean;
20
24
  }
@@ -44,15 +44,6 @@ export interface INestApplication extends INestApplicationContext {
44
44
  */
45
45
  listen(port: number | string, callback?: () => void): Promise<any>;
46
46
  listen(port: number | string, hostname: string, callback?: () => void): Promise<any>;
47
- /**
48
- * Starts the application (can be awaited).
49
- * @deprecated use "listen" instead.
50
- *
51
- * @param {number|string} port
52
- * @param {string} [hostname]
53
- * @returns {Promise}
54
- */
55
- listenAsync(port: number | string, hostname?: string): Promise<any>;
56
47
  /**
57
48
  * Returns the url the application is listening at, based on OS and IP version. Returns as an IP value either in IPv6 or IPv4
58
49
  *
@@ -109,13 +100,6 @@ export interface INestApplication extends INestApplicationContext {
109
100
  * @returns {Promise}
110
101
  */
111
102
  startAllMicroservices(): Promise<this>;
112
- /**
113
- * Starts all connected microservices and can be awaited.
114
- * @deprecated use "startAllMicroservices" instead.
115
- *
116
- * @returns {Promise}
117
- */
118
- startAllMicroservicesAsync(): Promise<this>;
119
103
  /**
120
104
  * Registers exception filters as global filters (will be used within
121
105
  * every HTTP route handler)
@@ -16,13 +16,6 @@ export interface INestMicroservice extends INestApplicationContext {
16
16
  * @returns {void}
17
17
  */
18
18
  listen(): Promise<any>;
19
- /**
20
- * Starts the microservice (can be awaited).
21
- * @deprecated use "listen" instead.
22
- *
23
- * @returns {Promise}
24
- */
25
- listenAsync(): Promise<any>;
26
19
  /**
27
20
  * Register Ws Adapter which will be used inside Gateways.
28
21
  * Use when you want to override default `socket.io` library.
@@ -27,4 +27,11 @@ export interface ScopeOptions {
27
27
  * Specifies the lifetime of an injected Provider or Controller.
28
28
  */
29
29
  scope?: Scope;
30
+ /**
31
+ * Flags provider as durable. This flag can be used in combination with custom context id
32
+ * factory strategy to construct lazy DI subtrees.
33
+ *
34
+ * This flag can be used only in conjunction with scope = Scope.REQUEST.
35
+ */
36
+ durable?: boolean;
30
37
  }
@@ -0,0 +1,93 @@
1
+ import { DynamicModule } from '../interfaces';
2
+ import { Logger } from '../services/logger.service';
3
+ import { DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY } from './constants';
4
+ import { ConfigurableModuleHost } from './interfaces/configurable-module-host.interface';
5
+ /**
6
+ * @publicApi
7
+ */
8
+ export interface ConfigurableModuleBuilderOptions {
9
+ /**
10
+ * Specified what injection token should be used for the module options provider.
11
+ * By default, an auto-generated UUID will be used.
12
+ */
13
+ optionsInjectionToken?: string | symbol;
14
+ /**
15
+ * By default, an UUID will be used as a module options provider token.
16
+ * Explicitly specifying the "moduleName" will instruct the "ConfigurableModuleBuilder"
17
+ * to use a more descriptive provider token.
18
+ *
19
+ * For example, if `moduleName: "Cache"` then auto-generated provider token will be "CACHE_MODULE_OPTIONS".
20
+ */
21
+ moduleName?: string;
22
+ /**
23
+ * Indicates whether module should always be "transient", meaning,
24
+ * every time you call the static method to construct a dynamic module,
25
+ * regardless of what arguments you pass in, a new "unique" module will be created.
26
+ *
27
+ * @default false
28
+ */
29
+ alwaysTransient?: boolean;
30
+ }
31
+ /**
32
+ * Factory that lets you create configurable modules and
33
+ * provides a way to reduce the majority of dynamic module boilerplate.
34
+ *
35
+ * @publicApi
36
+ */
37
+ export declare class ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = {}> {
38
+ protected readonly options: ConfigurableModuleBuilderOptions;
39
+ protected staticMethodKey: StaticMethodKey;
40
+ protected factoryClassMethodKey: FactoryClassMethodKey;
41
+ protected extras: ExtraModuleDefinitionOptions;
42
+ protected transformModuleDefinition: (definition: DynamicModule, extraOptions: ExtraModuleDefinitionOptions) => DynamicModule;
43
+ protected readonly logger: Logger;
44
+ constructor(options?: ConfigurableModuleBuilderOptions, parentBuilder?: ConfigurableModuleBuilder<ModuleOptions>);
45
+ /**
46
+ * Registers the "extras" object (a set of extra options that can be used to modify the dynamic module definition).
47
+ * Values you specify within the "extras" object will be used as default values (that can be overriden by module consumers).
48
+ *
49
+ * This method also applies the so-called "module definition transform function" that takes the auto-generated
50
+ * dynamic module object ("DynamicModule") and the actual consumer "extras" object as input parameters.
51
+ * The "extras" object consists of values explicitly specified by module consumers and default values.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * .setExtras<{ isGlobal?: boolean }>({ isGlobal: false }, (definition, extras) =>
56
+ * ({ ...definition, global: extras.isGlobal })
57
+ * )
58
+ * ```
59
+ */
60
+ setExtras<ExtraModuleDefinitionOptions>(extras: ExtraModuleDefinitionOptions, transformDefinition: (definition: DynamicModule, extras: ExtraModuleDefinitionOptions) => DynamicModule): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
61
+ /**
62
+ * Dynamic modules must expose public static methods that let you pass in
63
+ * configuration parameters (control the module's behavior from the outside).
64
+ * Some frequently used names that you may have seen in other modules are:
65
+ * "forRoot", "forFeature", "register", "configure".
66
+ *
67
+ * This method "setClassMethodName" lets you specify the name of the
68
+ * method that will be auto-generated.
69
+ *
70
+ * @param key name of the method
71
+ */
72
+ setClassMethodName<StaticMethodKey extends string>(key: StaticMethodKey): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
73
+ /**
74
+ * Asynchronously configured modules (that rely on other modules, i.e. "ConfigModule")
75
+ * let you pass the configuration factory class that will be registered and instantiated as a provider.
76
+ * This provider then will be used to retrieve the module's configuration. To provide the configuration,
77
+ * the corresponding factory method must be implemented.
78
+ *
79
+ * This method ("setFactoryMethodName") lets you control what method name will have to be
80
+ * implemented by the config factory (default is "create").
81
+ *
82
+ * @param key name of the method
83
+ */
84
+ setFactoryMethodName<FactoryClassMethodKey extends string>(key: FactoryClassMethodKey): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
85
+ /**
86
+ * Returns an object consisting of multiple properties that lets you
87
+ * easily construct dynamic configurable modules. See "ConfigurableModuleHost" interface for more details.
88
+ */
89
+ build(): ConfigurableModuleHost<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
90
+ private constructInjectionTokenString;
91
+ private createConfigurableModuleCls;
92
+ private createTypeProxy;
93
+ }