@nestjs/core 11.0.4 → 11.0.5

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.
@@ -23,9 +23,10 @@ class ByReferenceModuleOpaqueKeyFactory {
23
23
  moduleId = this.generateRandomString();
24
24
  }
25
25
  else {
26
+ const delimiter = ':';
26
27
  moduleId = dynamicMetadata
27
- ? `${this.generateRandomString()}:${this.hashString(moduleCls.name + JSON.stringify(dynamicMetadata))}`
28
- : `${this.generateRandomString()}:${this.hashString(moduleCls.toString())}`;
28
+ ? `${this.generateRandomString()}${delimiter}${this.hashString(moduleCls.name + JSON.stringify(dynamicMetadata))}`
29
+ : `${this.generateRandomString()}${delimiter}${this.hashString(moduleCls.toString())}`;
29
30
  }
30
31
  originalRef[K_MODULE_ID] = moduleId;
31
32
  return moduleId;
@@ -76,8 +76,15 @@ class MiddlewareModule {
76
76
  }
77
77
  };
78
78
  const entriesSortedByDistance = [...configs.entries()].sort(([moduleA], [moduleB]) => {
79
- return (this.container.getModuleByKey(moduleA).distance -
80
- this.container.getModuleByKey(moduleB).distance);
79
+ const moduleARef = this.container.getModuleByKey(moduleA);
80
+ const moduleBRef = this.container.getModuleByKey(moduleB);
81
+ if (moduleARef.distance === Number.MAX_VALUE) {
82
+ return -1;
83
+ }
84
+ if (moduleBRef.distance === Number.MAX_VALUE) {
85
+ return 1;
86
+ }
87
+ return moduleARef.distance - moduleBRef.distance;
81
88
  });
82
89
  for (const [moduleRef, moduleConfigurations] of entriesSortedByDistance) {
83
90
  await registerAllConfigs(moduleRef, [...moduleConfigurations]);
package/nest-factory.js CHANGED
@@ -35,7 +35,7 @@ class NestFactoryStatic {
35
35
  ? [serverOrOptions, options]
36
36
  : [this.createHttpAdapter(), serverOrOptions];
37
37
  const applicationConfig = new application_config_1.ApplicationConfig();
38
- const container = new container_1.NestContainer(applicationConfig);
38
+ const container = new container_1.NestContainer(applicationConfig, appOptions);
39
39
  const graphInspector = this.createGraphInspector(appOptions, container);
40
40
  this.setAbortOnError(serverOrOptions, options);
41
41
  this.registerLoggerConfiguration(appOptions);
@@ -56,7 +56,7 @@ class NestFactoryStatic {
56
56
  async createMicroservice(moduleCls, options) {
57
57
  const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
58
58
  const applicationConfig = new application_config_1.ApplicationConfig();
59
- const container = new container_1.NestContainer(applicationConfig);
59
+ const container = new container_1.NestContainer(applicationConfig, options);
60
60
  const graphInspector = this.createGraphInspector(options, container);
61
61
  this.setAbortOnError(options);
62
62
  this.registerLoggerConfiguration(options);
@@ -74,7 +74,7 @@ class NestFactoryStatic {
74
74
  */
75
75
  async createApplicationContext(moduleCls, options) {
76
76
  const applicationConfig = new application_config_1.ApplicationConfig();
77
- const container = new container_1.NestContainer(applicationConfig);
77
+ const container = new container_1.NestContainer(applicationConfig, options);
78
78
  const graphInspector = this.createGraphInspector(options, container);
79
79
  this.setAbortOnError(options);
80
80
  this.registerLoggerConfiguration(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "11.0.4",
3
+ "version": "11.0.5",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "uid": "2.0.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@nestjs/common": "11.0.4"
42
+ "@nestjs/common": "11.0.5"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@nestjs/common": "^11.0.0",
@@ -1,14 +0,0 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { Type } from '@nestjs/common/interfaces/type.interface';
3
- export declare class ModuleTokenFactory {
4
- private readonly moduleTokenCache;
5
- private readonly moduleIdsCache;
6
- private readonly logger;
7
- create(metatype: Type<unknown>, dynamicModuleMetadata?: Partial<DynamicModule> | undefined): string;
8
- getStaticModuleToken(moduleId: string, moduleName: string): string;
9
- getStringifiedOpaqueToken(opaqueToken: object | undefined): string;
10
- getModuleId(metatype: Type<unknown>): string;
11
- getModuleName(metatype: Type<any>): string;
12
- private hashString;
13
- private replacer;
14
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModuleTokenFactory = void 0;
4
- const common_1 = require("@nestjs/common");
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 perf_hooks_1 = require("perf_hooks");
10
- const CLASS_STR = 'class ';
11
- const CLASS_STR_LEN = CLASS_STR.length;
12
- class ModuleTokenFactory {
13
- constructor() {
14
- this.moduleTokenCache = new Map();
15
- this.moduleIdsCache = new WeakMap();
16
- this.logger = new common_1.Logger(ModuleTokenFactory.name, {
17
- timestamp: true,
18
- });
19
- }
20
- create(metatype, dynamicModuleMetadata) {
21
- const moduleId = this.getModuleId(metatype);
22
- if (!dynamicModuleMetadata) {
23
- return this.getStaticModuleToken(moduleId, this.getModuleName(metatype));
24
- }
25
- const opaqueToken = {
26
- id: moduleId,
27
- module: this.getModuleName(metatype),
28
- dynamic: dynamicModuleMetadata,
29
- };
30
- const start = perf_hooks_1.performance.now();
31
- const opaqueTokenString = this.getStringifiedOpaqueToken(opaqueToken);
32
- const timeSpentInMs = perf_hooks_1.performance.now() - start;
33
- if (timeSpentInMs > 10) {
34
- const formattedTimeSpent = timeSpentInMs.toFixed(2);
35
- 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`);
36
- }
37
- return this.hashString(opaqueTokenString);
38
- }
39
- getStaticModuleToken(moduleId, moduleName) {
40
- const key = `${moduleId}_${moduleName}`;
41
- if (this.moduleTokenCache.has(key)) {
42
- return this.moduleTokenCache.get(key);
43
- }
44
- const hash = this.hashString(key);
45
- this.moduleTokenCache.set(key, hash);
46
- return hash;
47
- }
48
- getStringifiedOpaqueToken(opaqueToken) {
49
- // Uses safeStringify instead of JSON.stringify to support circular dynamic modules
50
- // The replacer function is also required in order to obtain real class names
51
- // instead of the unified "Function" key
52
- return opaqueToken ? (0, fast_safe_stringify_1.default)(opaqueToken, this.replacer) : '';
53
- }
54
- getModuleId(metatype) {
55
- let moduleId = this.moduleIdsCache.get(metatype);
56
- if (moduleId) {
57
- return moduleId;
58
- }
59
- moduleId = (0, random_string_generator_util_1.randomStringGenerator)();
60
- this.moduleIdsCache.set(metatype, moduleId);
61
- return moduleId;
62
- }
63
- getModuleName(metatype) {
64
- return metatype.name;
65
- }
66
- hashString(value) {
67
- return (0, crypto_1.createHash)('sha256').update(value).digest('hex');
68
- }
69
- replacer(key, value) {
70
- if ((0, shared_utils_1.isFunction)(value)) {
71
- const funcAsString = value.toString();
72
- const isClass = funcAsString.slice(0, CLASS_STR_LEN) === CLASS_STR;
73
- if (isClass) {
74
- return value.name;
75
- }
76
- return funcAsString;
77
- }
78
- if ((0, shared_utils_1.isSymbol)(value)) {
79
- return value.toString();
80
- }
81
- return value;
82
- }
83
- }
84
- exports.ModuleTokenFactory = ModuleTokenFactory;