@nestjs/core 9.0.11 → 9.1.1
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,14 +1,24 @@
|
|
|
1
1
|
import { ContextId, HostComponentInfo } from '../injector/instance-wrapper';
|
|
2
2
|
export declare function createContextId(): ContextId;
|
|
3
|
+
export declare type ContextIdResolverFn = (info: HostComponentInfo) => ContextId;
|
|
4
|
+
export interface ContextIdResolver {
|
|
5
|
+
/**
|
|
6
|
+
* Payload associated with the custom context id
|
|
7
|
+
*/
|
|
8
|
+
payload: unknown;
|
|
9
|
+
/**
|
|
10
|
+
* A context id resolver function
|
|
11
|
+
*/
|
|
12
|
+
resolve: ContextIdResolverFn;
|
|
13
|
+
}
|
|
3
14
|
export interface ContextIdStrategy<T = any> {
|
|
4
15
|
/**
|
|
5
16
|
* Allows to attach a parent context id to the existing child context id.
|
|
6
17
|
* This lets you construct durable DI sub-trees that can be shared between contexts.
|
|
7
18
|
* @param contextId auto-generated child context id
|
|
8
19
|
* @param request request object
|
|
9
|
-
* @returns a context id resolver function
|
|
10
20
|
*/
|
|
11
|
-
attach(contextId: ContextId, request: T):
|
|
21
|
+
attach(contextId: ContextId, request: T): ContextIdResolverFn | ContextIdResolver | undefined;
|
|
12
22
|
}
|
|
13
23
|
export declare class ContextIdFactory {
|
|
14
24
|
private static strategy?;
|
|
@@ -27,4 +37,5 @@ export declare class ContextIdFactory {
|
|
|
27
37
|
* @param strategy strategy instance
|
|
28
38
|
*/
|
|
29
39
|
static apply(strategy: ContextIdStrategy): void;
|
|
40
|
+
private static isContextIdResolverWithPayload;
|
|
30
41
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContextIdFactory = exports.createContextId = void 0;
|
|
4
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
4
5
|
const request_constants_1 = require("../router/request/request-constants");
|
|
5
6
|
function createContextId() {
|
|
6
7
|
/**
|
|
@@ -42,7 +43,14 @@ class ContextIdFactory {
|
|
|
42
43
|
return ContextIdFactory.create();
|
|
43
44
|
}
|
|
44
45
|
const contextId = createContextId();
|
|
45
|
-
|
|
46
|
+
const resolverObjectOrFunction = this.strategy.attach(contextId, request);
|
|
47
|
+
if (this.isContextIdResolverWithPayload(resolverObjectOrFunction)) {
|
|
48
|
+
contextId.getParent = resolverObjectOrFunction.resolve;
|
|
49
|
+
contextId.payload = resolverObjectOrFunction.payload;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
contextId.getParent = resolverObjectOrFunction;
|
|
53
|
+
}
|
|
46
54
|
return contextId;
|
|
47
55
|
}
|
|
48
56
|
/**
|
|
@@ -53,5 +61,8 @@ class ContextIdFactory {
|
|
|
53
61
|
static apply(strategy) {
|
|
54
62
|
this.strategy = strategy;
|
|
55
63
|
}
|
|
64
|
+
static isContextIdResolverWithPayload(resolverOrResolverFn) {
|
|
65
|
+
return (0, shared_utils_1.isObject)(resolverOrResolverFn);
|
|
66
|
+
}
|
|
56
67
|
}
|
|
57
68
|
exports.ContextIdFactory = ContextIdFactory;
|
|
@@ -109,7 +109,7 @@ class MiddlewareModule {
|
|
|
109
109
|
writable: false,
|
|
110
110
|
configurable: false,
|
|
111
111
|
});
|
|
112
|
-
this.container.registerRequestProvider(req, contextId);
|
|
112
|
+
this.container.registerRequestProvider(contextId.getParent ? contextId.payload : req, contextId);
|
|
113
113
|
}
|
|
114
114
|
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, collection, contextId);
|
|
115
115
|
const proxy = await this.createProxy(contextInstance, contextId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.1.1",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"object-hash": "3.0.0",
|
|
34
34
|
"path-to-regexp": "3.2.0",
|
|
35
35
|
"tslib": "2.4.0",
|
|
36
|
-
"uuid": "
|
|
36
|
+
"uuid": "9.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "9.
|
|
39
|
+
"@nestjs/common": "9.1.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@nestjs/common": "^9.0.0",
|
|
@@ -196,7 +196,7 @@ class RouterExplorer {
|
|
|
196
196
|
writable: false,
|
|
197
197
|
configurable: false,
|
|
198
198
|
});
|
|
199
|
-
this.container.registerRequestProvider(request, contextId);
|
|
199
|
+
this.container.registerRequestProvider(contextId.getParent ? contextId.payload : request, contextId);
|
|
200
200
|
}
|
|
201
201
|
return contextId;
|
|
202
202
|
}
|
|
@@ -31,7 +31,7 @@ class Reflector {
|
|
|
31
31
|
*
|
|
32
32
|
*/
|
|
33
33
|
getAll(metadataKey, targets) {
|
|
34
|
-
return (targets || []).map(target =>
|
|
34
|
+
return (targets || []).map(target => this.get(metadataKey, target));
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Retrieve metadata for a specified key for a specified set of targets and merge results.
|
|
@@ -63,7 +63,13 @@ class Reflector {
|
|
|
63
63
|
*
|
|
64
64
|
*/
|
|
65
65
|
getAllAndOverride(metadataKey, targets) {
|
|
66
|
-
|
|
66
|
+
for (const target of targets) {
|
|
67
|
+
const result = this.get(metadataKey, target);
|
|
68
|
+
if (result !== undefined) {
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
exports.Reflector = Reflector;
|