@nestjs/core 9.3.9 → 9.3.11

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;
@@ -34,7 +34,7 @@ class BaseExceptionFilterContext extends context_creator_1.ContextCreator {
34
34
  if (!instanceWrapper) {
35
35
  return null;
36
36
  }
37
- const instanceHost = instanceWrapper.getInstanceByContextId(contextId, inquirerId);
37
+ const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
38
38
  return instanceHost && instanceHost.instance;
39
39
  }
40
40
  getInstanceByMetatype(metatype) {
@@ -35,7 +35,7 @@ class GuardsContextCreator extends context_creator_1.ContextCreator {
35
35
  if (!instanceWrapper) {
36
36
  return null;
37
37
  }
38
- const instanceHost = instanceWrapper.getInstanceByContextId(contextId, inquirerId);
38
+ const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
39
39
  return instanceHost && instanceHost.instance;
40
40
  }
41
41
  getInstanceByMetatype(metatype) {
@@ -60,7 +60,7 @@ class GuardsContextCreator extends context_creator_1.ContextCreator {
60
60
  }
61
61
  const scopedGuardWrappers = this.config.getGlobalRequestGuards();
62
62
  const scopedGuards = (0, iterare_1.iterate)(scopedGuardWrappers)
63
- .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
63
+ .map(wrapper => wrapper.getInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId))
64
64
  .filter(host => !!host)
65
65
  .map(host => host.instance)
66
66
  .toArray();
@@ -1,9 +1,10 @@
1
1
  import { Controller } from '@nestjs/common/interfaces';
2
- import { ContextId } from '../injector/instance-wrapper';
2
+ import { ContextId, InstanceWrapper } from '../injector/instance-wrapper';
3
3
  export declare abstract class ContextCreator {
4
4
  abstract createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: ContextId, inquirerId?: string): R;
5
5
  getGlobalMetadata?<T extends any[]>(contextId?: ContextId, inquirerId?: string): T;
6
6
  createContext<T extends unknown[] = any, R extends unknown[] = any>(instance: Controller, callback: (...args: any[]) => void, metadataKey: string, contextId?: ContextId, inquirerId?: string): R;
7
7
  reflectClassMetadata<T>(instance: Controller, metadataKey: string): T;
8
8
  reflectMethodMetadata<T>(callback: (...args: unknown[]) => unknown, metadataKey: string): T;
9
+ protected getContextId(contextId: ContextId, instanceWrapper: InstanceWrapper): ContextId;
9
10
  }
@@ -21,5 +21,13 @@ class ContextCreator {
21
21
  reflectMethodMetadata(callback, metadataKey) {
22
22
  return Reflect.getMetadata(metadataKey, callback);
23
23
  }
24
+ getContextId(contextId, instanceWrapper) {
25
+ return contextId.getParent
26
+ ? contextId.getParent({
27
+ token: instanceWrapper.token,
28
+ isTreeDurable: instanceWrapper.isDependencyTreeDurable(),
29
+ })
30
+ : contextId;
31
+ }
24
32
  }
25
33
  exports.ContextCreator = ContextCreator;
@@ -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);
@@ -231,7 +231,7 @@ class Injector {
231
231
  const token = wrapper.token || wrapper.name;
232
232
  const { name } = dependencyContext;
233
233
  if (wrapper && token === name) {
234
- 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 });
235
235
  }
236
236
  if (providers.has(name)) {
237
237
  const instanceWrapper = providers.get(name);
@@ -244,7 +244,7 @@ class Injector {
244
244
  async lookupComponentInParentModules(dependencyContext, moduleRef, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
245
245
  const instanceWrapper = await this.lookupComponentInImports(moduleRef, dependencyContext.name, wrapper, [], contextId, inquirer, keyOrIndex);
246
246
  if ((0, shared_utils_1.isNil)(instanceWrapper)) {
247
- 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 });
248
248
  }
249
249
  return instanceWrapper;
250
250
  }
@@ -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) {
@@ -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'));
@@ -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);
@@ -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) => {
@@ -35,7 +35,7 @@ class InterceptorsContextCreator extends context_creator_1.ContextCreator {
35
35
  if (!instanceWrapper) {
36
36
  return null;
37
37
  }
38
- const instanceHost = instanceWrapper.getInstanceByContextId(contextId, inquirerId);
38
+ const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
39
39
  return instanceHost && instanceHost.instance;
40
40
  }
41
41
  getInstanceByMetatype(metatype) {
@@ -59,7 +59,7 @@ class InterceptorsContextCreator extends context_creator_1.ContextCreator {
59
59
  }
60
60
  const scopedInterceptorWrappers = this.config.getGlobalRequestInterceptors();
61
61
  const scopedInterceptors = (0, iterare_1.iterate)(scopedInterceptorWrappers)
62
- .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
62
+ .map(wrapper => wrapper.getInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId))
63
63
  .filter(host => !!host)
64
64
  .map(host => host.instance)
65
65
  .toArray();
@@ -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.9",
3
+ "version": "9.3.11",
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.9"
38
+ "@nestjs/common": "9.3.11"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@nestjs/common": "^9.0.0",
@@ -35,7 +35,7 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
35
35
  if (!instanceWrapper) {
36
36
  return null;
37
37
  }
38
- const instanceHost = instanceWrapper.getInstanceByContextId(contextId, inquirerId);
38
+ const instanceHost = instanceWrapper.getInstanceByContextId(this.getContextId(contextId, instanceWrapper), inquirerId);
39
39
  return instanceHost && instanceHost.instance;
40
40
  }
41
41
  getInstanceByMetatype(metatype) {
@@ -59,7 +59,7 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
59
59
  }
60
60
  const scopedPipeWrappers = this.config.getGlobalRequestPipes();
61
61
  const scopedPipes = (0, iterare_1.iterate)(scopedPipeWrappers)
62
- .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
62
+ .map(wrapper => wrapper.getInstanceByContextId(this.getContextId(contextId, wrapper), inquirerId))
63
63
  .filter(host => !!host)
64
64
  .map(host => host.instance)
65
65
  .toArray();
File without changes
@@ -1 +0,0 @@
1
- "use strict";