@nestjs/core 10.3.3 → 10.3.4

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 CHANGED
@@ -25,12 +25,12 @@
25
25
 
26
26
  Nest is a framework for building efficient, scalable <a href="https://nodejs.org" target="_blank">Node.js</a> server-side applications. It uses modern JavaScript, is built with <a href="https://www.typescriptlang.org" target="_blank">TypeScript</a> (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
27
27
 
28
- <p>Under the hood, Nest makes use of <a href="https://expressjs.com/" target="_blank">Express</a>, but also, provides compatibility with a wide range of other libraries, like e.g. <a href="https://github.com/fastify/fastify" target="_blank">Fastify</a>, allowing for easy use of the myriad third-party plugins which are available.</p>
28
+ <p>Under the hood, Nest makes use of <a href="https://expressjs.com/" target="_blank">Express</a>, but also provides compatibility with a wide range of other libraries, like <a href="https://github.com/fastify/fastify" target="_blank">Fastify</a>, allowing for easy use of the myriad of third-party plugins which are available.</p>
29
29
 
30
30
  ## Philosophy
31
31
 
32
- <p>In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like <a href="https://angular.io/" target="_blank">Angular</a>, <a href="https://github.com/facebook/react" target="_blank">React</a> and <a href="https://github.com/vuejs/vue" target="_blank">Vue</a> which improve developer productivity and enable the construction of fast, testable, extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers and tools for Node, none of them effectively solve the main problem - the architecture.</p>
33
- <p>Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.</p>
32
+ <p>In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like <a href="https://angular.io/" target="_blank">Angular</a>, <a href="https://github.com/facebook/react" target="_blank">React</a>, and <a href="https://github.com/vuejs/vue" target="_blank">Vue</a>, which improve developer productivity and enable the construction of fast, testable, and extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers, and tools for Node, none of them effectively solve the main problem - the architecture.</p>
33
+ <p>Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, and loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.</p>
34
34
 
35
35
  ## Getting started
36
36
 
@@ -93,7 +93,6 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
93
93
  <table style="text-align:center;"><tr>
94
94
  <td><a href="https://n.inc" target="_blank"><img src="https://nestjs.com/img/n-inc-logo.svg" width="120" valign="middle" /></td>
95
95
  <td><a href="https://twistag.com/" target="_blank"><img src="https://nestjs.com/img/twistag-logo.png" width="120" valign="middle" /></td>
96
- <td><a href="https://immediateedgeapp.org/" target="_blank"><img src="https://nestjs.com/img/immediate-edge-logo.png" width="120" valign="middle" /></td>
97
96
  </tr>
98
97
  </table>
99
98
 
@@ -4,5 +4,6 @@ import { Module } from '../injector/module';
4
4
  * (providers / controllers).
5
5
  *
6
6
  * @param module The module which will be initialized
7
+ * @param signal
7
8
  */
8
9
  export declare function callAppShutdownHook(module: Module, signal?: string): Promise<any>;
@@ -27,6 +27,7 @@ function callOperator(instances, signal) {
27
27
  * (providers / controllers).
28
28
  *
29
29
  * @param module The module which will be initialized
30
+ * @param signal
30
31
  */
31
32
  async function callAppShutdownHook(module, signal) {
32
33
  const providers = module.getNonAliasProviders();
@@ -0,0 +1,15 @@
1
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
2
+ import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
3
+ import { Type } from '@nestjs/common/interfaces/type.interface';
4
+ import { ModuleOpaqueKeyFactory } from './interfaces/module-opaque-key-factory.interface';
5
+ export declare class ByReferenceModuleOpaqueKeyFactory implements ModuleOpaqueKeyFactory {
6
+ private readonly keyGenerationStrategy;
7
+ constructor(options?: {
8
+ keyGenerationStrategy: 'random' | 'shallow';
9
+ });
10
+ createForStatic(moduleCls: Type, originalRef?: Type | ForwardReference): string;
11
+ createForDynamic(moduleCls: Type<unknown>, dynamicMetadata: Partial<DynamicModule>, originalRef: DynamicModule | ForwardReference): string;
12
+ private getOrCreateModuleId;
13
+ private hashString;
14
+ private generateRandomString;
15
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ByReferenceModuleOpaqueKeyFactory = void 0;
4
+ const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
5
+ const crypto_1 = require("crypto");
6
+ const K_MODULE_ID = Symbol('K_MODULE_ID');
7
+ class ByReferenceModuleOpaqueKeyFactory {
8
+ constructor(options) {
9
+ this.keyGenerationStrategy = options?.keyGenerationStrategy ?? 'random';
10
+ }
11
+ createForStatic(moduleCls, originalRef = moduleCls) {
12
+ return this.getOrCreateModuleId(moduleCls, undefined, originalRef);
13
+ }
14
+ createForDynamic(moduleCls, dynamicMetadata, originalRef) {
15
+ return this.getOrCreateModuleId(moduleCls, dynamicMetadata, originalRef);
16
+ }
17
+ getOrCreateModuleId(moduleCls, dynamicMetadata, originalRef) {
18
+ if (originalRef[K_MODULE_ID]) {
19
+ return originalRef[K_MODULE_ID];
20
+ }
21
+ let moduleId;
22
+ if (this.keyGenerationStrategy === 'random') {
23
+ moduleId = this.generateRandomString();
24
+ }
25
+ else {
26
+ moduleId = dynamicMetadata
27
+ ? `${this.generateRandomString()}:${this.hashString(moduleCls.name + JSON.stringify(dynamicMetadata))}`
28
+ : `${this.generateRandomString()}:${this.hashString(moduleCls.toString())}`;
29
+ }
30
+ originalRef[K_MODULE_ID] = moduleId;
31
+ return moduleId;
32
+ }
33
+ hashString(value) {
34
+ return (0, crypto_1.createHash)('sha256').update(value).digest('hex');
35
+ }
36
+ generateRandomString() {
37
+ return (0, random_string_generator_util_1.randomStringGenerator)();
38
+ }
39
+ }
40
+ exports.ByReferenceModuleOpaqueKeyFactory = ByReferenceModuleOpaqueKeyFactory;
@@ -0,0 +1,15 @@
1
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
2
+ import { Type } from '@nestjs/common/interfaces/type.interface';
3
+ import { ModuleOpaqueKeyFactory } from './interfaces/module-opaque-key-factory.interface';
4
+ export declare class DeepHashedModuleOpaqueKeyFactory implements ModuleOpaqueKeyFactory {
5
+ private readonly moduleIdsCache;
6
+ private readonly moduleTokenCache;
7
+ private readonly logger;
8
+ createForStatic(moduleCls: Type): string;
9
+ createForDynamic(moduleCls: Type<unknown>, dynamicMetadata: Partial<DynamicModule>): string;
10
+ getStringifiedOpaqueToken(opaqueToken: object | undefined): string;
11
+ getModuleId(metatype: Type<unknown>): string;
12
+ getModuleName(metatype: Type<any>): string;
13
+ private hashString;
14
+ private replacer;
15
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeepHashedModuleOpaqueKeyFactory = void 0;
4
+ const logger_service_1 = require("@nestjs/common/services/logger.service");
5
+ const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
6
+ const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
7
+ const crypto_1 = require("crypto");
8
+ const fast_safe_stringify_1 = require("fast-safe-stringify");
9
+ const CLASS_STR = 'class ';
10
+ const CLASS_STR_LEN = CLASS_STR.length;
11
+ class DeepHashedModuleOpaqueKeyFactory {
12
+ constructor() {
13
+ this.moduleIdsCache = new WeakMap();
14
+ this.moduleTokenCache = new Map();
15
+ this.logger = new logger_service_1.Logger(DeepHashedModuleOpaqueKeyFactory.name, {
16
+ timestamp: true,
17
+ });
18
+ }
19
+ createForStatic(moduleCls) {
20
+ const moduleId = this.getModuleId(moduleCls);
21
+ const moduleName = this.getModuleName(moduleCls);
22
+ const key = `${moduleId}_${moduleName}`;
23
+ if (this.moduleTokenCache.has(key)) {
24
+ return this.moduleTokenCache.get(key);
25
+ }
26
+ const hash = this.hashString(key);
27
+ this.moduleTokenCache.set(key, hash);
28
+ return hash;
29
+ }
30
+ createForDynamic(moduleCls, dynamicMetadata) {
31
+ const moduleId = this.getModuleId(moduleCls);
32
+ const moduleName = this.getModuleName(moduleCls);
33
+ const opaqueToken = {
34
+ id: moduleId,
35
+ module: moduleName,
36
+ dynamic: dynamicMetadata,
37
+ };
38
+ const start = performance.now();
39
+ const opaqueTokenString = this.getStringifiedOpaqueToken(opaqueToken);
40
+ const timeSpentInMs = performance.now() - start;
41
+ if (timeSpentInMs > 10) {
42
+ const formattedTimeSpent = timeSpentInMs.toFixed(2);
43
+ this.logger.warn(`The module "${opaqueToken.module}" is taking ${formattedTimeSpent}ms to serialize, this may be caused by larger objects statically assigned to the module. More details: https://github.com/nestjs/nest/issues/12738`);
44
+ }
45
+ return this.hashString(opaqueTokenString);
46
+ }
47
+ getStringifiedOpaqueToken(opaqueToken) {
48
+ // Uses safeStringify instead of JSON.stringify to support circular dynamic modules
49
+ // The replacer function is also required in order to obtain real class names
50
+ // instead of the unified "Function" key
51
+ return opaqueToken ? (0, fast_safe_stringify_1.default)(opaqueToken, this.replacer) : '';
52
+ }
53
+ getModuleId(metatype) {
54
+ let moduleId = this.moduleIdsCache.get(metatype);
55
+ if (moduleId) {
56
+ return moduleId;
57
+ }
58
+ moduleId = (0, random_string_generator_util_1.randomStringGenerator)();
59
+ this.moduleIdsCache.set(metatype, moduleId);
60
+ return moduleId;
61
+ }
62
+ getModuleName(metatype) {
63
+ return metatype.name;
64
+ }
65
+ hashString(value) {
66
+ return (0, crypto_1.createHash)('sha256').update(value).digest('hex');
67
+ }
68
+ replacer(key, value) {
69
+ if ((0, shared_utils_1.isFunction)(value)) {
70
+ const funcAsString = value.toString();
71
+ const isClass = funcAsString.slice(0, CLASS_STR_LEN) === CLASS_STR;
72
+ if (isClass) {
73
+ return value.name;
74
+ }
75
+ return funcAsString;
76
+ }
77
+ if ((0, shared_utils_1.isSymbol)(value)) {
78
+ return value.toString();
79
+ }
80
+ return value;
81
+ }
82
+ }
83
+ exports.DeepHashedModuleOpaqueKeyFactory = DeepHashedModuleOpaqueKeyFactory;
@@ -0,0 +1,18 @@
1
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
2
+ import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
3
+ import { Type } from '@nestjs/common/interfaces/type.interface';
4
+ export interface ModuleOpaqueKeyFactory {
5
+ /**
6
+ * Creates a unique opaque key for the given static module.
7
+ * @param moduleCls A static module class.
8
+ * @param originalRef Original object reference. In most cases, it's the same as `moduleCls`.
9
+ */
10
+ createForStatic(moduleCls: Type, originalRef: Type | ForwardReference): string;
11
+ /**
12
+ * Creates a unique opaque key for the given dynamic module.
13
+ * @param moduleCls A dynamic module class reference.
14
+ * @param dynamicMetadata Partial dynamic module metadata.
15
+ * @param originalRef Original object reference.
16
+ */
17
+ createForDynamic(moduleCls: Type<unknown>, dynamicMetadata: Partial<DynamicModule>, originalRef: DynamicModule | ForwardReference): string;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -167,7 +167,11 @@ class MiddlewareModule {
167
167
  }
168
168
  return next();
169
169
  };
170
- paths.forEach(path => router(path, middlewareFunction));
170
+ const pathsToApplyMiddleware = [];
171
+ paths.some(path => path.match(/^\/?$/))
172
+ ? pathsToApplyMiddleware.push('/')
173
+ : pathsToApplyMiddleware.push(...paths);
174
+ pathsToApplyMiddleware.forEach(path => router(path, middlewareFunction));
171
175
  }
172
176
  getContextId(request, isTreeDurable) {
173
177
  const contextId = context_id_factory_1.ContextIdFactory.getByRequest(request);
@@ -18,8 +18,15 @@ class RouteInfoPathExtractor {
18
18
  const versionPaths = this.extractVersionPathFrom(version);
19
19
  if (this.isAWildcard(path)) {
20
20
  const entries = versionPaths.length > 0
21
- ? versionPaths.map(versionPath => this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path))
22
- : [this.prefixPath + (0, shared_utils_1.addLeadingSlash)(path)];
21
+ ? versionPaths
22
+ .map(versionPath => [
23
+ this.prefixPath + versionPath + '$',
24
+ this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path),
25
+ ])
26
+ .flat()
27
+ : this.prefixPath
28
+ ? [this.prefixPath + '$', this.prefixPath + (0, shared_utils_1.addLeadingSlash)(path)]
29
+ : [(0, shared_utils_1.addLeadingSlash)(path)];
23
30
  return Array.isArray(this.excludedGlobalPrefixRoutes)
24
31
  ? [
25
32
  ...entries,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "10.3.3",
3
+ "version": "10.3.4",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "uid": "2.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "10.3.3"
39
+ "@nestjs/common": "10.3.4"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^10.0.0",
@@ -13,6 +13,8 @@ class RouteParamsFactory {
13
13
  return res;
14
14
  case route_paramtypes_enum_1.RouteParamtypes.BODY:
15
15
  return data && req.body ? req.body[data] : req.body;
16
+ case route_paramtypes_enum_1.RouteParamtypes.RAW_BODY:
17
+ return req.rawBody;
16
18
  case route_paramtypes_enum_1.RouteParamtypes.PARAM:
17
19
  return data ? req.params[data] : req.params;
18
20
  case route_paramtypes_enum_1.RouteParamtypes.HOST:
@@ -123,6 +123,7 @@ class RouterExecutionContext {
123
123
  }
124
124
  isPipeable(type) {
125
125
  return (type === route_paramtypes_enum_1.RouteParamtypes.BODY ||
126
+ type === route_paramtypes_enum_1.RouteParamtypes.RAW_BODY ||
126
127
  type === route_paramtypes_enum_1.RouteParamtypes.QUERY ||
127
128
  type === route_paramtypes_enum_1.RouteParamtypes.PARAM ||
128
129
  type === route_paramtypes_enum_1.RouteParamtypes.FILE ||