@nestjs/common 8.4.6 → 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 (53) hide show
  1. package/cache/cache.constants.d.ts +0 -1
  2. package/cache/cache.constants.js +1 -2
  3. package/cache/cache.module-definition.d.ts +2 -0
  4. package/cache/cache.module-definition.js +10 -0
  5. package/cache/cache.module.d.ts +2 -3
  6. package/cache/cache.module.js +6 -43
  7. package/cache/cache.providers.js +2 -1
  8. package/cache/interfaces/cache-module.interface.d.ts +6 -2
  9. package/decorators/core/controller.decorator.js +1 -1
  10. package/index.d.ts +2 -2
  11. package/index.js +1 -1
  12. package/interfaces/http/http-server.interface.d.ts +1 -1
  13. package/interfaces/http/index.d.ts +1 -0
  14. package/interfaces/http/index.js +1 -0
  15. package/{http/interfaces → interfaces/http}/raw-body-request.interface.d.ts +0 -0
  16. package/{http/interfaces → interfaces/http}/raw-body-request.interface.js +0 -0
  17. package/interfaces/modules/provider.interface.d.ts +27 -1
  18. package/interfaces/nest-application.interface.d.ts +0 -16
  19. package/interfaces/nest-microservice.interface.d.ts +0 -7
  20. package/interfaces/scope-options.interface.d.ts +7 -0
  21. package/module-utils/configurable-module.builder.d.ts +93 -0
  22. package/module-utils/configurable-module.builder.js +195 -0
  23. package/module-utils/constants.d.ts +4 -0
  24. package/module-utils/constants.js +7 -0
  25. package/module-utils/index.d.ts +2 -0
  26. package/{http → module-utils}/index.js +1 -2
  27. package/module-utils/interfaces/configurable-module-async-options.interface.d.ts +36 -0
  28. package/{http/interfaces/http-module.interface.js → module-utils/interfaces/configurable-module-async-options.interface.js} +0 -0
  29. package/module-utils/interfaces/configurable-module-cls.interface.d.ts +13 -0
  30. package/module-utils/interfaces/configurable-module-cls.interface.js +2 -0
  31. package/module-utils/interfaces/configurable-module-host.interface.d.ts +62 -0
  32. package/module-utils/interfaces/configurable-module-host.interface.js +2 -0
  33. package/module-utils/interfaces/index.d.ts +3 -0
  34. package/module-utils/interfaces/index.js +6 -0
  35. package/module-utils/utils/generate-options-injection-token.util.d.ts +1 -0
  36. package/module-utils/utils/generate-options-injection-token.util.js +9 -0
  37. package/package.json +1 -2
  38. package/pipes/parse-uuid.pipe.d.ts +7 -0
  39. package/pipes/parse-uuid.pipe.js +19 -5
  40. package/utils/shared.utils.d.ts +0 -5
  41. package/utils/shared.utils.js +1 -6
  42. package/http/http.constants.d.ts +0 -3
  43. package/http/http.constants.js +0 -6
  44. package/http/http.module.d.ts +0 -11
  45. package/http/http.module.js +0 -88
  46. package/http/http.service.d.ts +0 -19
  47. package/http/http.service.js +0 -74
  48. package/http/index.d.ts +0 -3
  49. package/http/interfaces/http-module.interface.d.ts +0 -13
  50. package/http/interfaces/index.d.ts +0 -2
  51. package/http/interfaces/index.js +0 -5
  52. package/utils/is-uuid.d.ts +0 -1
  53. package/utils/is-uuid.js +0 -19
@@ -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);
@@ -47,5 +47,5 @@ export interface HttpServer<TRequest = any, TResponse = any> {
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);
@@ -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.
@@ -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
+ }
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigurableModuleBuilder = void 0;
4
+ const logger_service_1 = require("../services/logger.service");
5
+ const random_string_generator_util_1 = require("../utils/random-string-generator.util");
6
+ const constants_1 = require("./constants");
7
+ const generate_options_injection_token_util_1 = require("./utils/generate-options-injection-token.util");
8
+ /**
9
+ * Factory that lets you create configurable modules and
10
+ * provides a way to reduce the majority of dynamic module boilerplate.
11
+ *
12
+ * @publicApi
13
+ */
14
+ class ConfigurableModuleBuilder {
15
+ constructor(options = {}, parentBuilder) {
16
+ this.options = options;
17
+ this.logger = new logger_service_1.Logger(ConfigurableModuleBuilder.name);
18
+ if (parentBuilder) {
19
+ this.staticMethodKey = parentBuilder.staticMethodKey;
20
+ this.factoryClassMethodKey =
21
+ parentBuilder.factoryClassMethodKey;
22
+ this.transformModuleDefinition = parentBuilder.transformModuleDefinition;
23
+ this.extras = parentBuilder.extras;
24
+ }
25
+ }
26
+ /**
27
+ * Registers the "extras" object (a set of extra options that can be used to modify the dynamic module definition).
28
+ * Values you specify within the "extras" object will be used as default values (that can be overriden by module consumers).
29
+ *
30
+ * This method also applies the so-called "module definition transform function" that takes the auto-generated
31
+ * dynamic module object ("DynamicModule") and the actual consumer "extras" object as input parameters.
32
+ * The "extras" object consists of values explicitly specified by module consumers and default values.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * .setExtras<{ isGlobal?: boolean }>({ isGlobal: false }, (definition, extras) =>
37
+ * ({ ...definition, global: extras.isGlobal })
38
+ * )
39
+ * ```
40
+ */
41
+ setExtras(extras, transformDefinition) {
42
+ const builder = new ConfigurableModuleBuilder(this.options, this);
43
+ builder.extras = extras;
44
+ builder.transformModuleDefinition = transformDefinition;
45
+ return builder;
46
+ }
47
+ /**
48
+ * Dynamic modules must expose public static methods that let you pass in
49
+ * configuration parameters (control the module's behavior from the outside).
50
+ * Some frequently used names that you may have seen in other modules are:
51
+ * "forRoot", "forFeature", "register", "configure".
52
+ *
53
+ * This method "setClassMethodName" lets you specify the name of the
54
+ * method that will be auto-generated.
55
+ *
56
+ * @param key name of the method
57
+ */
58
+ setClassMethodName(key) {
59
+ const builder = new ConfigurableModuleBuilder(this.options, this);
60
+ builder.staticMethodKey = key;
61
+ return builder;
62
+ }
63
+ /**
64
+ * Asynchronously configured modules (that rely on other modules, i.e. "ConfigModule")
65
+ * let you pass the configuration factory class that will be registered and instantiated as a provider.
66
+ * This provider then will be used to retrieve the module's configuration. To provide the configuration,
67
+ * the corresponding factory method must be implemented.
68
+ *
69
+ * This method ("setFactoryMethodName") lets you control what method name will have to be
70
+ * implemented by the config factory (default is "create").
71
+ *
72
+ * @param key name of the method
73
+ */
74
+ setFactoryMethodName(key) {
75
+ const builder = new ConfigurableModuleBuilder(this.options, this);
76
+ builder.factoryClassMethodKey = key;
77
+ return builder;
78
+ }
79
+ /**
80
+ * Returns an object consisting of multiple properties that lets you
81
+ * easily construct dynamic configurable modules. See "ConfigurableModuleHost" interface for more details.
82
+ */
83
+ build() {
84
+ var _a, _b, _c, _d;
85
+ var _e;
86
+ (_a = this.staticMethodKey) !== null && _a !== void 0 ? _a : (this.staticMethodKey = constants_1.DEFAULT_METHOD_KEY);
87
+ (_b = this.factoryClassMethodKey) !== null && _b !== void 0 ? _b : (this.factoryClassMethodKey = constants_1.DEFAULT_FACTORY_CLASS_METHOD_KEY);
88
+ (_c = (_e = this.options).optionsInjectionToken) !== null && _c !== void 0 ? _c : (_e.optionsInjectionToken = this.options.moduleName
89
+ ? this.constructInjectionTokenString()
90
+ : (0, generate_options_injection_token_util_1.generateOptionsInjectionToken)());
91
+ (_d = this.transformModuleDefinition) !== null && _d !== void 0 ? _d : (this.transformModuleDefinition = definition => definition);
92
+ return {
93
+ ConfigurableModuleClass: this.createConfigurableModuleCls(),
94
+ MODULE_OPTIONS_TOKEN: this.options.optionsInjectionToken,
95
+ ASYNC_OPTIONS_TYPE: this.createTypeProxy('ASYNC_OPTIONS_TYPE'),
96
+ OPTIONS_TYPE: this.createTypeProxy('OPTIONS_TYPE'),
97
+ };
98
+ }
99
+ constructInjectionTokenString() {
100
+ const moduleNameInSnakeCase = this.options.moduleName
101
+ .trim()
102
+ .split(/(?=[A-Z])/)
103
+ .join('_')
104
+ .toUpperCase();
105
+ return `${moduleNameInSnakeCase}_MODULE_OPTIONS`;
106
+ }
107
+ createConfigurableModuleCls() {
108
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
109
+ const self = this;
110
+ const asyncMethodKey = this.staticMethodKey + constants_1.ASYNC_METHOD_SUFFIX;
111
+ class InternalModuleClass {
112
+ static [self.staticMethodKey](options) {
113
+ const providers = [
114
+ {
115
+ provide: self.options.optionsInjectionToken,
116
+ useValue: this.omitExtras(options, self.extras),
117
+ },
118
+ ];
119
+ if (self.options.alwaysTransient) {
120
+ providers.push({
121
+ provide: constants_1.CONFIGURABLE_MODULE_ID,
122
+ useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
123
+ });
124
+ }
125
+ return self.transformModuleDefinition({
126
+ module: this,
127
+ providers,
128
+ }, options);
129
+ }
130
+ static [asyncMethodKey](options) {
131
+ const providers = this.createAsyncProviders(options);
132
+ if (self.options.alwaysTransient) {
133
+ providers.push({
134
+ provide: constants_1.CONFIGURABLE_MODULE_ID,
135
+ useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
136
+ });
137
+ }
138
+ return self.transformModuleDefinition({
139
+ module: this,
140
+ imports: options.imports || [],
141
+ providers,
142
+ }, options);
143
+ }
144
+ static omitExtras(input, extras) {
145
+ if (!extras) {
146
+ return input;
147
+ }
148
+ const moduleOptions = {};
149
+ const extrasKeys = Object.keys(extras);
150
+ Object.keys(input)
151
+ .filter(key => !extrasKeys.includes(key))
152
+ .forEach(key => {
153
+ moduleOptions[key] = input[key];
154
+ });
155
+ return moduleOptions;
156
+ }
157
+ static createAsyncProviders(options) {
158
+ if (options.useExisting || options.useFactory) {
159
+ return [this.createAsyncOptionsProvider(options)];
160
+ }
161
+ return [
162
+ this.createAsyncOptionsProvider(options),
163
+ {
164
+ provide: options.useClass,
165
+ useClass: options.useClass,
166
+ },
167
+ ];
168
+ }
169
+ static createAsyncOptionsProvider(options) {
170
+ if (options.useFactory) {
171
+ return {
172
+ provide: self.options.optionsInjectionToken,
173
+ useFactory: options.useFactory,
174
+ inject: options.inject || [],
175
+ };
176
+ }
177
+ return {
178
+ provide: self.options.optionsInjectionToken,
179
+ useFactory: async (optionsFactory) => await optionsFactory[self.factoryClassMethodKey](),
180
+ inject: [options.useExisting || options.useClass],
181
+ };
182
+ }
183
+ }
184
+ return InternalModuleClass;
185
+ }
186
+ createTypeProxy(typeName) {
187
+ const proxy = new Proxy({}, {
188
+ get: () => {
189
+ throw new Error(`"${typeName}" is not supposed to be used as a value.`);
190
+ },
191
+ });
192
+ return proxy;
193
+ }
194
+ }
195
+ exports.ConfigurableModuleBuilder = ConfigurableModuleBuilder;
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_METHOD_KEY = "register";
2
+ export declare const DEFAULT_FACTORY_CLASS_METHOD_KEY = "create";
3
+ export declare const ASYNC_METHOD_SUFFIX = "Async";
4
+ export declare const CONFIGURABLE_MODULE_ID = "CONFIGURABLE_MODULE_ID";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIGURABLE_MODULE_ID = exports.ASYNC_METHOD_SUFFIX = exports.DEFAULT_FACTORY_CLASS_METHOD_KEY = exports.DEFAULT_METHOD_KEY = void 0;
4
+ exports.DEFAULT_METHOD_KEY = 'register';
5
+ exports.DEFAULT_FACTORY_CLASS_METHOD_KEY = 'create';
6
+ exports.ASYNC_METHOD_SUFFIX = 'Async';
7
+ exports.CONFIGURABLE_MODULE_ID = 'CONFIGURABLE_MODULE_ID';
@@ -0,0 +1,2 @@
1
+ export * from './configurable-module.builder';
2
+ export * from './interfaces';
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./http.module"), exports);
5
- tslib_1.__exportStar(require("./http.service"), exports);
4
+ tslib_1.__exportStar(require("./configurable-module.builder"), exports);
6
5
  tslib_1.__exportStar(require("./interfaces"), exports);
@@ -0,0 +1,36 @@
1
+ import { FactoryProvider, ModuleMetadata, Type } from '../../interfaces';
2
+ import { DEFAULT_FACTORY_CLASS_METHOD_KEY } from '../constants';
3
+ /**
4
+ * Interface that must be implemented by the module options factory class.
5
+ * Method key varies depending on the "FactoryClassMethodKey" type argument.
6
+ *
7
+ * @publicApi
8
+ */
9
+ export declare type ConfigurableModuleOptionsFactory<ModuleOptions, FactoryClassMethodKey extends string> = Record<`${FactoryClassMethodKey}`, () => Promise<ModuleOptions> | ModuleOptions>;
10
+ /**
11
+ * Interface that represents the module async options object
12
+ * Factory method name varies depending on the "FactoryClassMethodKey" type argument.
13
+ *
14
+ * @publicApi
15
+ */
16
+ export interface ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY> extends Pick<ModuleMetadata, 'imports'> {
17
+ /**
18
+ * Injection token resolving to an existing provider. The provider must implement
19
+ * the corresponding interface.
20
+ */
21
+ useExisting?: Type<ConfigurableModuleOptionsFactory<ModuleOptions, FactoryClassMethodKey>>;
22
+ /**
23
+ * Injection token resolving to a class that will be instantiated as a provider.
24
+ * The class must implement the corresponding interface.
25
+ */
26
+ useClass?: Type<ConfigurableModuleOptionsFactory<ModuleOptions, FactoryClassMethodKey>>;
27
+ /**
28
+ * Function returning options (or a Promise resolving to options) to configure the
29
+ * cache module.
30
+ */
31
+ useFactory?: (...args: unknown[]) => Promise<ModuleOptions> | ModuleOptions;
32
+ /**
33
+ * Dependencies that a Factory may inject.
34
+ */
35
+ inject?: FactoryProvider['inject'];
36
+ }
@@ -0,0 +1,13 @@
1
+ import { DynamicModule } from '../../interfaces';
2
+ import { DEFAULT_FACTORY_CLASS_METHOD_KEY, DEFAULT_METHOD_KEY } from '../constants';
3
+ import { ConfigurableModuleAsyncOptions } from './configurable-module-async-options.interface';
4
+ /**
5
+ * Class that represents a blueprint/prototype for a configurable Nest module.
6
+ * This class provides static methods for constructing dynamic modules. Their names
7
+ * can be controlled through the "MethodKey" type argument.
8
+ *
9
+ * @publicApi
10
+ */
11
+ export declare type ConfigurableModuleCls<ModuleOptions, MethodKey extends string = typeof DEFAULT_METHOD_KEY, FactoryClassMethodKey extends string = typeof DEFAULT_FACTORY_CLASS_METHOD_KEY, ExtraModuleDefinitionOptions = {}> = {
12
+ new (): any;
13
+ } & Record<`${MethodKey}`, (options: ModuleOptions & ExtraModuleDefinitionOptions) => DynamicModule> & Record<`${MethodKey}Async`, (options: ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey> & ExtraModuleDefinitionOptions) => DynamicModule>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,62 @@
1
+ import { ConfigurableModuleAsyncOptions } from './configurable-module-async-options.interface';
2
+ import { ConfigurableModuleCls } from './configurable-module-cls.interface';
3
+ /**
4
+ * Configurable module host. See properties for more details
5
+ *
6
+ * @publicApi
7
+ */
8
+ export interface ConfigurableModuleHost<ModuleOptions = Record<string, unknown>, MethodKey extends string = string, FactoryClassMethodKey extends string = string, ExtraModuleDefinitionOptions = {}> {
9
+ /**
10
+ * Class that represents a blueprint/prototype for a configurable Nest module.
11
+ * This class provides static methods for constructing dynamic modules. Their names
12
+ * can be controlled through the "MethodKey" type argument.
13
+ *
14
+ * Your module class should inherit from this class to make the static methods available.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * @Module({})
19
+ * class IntegrationModule extends ConfigurableModuleCls {
20
+ * // ...
21
+ * }
22
+ * ```
23
+ */
24
+ ConfigurableModuleClass: ConfigurableModuleCls<ModuleOptions, MethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
25
+ /**
26
+ * Module options provider token. Can be used to inject the "options object" to
27
+ * providers registered within the host module.
28
+ */
29
+ MODULE_OPTIONS_TOKEN: string | symbol;
30
+ /**
31
+ * Can be used to auto-infer the compound "async module options" type.
32
+ * Note: this property is not supposed to be used as a value.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * @Module({})
37
+ * class IntegrationModule extends ConfigurableModuleCls {
38
+ * static module = initializer(IntegrationModule);
39
+ *
40
+ * static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule {
41
+ * return super.registerAsync(options);
42
+ * }
43
+ * ```
44
+ */
45
+ ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<ModuleOptions, FactoryClassMethodKey> & ExtraModuleDefinitionOptions;
46
+ /**
47
+ * Can be used to auto-infer the compound "module options" type (options interface + extra module definition options).
48
+ * Note: this property is not supposed to be used as a value.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * @Module({})
53
+ * class IntegrationModule extends ConfigurableModuleCls {
54
+ * static module = initializer(IntegrationModule);
55
+ *
56
+ * static register(options: typeof OPTIONS_TYPE): DynamicModule {
57
+ * return super.register(options);
58
+ * }
59
+ * ```
60
+ */
61
+ OPTIONS_TYPE: ModuleOptions & ExtraModuleDefinitionOptions;
62
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './configurable-module-async-options.interface';
2
+ export * from './configurable-module-cls.interface';
3
+ export * from './configurable-module-host.interface';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./configurable-module-async-options.interface"), exports);
5
+ tslib_1.__exportStar(require("./configurable-module-cls.interface"), exports);
6
+ tslib_1.__exportStar(require("./configurable-module-host.interface"), exports);
@@ -0,0 +1 @@
1
+ export declare function generateOptionsInjectionToken(): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateOptionsInjectionToken = void 0;
4
+ const random_string_generator_util_1 = require("../../utils/random-string-generator.util");
5
+ function generateOptionsInjectionToken() {
6
+ const hash = (0, random_string_generator_util_1.randomStringGenerator)();
7
+ return `CONFIGURABLE_MODULE_OPTIONS[${hash}]`;
8
+ }
9
+ exports.generateOptionsInjectionToken = generateOptionsInjectionToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "8.4.6",
3
+ "version": "9.0.0-next.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -17,7 +17,6 @@
17
17
  },
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "axios": "0.27.2",
21
20
  "iterare": "1.2.1",
22
21
  "tslib": "2.4.0",
23
22
  "uuid": "8.3.2"
@@ -6,8 +6,15 @@ export interface ParseUUIDPipeOptions {
6
6
  exceptionFactory?: (errors: string) => any;
7
7
  }
8
8
  export declare class ParseUUIDPipe implements PipeTransform<string> {
9
+ protected static uuidRegExps: {
10
+ 3: RegExp;
11
+ 4: RegExp;
12
+ 5: RegExp;
13
+ all: RegExp;
14
+ };
9
15
  private readonly version;
10
16
  protected exceptionFactory: (errors: string) => any;
11
17
  constructor(options?: ParseUUIDPipeOptions);
12
18
  transform(value: string, metadata: ArgumentMetadata): Promise<string>;
19
+ protected isUUID(str: unknown, version?: string): any;
13
20
  }
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var ParseUUIDPipe_1;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.ParseUUIDPipe = void 0;
4
5
  const tslib_1 = require("tslib");
@@ -6,8 +7,8 @@ const injectable_decorator_1 = require("../decorators/core/injectable.decorator"
6
7
  const optional_decorator_1 = require("../decorators/core/optional.decorator");
7
8
  const http_status_enum_1 = require("../enums/http-status.enum");
8
9
  const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
9
- const is_uuid_1 = require("../utils/is-uuid");
10
- let ParseUUIDPipe = class ParseUUIDPipe {
10
+ const shared_utils_1 = require("../utils/shared.utils");
11
+ let ParseUUIDPipe = ParseUUIDPipe_1 = class ParseUUIDPipe {
11
12
  constructor(options) {
12
13
  options = options || {};
13
14
  const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST, version, } = options;
@@ -17,13 +18,26 @@ let ParseUUIDPipe = class ParseUUIDPipe {
17
18
  (error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
18
19
  }
19
20
  async transform(value, metadata) {
20
- if (!(0, is_uuid_1.isUUID)(value, this.version)) {
21
- throw this.exceptionFactory(`Validation failed (uuid ${this.version ? 'v' + this.version : ''} is expected)`);
21
+ if (!this.isUUID(value, this.version)) {
22
+ throw this.exceptionFactory(`Validation failed (uuid${this.version ? ` v ${this.version}` : ''} is expected)`);
22
23
  }
23
24
  return value;
24
25
  }
26
+ isUUID(str, version = 'all') {
27
+ if (!(0, shared_utils_1.isString)(str)) {
28
+ throw this.exceptionFactory('The value passed as UUID is not a string');
29
+ }
30
+ const pattern = ParseUUIDPipe_1.uuidRegExps[version];
31
+ return pattern === null || pattern === void 0 ? void 0 : pattern.test(str);
32
+ }
33
+ };
34
+ ParseUUIDPipe.uuidRegExps = {
35
+ 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
36
+ 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
37
+ 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
38
+ all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
25
39
  };
26
- ParseUUIDPipe = tslib_1.__decorate([
40
+ ParseUUIDPipe = ParseUUIDPipe_1 = tslib_1.__decorate([
27
41
  (0, injectable_decorator_1.Injectable)(),
28
42
  tslib_1.__param(0, (0, optional_decorator_1.Optional)()),
29
43
  tslib_1.__metadata("design:paramtypes", [Object])
@@ -2,11 +2,6 @@ export declare const isUndefined: (obj: any) => obj is undefined;
2
2
  export declare const isObject: (fn: any) => fn is object;
3
3
  export declare const isPlainObject: (fn: any) => fn is object;
4
4
  export declare const addLeadingSlash: (path?: string) => string;
5
- /**
6
- * Deprecated. Use the "addLeadingSlash" function instead.
7
- * @deprecated
8
- */
9
- export declare const validatePath: (path?: string) => string;
10
5
  export declare const normalizePath: (path?: string) => string;
11
6
  export declare const stripEndSlash: (path: string) => string;
12
7
  export declare const isFunction: (val: any) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSymbol = exports.isEmpty = exports.isNil = exports.isConstructor = exports.isNumber = exports.isString = exports.isFunction = exports.stripEndSlash = exports.normalizePath = exports.validatePath = exports.addLeadingSlash = exports.isPlainObject = exports.isObject = exports.isUndefined = void 0;
3
+ exports.isSymbol = exports.isEmpty = exports.isNil = exports.isConstructor = exports.isNumber = exports.isString = exports.isFunction = exports.stripEndSlash = exports.normalizePath = exports.addLeadingSlash = exports.isPlainObject = exports.isObject = exports.isUndefined = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-use-before-define */
5
5
  const isUndefined = (obj) => typeof obj === 'undefined';
6
6
  exports.isUndefined = isUndefined;
@@ -28,11 +28,6 @@ const addLeadingSlash = (path) => path && typeof path === 'string'
28
28
  : path
29
29
  : '';
30
30
  exports.addLeadingSlash = addLeadingSlash;
31
- /**
32
- * Deprecated. Use the "addLeadingSlash" function instead.
33
- * @deprecated
34
- */
35
- exports.validatePath = exports.addLeadingSlash;
36
31
  const normalizePath = (path) => path
37
32
  ? path.startsWith('/')
38
33
  ? ('/' + path.replace(/\/+$/, '')).replace(/\/+/g, '/')
@@ -1,3 +0,0 @@
1
- export declare const AXIOS_INSTANCE_TOKEN = "AXIOS_INSTANCE_TOKEN";
2
- export declare const HTTP_MODULE_ID = "HTTP_MODULE_ID";
3
- export declare const HTTP_MODULE_OPTIONS = "HTTP_MODULE_OPTIONS";
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HTTP_MODULE_OPTIONS = exports.HTTP_MODULE_ID = exports.AXIOS_INSTANCE_TOKEN = void 0;
4
- exports.AXIOS_INSTANCE_TOKEN = 'AXIOS_INSTANCE_TOKEN';
5
- exports.HTTP_MODULE_ID = 'HTTP_MODULE_ID';
6
- exports.HTTP_MODULE_OPTIONS = 'HTTP_MODULE_OPTIONS';
@@ -1,11 +0,0 @@
1
- import { DynamicModule } from '../interfaces';
2
- import { HttpModuleAsyncOptions, HttpModuleOptions } from './interfaces';
3
- /**
4
- * @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
5
- */
6
- export declare class HttpModule {
7
- static register(config: HttpModuleOptions): DynamicModule;
8
- static registerAsync(options: HttpModuleAsyncOptions): DynamicModule;
9
- private static createAsyncProviders;
10
- private static createAsyncOptionsProvider;
11
- }
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var HttpModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.HttpModule = void 0;
5
- const tslib_1 = require("tslib");
6
- const axios_1 = require("axios");
7
- const module_decorator_1 = require("../decorators/modules/module.decorator");
8
- const random_string_generator_util_1 = require("../utils/random-string-generator.util");
9
- const http_constants_1 = require("./http.constants");
10
- const http_service_1 = require("./http.service");
11
- /**
12
- * @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
13
- */
14
- let HttpModule = HttpModule_1 = class HttpModule {
15
- static register(config) {
16
- return {
17
- module: HttpModule_1,
18
- providers: [
19
- {
20
- provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
21
- useValue: axios_1.default.create(config),
22
- },
23
- {
24
- provide: http_constants_1.HTTP_MODULE_ID,
25
- useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
26
- },
27
- ],
28
- };
29
- }
30
- static registerAsync(options) {
31
- return {
32
- module: HttpModule_1,
33
- imports: options.imports,
34
- providers: [
35
- ...this.createAsyncProviders(options),
36
- {
37
- provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
38
- useFactory: (config) => axios_1.default.create(config),
39
- inject: [http_constants_1.HTTP_MODULE_OPTIONS],
40
- },
41
- {
42
- provide: http_constants_1.HTTP_MODULE_ID,
43
- useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
44
- },
45
- ...(options.extraProviders || []),
46
- ],
47
- };
48
- }
49
- static createAsyncProviders(options) {
50
- if (options.useExisting || options.useFactory) {
51
- return [this.createAsyncOptionsProvider(options)];
52
- }
53
- return [
54
- this.createAsyncOptionsProvider(options),
55
- {
56
- provide: options.useClass,
57
- useClass: options.useClass,
58
- },
59
- ];
60
- }
61
- static createAsyncOptionsProvider(options) {
62
- if (options.useFactory) {
63
- return {
64
- provide: http_constants_1.HTTP_MODULE_OPTIONS,
65
- useFactory: options.useFactory,
66
- inject: options.inject || [],
67
- };
68
- }
69
- return {
70
- provide: http_constants_1.HTTP_MODULE_OPTIONS,
71
- useFactory: async (optionsFactory) => optionsFactory.createHttpOptions(),
72
- inject: [options.useExisting || options.useClass],
73
- };
74
- }
75
- };
76
- HttpModule = HttpModule_1 = tslib_1.__decorate([
77
- (0, module_decorator_1.Module)({
78
- providers: [
79
- http_service_1.HttpService,
80
- {
81
- provide: http_constants_1.AXIOS_INSTANCE_TOKEN,
82
- useValue: axios_1.default,
83
- },
84
- ],
85
- exports: [http_service_1.HttpService],
86
- })
87
- ], HttpModule);
88
- exports.HttpModule = HttpModule;
@@ -1,19 +0,0 @@
1
- import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { Observable } from 'rxjs';
3
- /**
4
- * @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
5
- */
6
- export declare class HttpService {
7
- private readonly instance;
8
- private readonly logger;
9
- constructor(instance?: AxiosInstance);
10
- request<T = any>(config: AxiosRequestConfig): Observable<AxiosResponse<T>>;
11
- get<T = any>(url: string, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
12
- delete<T = any>(url: string, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
13
- head<T = any>(url: string, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
14
- post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
15
- put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
16
- patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Observable<AxiosResponse<T>>;
17
- get axiosRef(): AxiosInstance;
18
- private makeObservable;
19
- }
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpService = void 0;
4
- const tslib_1 = require("tslib");
5
- const axios_1 = require("axios");
6
- const rxjs_1 = require("rxjs");
7
- const decorators_1 = require("../decorators");
8
- const services_1 = require("../services");
9
- const http_constants_1 = require("./http.constants");
10
- /**
11
- * @deprecated "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
12
- */
13
- let HttpService = class HttpService {
14
- constructor(instance = axios_1.default) {
15
- this.instance = instance;
16
- this.logger = new services_1.Logger(HttpService.name);
17
- this.logger.warn('DEPRECATED! "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.');
18
- }
19
- request(config) {
20
- return this.makeObservable(this.instance.request, config);
21
- }
22
- get(url, config) {
23
- return this.makeObservable(this.instance.get, url, config);
24
- }
25
- delete(url, config) {
26
- return this.makeObservable(this.instance.delete, url, config);
27
- }
28
- head(url, config) {
29
- return this.makeObservable(this.instance.head, url, config);
30
- }
31
- post(url, data, config) {
32
- return this.makeObservable(this.instance.post, url, data, config);
33
- }
34
- put(url, data, config) {
35
- return this.makeObservable(this.instance.put, url, data, config);
36
- }
37
- patch(url, data, config) {
38
- return this.makeObservable(this.instance.patch, url, data, config);
39
- }
40
- get axiosRef() {
41
- return this.instance;
42
- }
43
- makeObservable(axios, ...args) {
44
- return new rxjs_1.Observable(subscriber => {
45
- const config = Object.assign({}, (args[args.length - 1] || {}));
46
- let cancelSource;
47
- if (!config.cancelToken) {
48
- cancelSource = axios_1.default.CancelToken.source();
49
- config.cancelToken = cancelSource.token;
50
- }
51
- axios(...args)
52
- .then(res => {
53
- subscriber.next(res);
54
- subscriber.complete();
55
- })
56
- .catch(err => {
57
- subscriber.error(err);
58
- });
59
- return () => {
60
- if (config.responseType === 'stream') {
61
- return;
62
- }
63
- if (cancelSource) {
64
- cancelSource.cancel();
65
- }
66
- };
67
- });
68
- }
69
- };
70
- HttpService = tslib_1.__decorate([
71
- tslib_1.__param(0, (0, decorators_1.Inject)(http_constants_1.AXIOS_INSTANCE_TOKEN)),
72
- tslib_1.__metadata("design:paramtypes", [Function])
73
- ], HttpService);
74
- exports.HttpService = HttpService;
package/http/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './http.module';
2
- export * from './http.service';
3
- export * from './interfaces';
@@ -1,13 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- import { ModuleMetadata, Provider, Type } from '../../interfaces';
3
- export declare type HttpModuleOptions = AxiosRequestConfig;
4
- export interface HttpModuleOptionsFactory {
5
- createHttpOptions(): Promise<HttpModuleOptions> | HttpModuleOptions;
6
- }
7
- export interface HttpModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
8
- useExisting?: Type<HttpModuleOptionsFactory>;
9
- useClass?: Type<HttpModuleOptionsFactory>;
10
- useFactory?: (...args: any[]) => Promise<HttpModuleOptions> | HttpModuleOptions;
11
- inject?: any[];
12
- extraProviders?: Provider[];
13
- }
@@ -1,2 +0,0 @@
1
- export * from './http-module.interface';
2
- export * from './raw-body-request.interface';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./http-module.interface"), exports);
5
- tslib_1.__exportStar(require("./raw-body-request.interface"), exports);
@@ -1 +0,0 @@
1
- export declare function isUUID(str: any, version?: string): any;
package/utils/is-uuid.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUUID = void 0;
4
- const exceptions_1 = require("../exceptions");
5
- const shared_utils_1 = require("./shared.utils");
6
- const uuid = {
7
- 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
8
- 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
9
- 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
10
- all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
11
- };
12
- function isUUID(str, version = 'all') {
13
- if (!(0, shared_utils_1.isString)(str)) {
14
- throw new exceptions_1.BadRequestException('The value passed as UUID is not a string');
15
- }
16
- const pattern = uuid[version];
17
- return pattern && pattern.test(str);
18
- }
19
- exports.isUUID = isUUID;