@nestjs/core 11.1.4 → 11.1.6
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/injector/injector.js
CHANGED
|
@@ -11,11 +11,11 @@ const exceptions_1 = require("../errors/exceptions");
|
|
|
11
11
|
const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
|
|
12
12
|
const undefined_dependency_exception_1 = require("../errors/exceptions/undefined-dependency.exception");
|
|
13
13
|
const unknown_dependencies_exception_1 = require("../errors/exceptions/unknown-dependencies.exception");
|
|
14
|
+
const barrier_1 = require("../helpers/barrier");
|
|
14
15
|
const constants_2 = require("./constants");
|
|
15
16
|
const inquirer_1 = require("./inquirer");
|
|
16
17
|
const instance_wrapper_1 = require("./instance-wrapper");
|
|
17
18
|
const settlement_signal_1 = require("./settlement-signal");
|
|
18
|
-
const barrier_1 = require("../helpers/barrier");
|
|
19
19
|
class Injector {
|
|
20
20
|
constructor(options) {
|
|
21
21
|
this.options = options;
|
|
@@ -111,7 +111,7 @@ class Injector {
|
|
|
111
111
|
return settlementSignal;
|
|
112
112
|
}
|
|
113
113
|
async resolveConstructorParams(wrapper, moduleRef, inject, callback, contextId = constants_2.STATIC_CONTEXT, inquirer, parentInquirer) {
|
|
114
|
-
|
|
114
|
+
const inquirerId = this.getInquirerId(inquirer);
|
|
115
115
|
const metadata = wrapper.getCtorMetadata();
|
|
116
116
|
if (metadata && contextId !== constants_2.STATIC_CONTEXT) {
|
|
117
117
|
const deps = await this.loadCtorMetadata(metadata, contextId, inquirer, parentInquirer);
|
|
@@ -133,8 +133,10 @@ class Injector {
|
|
|
133
133
|
return parentInquirer && parentInquirer.instance;
|
|
134
134
|
}
|
|
135
135
|
if (inquirer?.isTransient && parentInquirer) {
|
|
136
|
-
inquirer
|
|
137
|
-
|
|
136
|
+
// When `inquirer` is transient too, inherit the parent inquirer
|
|
137
|
+
// This is required to ensure that transient providers are only resolved
|
|
138
|
+
// when requested
|
|
139
|
+
inquirer.attachRootInquirer(parentInquirer);
|
|
138
140
|
}
|
|
139
141
|
const paramWrapper = await this.resolveSingleParam(wrapper, param, { index, dependencies }, moduleRef, contextId, inquirer, index);
|
|
140
142
|
/*
|
|
@@ -315,8 +317,11 @@ class Injector {
|
|
|
315
317
|
const inquirerId = this.getInquirerId(inquirer);
|
|
316
318
|
const instanceHost = instanceWrapperRef.getInstanceByContextId(this.getContextId(contextId, instanceWrapperRef), inquirerId);
|
|
317
319
|
if (!instanceHost.isResolved && !instanceWrapperRef.forwardRef) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
+
/*
|
|
321
|
+
* Provider will be loaded shortly in resolveComponentHost() once we pass the current
|
|
322
|
+
* Barrier. We cannot load it here because doing so could incorrectly evaluate the
|
|
323
|
+
* staticity of the dependency tree and lead to undefined / null injection.
|
|
324
|
+
*/
|
|
320
325
|
break;
|
|
321
326
|
}
|
|
322
327
|
}
|
|
@@ -51,6 +51,11 @@ export declare class InstanceWrapper<T = any> {
|
|
|
51
51
|
private transientMap?;
|
|
52
52
|
private isTreeStatic;
|
|
53
53
|
private isTreeDurable;
|
|
54
|
+
/**
|
|
55
|
+
* The root inquirer reference. Present only if child instance wrapper
|
|
56
|
+
* is transient and has a parent inquirer.
|
|
57
|
+
*/
|
|
58
|
+
private rootInquirer;
|
|
54
59
|
constructor(metadata?: Partial<InstanceWrapper<T>> & Partial<InstancePerContext<T>>);
|
|
55
60
|
get id(): string;
|
|
56
61
|
set instance(value: T);
|
|
@@ -80,6 +85,8 @@ export declare class InstanceWrapper<T = any> {
|
|
|
80
85
|
isLazyTransient(contextId: ContextId, inquirer: InstanceWrapper | undefined): boolean;
|
|
81
86
|
isExplicitlyRequested(contextId: ContextId, inquirer?: InstanceWrapper): boolean;
|
|
82
87
|
isStatic(contextId: ContextId, inquirer: InstanceWrapper | undefined): boolean;
|
|
88
|
+
attachRootInquirer(inquirer: InstanceWrapper): void;
|
|
89
|
+
getRootInquirer(): InstanceWrapper | undefined;
|
|
83
90
|
getStaticTransientInstances(): (InstancePerContext<T> | undefined)[];
|
|
84
91
|
mergeWith(provider: Provider): void;
|
|
85
92
|
private isNewable;
|
|
@@ -242,10 +242,22 @@ class InstanceWrapper {
|
|
|
242
242
|
isStatic(contextId, inquirer) {
|
|
243
243
|
const isInquirerRequestScoped = inquirer && !inquirer.isDependencyTreeStatic();
|
|
244
244
|
const isStaticTransient = this.isTransient && !isInquirerRequestScoped;
|
|
245
|
+
const rootInquirer = inquirer?.getRootInquirer();
|
|
245
246
|
return (this.isDependencyTreeStatic() &&
|
|
246
247
|
contextId === constants_1.STATIC_CONTEXT &&
|
|
247
248
|
(!this.isTransient ||
|
|
248
|
-
(isStaticTransient && !!inquirer && !inquirer.isTransient)
|
|
249
|
+
(isStaticTransient && !!inquirer && !inquirer.isTransient) ||
|
|
250
|
+
(isStaticTransient && !!rootInquirer && !rootInquirer.isTransient)));
|
|
251
|
+
}
|
|
252
|
+
attachRootInquirer(inquirer) {
|
|
253
|
+
if (!this.isTransient) {
|
|
254
|
+
// Only attach root inquirer if the instance wrapper is transient
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
this.rootInquirer = inquirer.getRootInquirer() ?? inquirer;
|
|
258
|
+
}
|
|
259
|
+
getRootInquirer() {
|
|
260
|
+
return this.rootInquirer;
|
|
249
261
|
}
|
|
250
262
|
getStaticTransientInstances() {
|
|
251
263
|
if (!this.transientMap) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.6",
|
|
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.1.
|
|
42
|
+
"@nestjs/common": "11.1.6"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@nestjs/common": "^11.0.0",
|