@nestjs/core 9.3.8 → 9.3.10

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.
@@ -1,6 +1,14 @@
1
1
  import { InjectorDependencyContext } from '../../injector/injector';
2
- import { RuntimeException } from './runtime.exception';
3
2
  import { Module } from '../../injector/module';
3
+ import { RuntimeException } from './runtime.exception';
4
4
  export declare class UnknownDependenciesException extends RuntimeException {
5
- constructor(type: string | symbol, unknownDependencyContext: InjectorDependencyContext, module?: Module);
5
+ readonly type: string | symbol;
6
+ readonly context: InjectorDependencyContext;
7
+ readonly moduleRef?: Module;
8
+ readonly metadata?: {
9
+ id: string;
10
+ };
11
+ constructor(type: string | symbol, context: InjectorDependencyContext, moduleRef?: Module, metadata?: {
12
+ id: string;
13
+ });
6
14
  }
@@ -4,8 +4,12 @@ exports.UnknownDependenciesException = void 0;
4
4
  const messages_1 = require("../messages");
5
5
  const runtime_exception_1 = require("./runtime.exception");
6
6
  class UnknownDependenciesException extends runtime_exception_1.RuntimeException {
7
- constructor(type, unknownDependencyContext, module) {
8
- super((0, messages_1.UNKNOWN_DEPENDENCIES_MESSAGE)(type, unknownDependencyContext, module));
7
+ constructor(type, context, moduleRef, metadata) {
8
+ super((0, messages_1.UNKNOWN_DEPENDENCIES_MESSAGE)(type, context, moduleRef));
9
+ this.type = type;
10
+ this.context = context;
11
+ this.moduleRef = moduleRef;
12
+ this.metadata = metadata;
9
13
  }
10
14
  }
11
15
  exports.UnknownDependenciesException = UnknownDependenciesException;
@@ -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
@@ -1,2 +1,3 @@
1
1
  export * from './context-id-factory';
2
+ export * from './external-context-creator';
2
3
  export * from './http-adapter-host';
package/helpers/index.js CHANGED
@@ -2,4 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./context-id-factory"), exports);
5
+ tslib_1.__exportStar(require("./external-context-creator"), exports);
5
6
  tslib_1.__exportStar(require("./http-adapter-host"), exports);
@@ -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);
@@ -228,7 +231,7 @@ class Injector {
228
231
  const token = wrapper.token || wrapper.name;
229
232
  const { name } = dependencyContext;
230
233
  if (wrapper && token === name) {
231
- throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef);
234
+ throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
232
235
  }
233
236
  if (providers.has(name)) {
234
237
  const instanceWrapper = providers.get(name);
@@ -241,7 +244,7 @@ class Injector {
241
244
  async lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
242
245
  const instanceWrapper = await this.lookupComponentInImports(moduleRef, dependencyContext.name, wrapper, [], contextId, inquirer, keyOrIndex);
243
246
  if ((0, shared_utils_1.isNil)(instanceWrapper)) {
244
- throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef);
247
+ throw new unknown_dependencies_exception_1.UnknownDependenciesException(wrapper.name, dependencyContext, moduleRef, { id: wrapper.id });
245
248
  }
246
249
  return instanceWrapper;
247
250
  }
@@ -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;
@@ -18,7 +18,14 @@ class InstanceLoader {
18
18
  }
19
19
  async createInstancesOfDependencies(modules = this.container.getModules()) {
20
20
  this.createPrototypes(modules);
21
- await this.createInstances(modules);
21
+ try {
22
+ await this.createInstances(modules);
23
+ }
24
+ catch (err) {
25
+ this.graphInspector.inspectModules(modules);
26
+ this.graphInspector.registerPartial(err);
27
+ throw err;
28
+ }
22
29
  this.graphInspector.inspectModules(modules);
23
30
  }
24
31
  createPrototypes(modules) {
@@ -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];
@@ -11,6 +11,7 @@ export declare class GraphInspector {
11
11
  private readonly enhancersMetadataCache;
12
12
  constructor(container: NestContainer);
13
13
  inspectModules(modules?: Map<string, Module>): void;
14
+ registerPartial(error: unknown): void;
14
15
  inspectInstanceWrapper<T = any>(source: InstanceWrapper<T>, moduleRef: Module): void;
15
16
  insertEnhancerMetadataCache(entry: EnhancerMetadataCacheEntry): void;
16
17
  insertOrphanedEnhancer(entry: OrphanedEnhancerDefinition): void;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphInspector = void 0;
4
+ const unknown_dependencies_exception_1 = require("../errors/exceptions/unknown-dependencies.exception");
4
5
  const deterministic_uuid_registry_1 = require("./deterministic-uuid-registry");
6
+ const partial_graph_host_1 = require("./partial-graph.host");
5
7
  class GraphInspector {
6
8
  constructor(container) {
7
9
  this.container = container;
@@ -17,6 +19,29 @@ class GraphInspector {
17
19
  this.enhancersMetadataCache.forEach(entry => this.insertEnhancerEdge(entry));
18
20
  deterministic_uuid_registry_1.DeterministicUuidRegistry.clear();
19
21
  }
22
+ registerPartial(error) {
23
+ var _a, _b;
24
+ this.graph.status = 'partial';
25
+ if (error instanceof unknown_dependencies_exception_1.UnknownDependenciesException) {
26
+ this.graph.metadata = {
27
+ cause: {
28
+ type: 'unknown-dependencies',
29
+ context: error.context,
30
+ moduleId: (_a = error.moduleRef) === null || _a === void 0 ? void 0 : _a.id,
31
+ nodeId: (_b = error.metadata) === null || _b === void 0 ? void 0 : _b.id,
32
+ },
33
+ };
34
+ }
35
+ else {
36
+ this.graph.metadata = {
37
+ cause: {
38
+ type: 'unknown',
39
+ error,
40
+ },
41
+ };
42
+ }
43
+ partial_graph_host_1.PartialGraphHost.register(this.graph);
44
+ }
20
45
  inspectInstanceWrapper(source, moduleRef) {
21
46
  const ctorMetadata = source.getCtorMetadata();
22
47
  ctorMetadata === null || ctorMetadata === void 0 ? void 0 : ctorMetadata.forEach((target, index) => this.insertClassToClassEdge(source, target, moduleRef, index, 'constructor'));
@@ -55,6 +80,7 @@ class GraphInspector {
55
80
  exported: moduleRef.exports.has(wrapper.token),
56
81
  token: wrapper.token,
57
82
  subtype: wrapper.subtype,
83
+ initTime: wrapper.initTime,
58
84
  },
59
85
  });
60
86
  }
@@ -1,2 +1,4 @@
1
1
  export * from './graph-inspector';
2
2
  export * from './initialize-on-preview.allowlist';
3
+ export * from './partial-graph.host';
4
+ export * from './serialized-graph';
@@ -3,3 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./graph-inspector"), exports);
5
5
  tslib_1.__exportStar(require("./initialize-on-preview.allowlist"), exports);
6
+ tslib_1.__exportStar(require("./partial-graph.host"), exports);
7
+ tslib_1.__exportStar(require("./serialized-graph"), exports);
@@ -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
  */
@@ -0,0 +1,14 @@
1
+ import { SerializedGraphStatus } from '../serialized-graph';
2
+ import { Edge } from './edge.interface';
3
+ import { Entrypoint } from './entrypoint.interface';
4
+ import { Extras } from './extras.interface';
5
+ import { Node } from './node.interface';
6
+ import { SerializedGraphMetadata } from './serialized-graph-metadata.interface';
7
+ export interface SerializedGraphJson {
8
+ nodes: Record<string, Node>;
9
+ edges: Record<string, Edge>;
10
+ entrypoints: Record<string, Entrypoint<unknown>[]>;
11
+ extras: Extras;
12
+ status?: SerializedGraphStatus;
13
+ metadata?: SerializedGraphMetadata;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { InjectorDependencyContext } from '../../injector/injector';
2
+ export interface SerializedGraphMetadata {
3
+ cause: {
4
+ type: 'unknown-dependencies' | 'unknown';
5
+ context?: InjectorDependencyContext;
6
+ moduleId?: string;
7
+ nodeId?: string;
8
+ error?: any;
9
+ };
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { SerializedGraph } from './serialized-graph';
2
+ export declare class PartialGraphHost {
3
+ private static partialGraph;
4
+ static toJSON(): import("./interfaces/serialized-graph-json.interface").SerializedGraphJson;
5
+ static toString(): string;
6
+ static register(partialGraph: SerializedGraph): void;
7
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PartialGraphHost = void 0;
4
+ class PartialGraphHost {
5
+ static toJSON() {
6
+ var _a;
7
+ return (_a = this.partialGraph) === null || _a === void 0 ? void 0 : _a.toJSON();
8
+ }
9
+ static toString() {
10
+ var _a;
11
+ return (_a = this.partialGraph) === null || _a === void 0 ? void 0 : _a.toString();
12
+ }
13
+ static register(partialGraph) {
14
+ this.partialGraph = partialGraph;
15
+ }
16
+ }
17
+ exports.PartialGraphHost = PartialGraphHost;
@@ -1,15 +1,22 @@
1
1
  import { InjectionToken } from '@nestjs/common';
2
2
  import { Edge } from './interfaces/edge.interface';
3
3
  import { Entrypoint } from './interfaces/entrypoint.interface';
4
- import { Extras, OrphanedEnhancerDefinition } from './interfaces/extras.interface';
4
+ import { OrphanedEnhancerDefinition } from './interfaces/extras.interface';
5
5
  import { Node } from './interfaces/node.interface';
6
+ import { SerializedGraphJson } from './interfaces/serialized-graph-json.interface';
7
+ import { SerializedGraphMetadata } from './interfaces/serialized-graph-metadata.interface';
8
+ export type SerializedGraphStatus = 'partial' | 'complete';
6
9
  type WithOptionalId<T extends Record<'id', string>> = Omit<T, 'id'> & Partial<Pick<T, 'id'>>;
7
10
  export declare class SerializedGraph {
8
11
  private readonly nodes;
9
12
  private readonly edges;
10
13
  private readonly entrypoints;
11
14
  private readonly extras;
15
+ private _status;
16
+ private _metadata?;
12
17
  private static readonly INTERNAL_PROVIDERS;
18
+ set status(status: SerializedGraphStatus);
19
+ set metadata(metadata: SerializedGraphMetadata);
13
20
  insertNode(nodeDefinition: Node): Node;
14
21
  insertEdge(edgeDefinition: WithOptionalId<Edge>): {
15
22
  id: string;
@@ -38,18 +45,7 @@ export declare class SerializedGraph {
38
45
  insertOrphanedEnhancer(entry: OrphanedEnhancerDefinition): void;
39
46
  insertAttachedEnhancer(nodeId: string): void;
40
47
  getNodeById(id: string): Node;
41
- toJSON(): {
42
- nodes: {
43
- [k: string]: Node;
44
- };
45
- edges: {
46
- [k: string]: Edge;
47
- };
48
- entrypoints: {
49
- [k: string]: Entrypoint<unknown>[];
50
- };
51
- extras: Extras;
52
- };
48
+ toJSON(): SerializedGraphJson;
53
49
  toString(): string;
54
50
  private generateUuidByEdgeDefinition;
55
51
  }
@@ -20,6 +20,13 @@ class SerializedGraph {
20
20
  orphanedEnhancers: [],
21
21
  attachedEnhancers: [],
22
22
  };
23
+ this._status = 'complete';
24
+ }
25
+ set status(status) {
26
+ this._status = status;
27
+ }
28
+ set metadata(metadata) {
29
+ this._metadata = metadata;
23
30
  }
24
31
  insertNode(nodeDefinition) {
25
32
  if (nodeDefinition.metadata.type === 'provider' &&
@@ -65,12 +72,19 @@ class SerializedGraph {
65
72
  return this.nodes.get(id);
66
73
  }
67
74
  toJSON() {
68
- return {
75
+ const json = {
69
76
  nodes: Object.fromEntries(this.nodes),
70
77
  edges: Object.fromEntries(this.edges),
71
78
  entrypoints: Object.fromEntries(this.entrypoints),
72
79
  extras: this.extras,
73
80
  };
81
+ if (this._status) {
82
+ json['status'] = this._status;
83
+ }
84
+ if (this._metadata) {
85
+ json['metadata'] = this._metadata;
86
+ }
87
+ return json;
74
88
  }
75
89
  toString() {
76
90
  const replacer = (key, value) => {
@@ -2,11 +2,15 @@ import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
2
2
  export declare class MetadataScanner {
3
3
  private readonly cachedScannedPrototypes;
4
4
  /**
5
- * @deprecated Use {@link getAllMethodNames} instead.
5
+ * @deprecated
6
+ * @see {@link getAllMethodNames}
7
+ * @see getAllMethodNames
6
8
  */
7
9
  scanFromPrototype<T extends Injectable, R = any>(instance: T, prototype: object, callback: (name: string) => R): R[];
8
10
  /**
9
- * @deprecated Use {@link getAllMethodNames} instead.
11
+ * @deprecated
12
+ * @see {@link getAllMethodNames}
13
+ * @see getAllMethodNames
10
14
  */
11
15
  getAllFilteredMethodNames(prototype: object): IterableIterator<string>;
12
16
  getAllMethodNames(prototype: object | null): string[];
@@ -7,7 +7,9 @@ class MetadataScanner {
7
7
  this.cachedScannedPrototypes = new Map();
8
8
  }
9
9
  /**
10
- * @deprecated Use {@link getAllMethodNames} instead.
10
+ * @deprecated
11
+ * @see {@link getAllMethodNames}
12
+ * @see getAllMethodNames
11
13
  */
12
14
  scanFromPrototype(instance, prototype, callback) {
13
15
  if (!prototype) {
@@ -40,7 +42,9 @@ class MetadataScanner {
40
42
  return result;
41
43
  }
42
44
  /**
43
- * @deprecated Use {@link getAllMethodNames} instead.
45
+ * @deprecated
46
+ * @see {@link getAllMethodNames}
47
+ * @see getAllMethodNames
44
48
  */
45
49
  *getAllFilteredMethodNames(prototype) {
46
50
  yield* this.getAllMethodNames(prototype);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "9.3.8",
3
+ "version": "9.3.10",
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.8"
38
+ "@nestjs/common": "9.3.10"
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;
File without changes
@@ -1 +0,0 @@
1
- "use strict";