@nestjs/core 9.3.7 → 9.3.9

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.
@@ -20,7 +20,7 @@ const getInstanceName = (instance) => {
20
20
  * Returns the name of the dependency
21
21
  * Tries to get the class name, otherwise the string value
22
22
  * (= injection token). As fallback it returns '+'
23
- * @param dependency The dependency whichs name should get displayed
23
+ * @param dependency The name of the dependency to be displayed
24
24
  */
25
25
  const getDependencyName = (dependency) =>
26
26
  // use class name
@@ -2,11 +2,11 @@ import { InstanceWrapper } from '../instance-wrapper';
2
2
  import { InstanceToken } from '../module';
3
3
  /**
4
4
  * Returns the instances which are transient
5
- * @param instances The instances which should be checked whether they are transcient
5
+ * @param instances The instances which should be checked whether they are transient
6
6
  */
7
7
  export declare function getTransientInstances(instances: [InstanceToken, InstanceWrapper][]): InstanceWrapper[];
8
8
  /**
9
9
  * Returns the instances which are not transient
10
- * @param instances The instances which should be checked whether they are transcient
10
+ * @param instances The instances which should be checked whether they are transient
11
11
  */
12
12
  export declare function getNonTransientInstances(instances: [InstanceToken, InstanceWrapper][]): InstanceWrapper[];
@@ -4,7 +4,7 @@ exports.getNonTransientInstances = exports.getTransientInstances = void 0;
4
4
  const iterare_1 = require("iterare");
5
5
  /**
6
6
  * Returns the instances which are transient
7
- * @param instances The instances which should be checked whether they are transcient
7
+ * @param instances The instances which should be checked whether they are transient
8
8
  */
9
9
  function getTransientInstances(instances) {
10
10
  return (0, iterare_1.iterate)(instances)
@@ -18,7 +18,7 @@ function getTransientInstances(instances) {
18
18
  exports.getTransientInstances = getTransientInstances;
19
19
  /**
20
20
  * Returns the instances which are not transient
21
- * @param instances The instances which should be checked whether they are transcient
21
+ * @param instances The instances which should be checked whether they are transient
22
22
  */
23
23
  function getNonTransientInstances(instances) {
24
24
  return (0, iterare_1.iterate)(instances)
@@ -83,4 +83,5 @@ export declare class Injector {
83
83
  private printFoundInModuleLog;
84
84
  private isDebugMode;
85
85
  private getContextId;
86
+ private getNowTimestamp;
86
87
  }
@@ -6,6 +6,7 @@ const constants_1 = require("@nestjs/common/constants");
6
6
  const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
7
7
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
8
8
  const iterare_1 = require("iterare");
9
+ const perf_hooks_1 = require("perf_hooks");
9
10
  const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
10
11
  const undefined_dependency_exception_1 = require("../errors/exceptions/undefined-dependency.exception");
11
12
  const unknown_dependencies_exception_1 = require("../errors/exceptions/unknown-dependencies.exception");
@@ -49,10 +50,12 @@ class Injector {
49
50
  return done();
50
51
  }
51
52
  try {
53
+ const t0 = this.getNowTimestamp();
52
54
  const callback = async (instances) => {
53
55
  const properties = await this.resolveProperties(wrapper, moduleRef, inject, contextId, wrapper, inquirer);
54
56
  const instance = await this.instantiateClass(instances, wrapper, targetWrapper, contextId, inquirer);
55
57
  this.applyProperties(instance, properties);
58
+ wrapper.initTime = this.getNowTimestamp() - t0;
56
59
  done();
57
60
  };
58
61
  await this.resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId, wrapper, inquirer);
@@ -454,5 +457,8 @@ class Injector {
454
457
  })
455
458
  : contextId;
456
459
  }
460
+ getNowTimestamp() {
461
+ return perf_hooks_1.performance.now();
462
+ }
457
463
  }
458
464
  exports.Injector = Injector;
@@ -41,6 +41,7 @@ export declare class InstanceWrapper<T = any> {
41
41
  inject?: FactoryProvider['inject'];
42
42
  forwardRef?: boolean;
43
43
  durable?: boolean;
44
+ initTime?: number;
44
45
  private static logger;
45
46
  private readonly values;
46
47
  private readonly [INSTANCE_METADATA_SYMBOL];
@@ -17,6 +17,7 @@ export declare class Module {
17
17
  private readonly _injectables;
18
18
  private readonly _middlewares;
19
19
  private readonly _controllers;
20
+ private readonly _entryProviderKeys;
20
21
  private readonly _exports;
21
22
  private _distance;
22
23
  private _initOnPreview;
@@ -48,6 +49,7 @@ export declare class Module {
48
49
  get routes(): Map<InstanceToken, InstanceWrapper<Controller>>;
49
50
  get injectables(): Map<InstanceToken, InstanceWrapper<Injectable>>;
50
51
  get controllers(): Map<InstanceToken, InstanceWrapper<Controller>>;
52
+ get entryProviders(): Array<InstanceWrapper<Injectable>>;
51
53
  get exports(): Set<InstanceToken>;
52
54
  get instance(): NestModule;
53
55
  get metatype(): Type<any>;
@@ -90,5 +92,6 @@ export declare class Module {
90
92
  InstanceWrapper<Injectable>
91
93
  ]>;
92
94
  createModuleReferenceType(): Type<ModuleRef>;
95
+ private isEntryProvider;
93
96
  private generateUuid;
94
97
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Module = void 0;
4
+ const constants_1 = require("@nestjs/common/constants");
4
5
  const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
5
6
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
7
  const iterare_1 = require("iterare");
@@ -10,7 +11,7 @@ const context_id_factory_1 = require("../helpers/context-id-factory");
10
11
  const get_class_scope_1 = require("../helpers/get-class-scope");
11
12
  const is_durable_1 = require("../helpers/is-durable");
12
13
  const uuid_factory_1 = require("../inspector/uuid-factory");
13
- const constants_1 = require("./constants");
14
+ const constants_2 = require("./constants");
14
15
  const instance_wrapper_1 = require("./instance-wrapper");
15
16
  const module_ref_1 = require("./module-ref");
16
17
  class Module {
@@ -22,6 +23,7 @@ class Module {
22
23
  this._injectables = new Map();
23
24
  this._middlewares = new Map();
24
25
  this._controllers = new Map();
26
+ this._entryProviderKeys = new Set();
25
27
  this._exports = new Set();
26
28
  this._distance = 0;
27
29
  this._initOnPreview = false;
@@ -86,6 +88,9 @@ class Module {
86
88
  get controllers() {
87
89
  return this._controllers;
88
90
  }
91
+ get entryProviders() {
92
+ return Array.from(this._entryProviderKeys).map(token => this.providers.get(token));
93
+ }
89
94
  get exports() {
90
95
  return this._exports;
91
96
  }
@@ -142,7 +147,7 @@ class Module {
142
147
  }
143
148
  addInjectable(injectable, enhancerSubtype, host) {
144
149
  if (this.isCustomProvider(injectable)) {
145
- return this.addCustomProvider(injectable, this._injectables);
150
+ return this.addCustomProvider(injectable, this._injectables, enhancerSubtype);
146
151
  }
147
152
  let instanceWrapper = this.injectables.get(injectable);
148
153
  if (!instanceWrapper) {
@@ -167,6 +172,9 @@ class Module {
167
172
  }
168
173
  addProvider(provider, enhancerSubtype) {
169
174
  if (this.isCustomProvider(provider)) {
175
+ if (this.isEntryProvider(provider.provide)) {
176
+ this._entryProviderKeys.add(provider.provide);
177
+ }
170
178
  return this.addCustomProvider(provider, this._providers, enhancerSubtype);
171
179
  }
172
180
  this._providers.set(provider, new instance_wrapper_1.InstanceWrapper({
@@ -179,6 +187,9 @@ class Module {
179
187
  durable: (0, is_durable_1.isDurable)(provider),
180
188
  host: this,
181
189
  }));
190
+ if (this.isEntryProvider(provider)) {
191
+ this._entryProviderKeys.add(provider);
192
+ }
182
193
  return provider;
183
194
  }
184
195
  isCustomProvider(provider) {
@@ -223,8 +234,9 @@ class Module {
223
234
  if ((0, shared_utils_1.isUndefined)(durable)) {
224
235
  durable = (0, is_durable_1.isDurable)(useClass);
225
236
  }
226
- collection.set(provider.provide, new instance_wrapper_1.InstanceWrapper({
227
- token: provider.provide,
237
+ const token = provider.provide;
238
+ collection.set(token, new instance_wrapper_1.InstanceWrapper({
239
+ token,
228
240
  name: (useClass === null || useClass === void 0 ? void 0 : useClass.name) || useClass,
229
241
  metatype: useClass,
230
242
  instance: null,
@@ -328,7 +340,7 @@ class Module {
328
340
  this.assignControllerUniqueId(controller);
329
341
  }
330
342
  assignControllerUniqueId(controller) {
331
- Object.defineProperty(controller, constants_1.CONTROLLER_ID_KEY, {
343
+ Object.defineProperty(controller, constants_2.CONTROLLER_ID_KEY, {
332
344
  enumerable: false,
333
345
  writable: false,
334
346
  configurable: true,
@@ -404,6 +416,11 @@ class Module {
404
416
  }
405
417
  };
406
418
  }
419
+ isEntryProvider(metatype) {
420
+ return typeof metatype === 'function'
421
+ ? !!Reflect.getMetadata(constants_1.ENTRY_PROVIDER_WATERMARK, metatype)
422
+ : false;
423
+ }
407
424
  generateUuid() {
408
425
  var _a, _b, _c;
409
426
  const prefix = 'M_';
@@ -55,6 +55,7 @@ class GraphInspector {
55
55
  exported: moduleRef.exports.has(wrapper.token),
56
56
  token: wrapper.token,
57
57
  subtype: wrapper.subtype,
58
+ initTime: wrapper.initTime,
58
59
  },
59
60
  });
60
61
  }
@@ -20,6 +20,7 @@ export type ClassNode = {
20
20
  exported: boolean;
21
21
  scope: Scope;
22
22
  token: InjectionToken;
23
+ initTime: number;
23
24
  /**
24
25
  * Enhancers metadata collection
25
26
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "9.3.7",
3
+ "version": "9.3.9",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "uid": "2.0.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@nestjs/common": "9.3.7"
38
+ "@nestjs/common": "9.3.9"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@nestjs/common": "^9.0.0",
@@ -76,14 +76,14 @@ class ReplContext {
76
76
  const nativeFunction = new NativeFunctionRef(this);
77
77
  const nativeFunctions = [nativeFunction];
78
78
  this.nativeFunctions.set(nativeFunction.fnDefinition.name, nativeFunction);
79
- (_a = nativeFunction.fnDefinition.aliases) === null || _a === void 0 ? void 0 : _a.forEach(aliaseName => {
79
+ (_a = nativeFunction.fnDefinition.aliases) === null || _a === void 0 ? void 0 : _a.forEach(aliasName => {
80
80
  const aliasNativeFunction = Object.create(nativeFunction);
81
81
  aliasNativeFunction.fnDefinition = {
82
- name: aliaseName,
82
+ name: aliasName,
83
83
  description: aliasNativeFunction.fnDefinition.description,
84
84
  signature: aliasNativeFunction.fnDefinition.signature,
85
85
  };
86
- this.nativeFunctions.set(aliaseName, aliasNativeFunction);
86
+ this.nativeFunctions.set(aliasName, aliasNativeFunction);
87
87
  nativeFunctions.push(aliasNativeFunction);
88
88
  });
89
89
  return nativeFunctions;
package/scanner.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DynamicModule, ForwardReference, Provider } from '@nestjs/common';
2
2
  import { EnhancerSubtype } from '@nestjs/common/constants';
3
- import { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider, Controller, Injectable, Type } from '@nestjs/common/interfaces';
3
+ import { ClassProvider, Controller, ExistingProvider, FactoryProvider, Injectable, Type, ValueProvider } from '@nestjs/common/interfaces';
4
4
  import { ApplicationConfig } from './application-config';
5
5
  import { NestContainer } from './injector/container';
6
6
  import { InstanceWrapper } from './injector/instance-wrapper';
package/scanner.js CHANGED
@@ -290,10 +290,11 @@ class DependenciesScanner {
290
290
  const modulesContainer = this.container.getModules();
291
291
  const { injectables } = modulesContainer.get(moduleKey);
292
292
  const instanceWrapper = injectables.get(providerKey);
293
- (0, iterare_1.iterate)(modulesContainer.values())
294
- .map(module => module.controllers.values())
293
+ const iterableIterator = modulesContainer.values();
294
+ (0, iterare_1.iterate)(iterableIterator)
295
+ .map(moduleRef => Array.from(moduleRef.controllers.values()).concat(moduleRef.entryProviders))
295
296
  .flatten()
296
- .forEach(controller => controller.addEnhancerMetadata(instanceWrapper));
297
+ .forEach(controllerOrEntryProvider => controllerOrEntryProvider.addEnhancerMetadata(instanceWrapper));
297
298
  });
298
299
  }
299
300
  applyApplicationProviders() {