@nestjs/core 9.3.4 → 9.3.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/index.d.ts +1 -0
- package/index.js +1 -0
- package/injector/container.d.ts +1 -0
- package/injector/container.js +5 -0
- package/injector/injector.js +2 -2
- package/injector/module-token-factory.js +2 -2
- package/injector/module.d.ts +3 -0
- package/injector/module.js +9 -2
- package/inspector/deterministic-uuid-registry.d.ts +2 -1
- package/inspector/deterministic-uuid-registry.js +14 -12
- package/inspector/index.d.ts +2 -0
- package/inspector/index.js +5 -0
- package/inspector/initialize-on-preview.allowlist.d.ts +6 -0
- package/inspector/initialize-on-preview.allowlist.js +13 -0
- package/inspector/on-preview-allowlist.registry.d.ts +0 -0
- package/inspector/on-preview-allowlist.registry.js +1 -0
- package/inspector/serialized-graph.js +1 -2
- package/inspector/uuid-factory.d.ts +1 -1
- package/inspector/uuid-factory.js +2 -2
- package/nest-application-context.d.ts +2 -2
- package/nest-application-context.js +14 -25
- package/package.json +2 -3
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -20,6 +20,7 @@ tslib_1.__exportStar(require("./discovery"), exports);
|
|
|
20
20
|
tslib_1.__exportStar(require("./exceptions"), exports);
|
|
21
21
|
tslib_1.__exportStar(require("./helpers"), exports);
|
|
22
22
|
tslib_1.__exportStar(require("./injector"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./inspector"), exports);
|
|
23
24
|
tslib_1.__exportStar(require("./metadata-scanner"), exports);
|
|
24
25
|
tslib_1.__exportStar(require("./middleware"), exports);
|
|
25
26
|
tslib_1.__exportStar(require("./nest-application"), exports);
|
package/injector/container.d.ts
CHANGED
package/injector/container.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NestContainer = void 0;
|
|
4
4
|
const constants_1 = require("@nestjs/common/constants");
|
|
5
5
|
const exceptions_1 = require("../errors/exceptions");
|
|
6
|
+
const initialize_on_preview_allowlist_1 = require("../inspector/initialize-on-preview.allowlist");
|
|
6
7
|
const serialized_graph_1 = require("../inspector/serialized-graph");
|
|
7
8
|
const request_constants_1 = require("../router/request/request-constants");
|
|
8
9
|
const compiler_1 = require("./compiler");
|
|
@@ -54,6 +55,7 @@ class NestContainer {
|
|
|
54
55
|
}
|
|
55
56
|
const moduleRef = new module_1.Module(type, this);
|
|
56
57
|
moduleRef.token = token;
|
|
58
|
+
moduleRef.initOnPreview = this.shouldInitOnPreview(type);
|
|
57
59
|
this.modules.set(token, moduleRef);
|
|
58
60
|
const updatedScope = [].concat(scope, type);
|
|
59
61
|
await this.addDynamicMetadata(token, dynamicMetadata, updatedScope);
|
|
@@ -175,5 +177,8 @@ class NestContainer {
|
|
|
175
177
|
isResolved: true,
|
|
176
178
|
});
|
|
177
179
|
}
|
|
180
|
+
shouldInitOnPreview(type) {
|
|
181
|
+
return initialize_on_preview_allowlist_1.InitializeOnPreviewAllowlist.has(type);
|
|
182
|
+
}
|
|
178
183
|
}
|
|
179
184
|
exports.NestContainer = NestContainer;
|
package/injector/injector.js
CHANGED
|
@@ -330,7 +330,7 @@ class Injector {
|
|
|
330
330
|
.forEach(item => (instance[item.key] = item.instance));
|
|
331
331
|
}
|
|
332
332
|
async instantiateClass(instances, wrapper, targetMetatype, contextId = constants_2.STATIC_CONTEXT, inquirer) {
|
|
333
|
-
var _a;
|
|
333
|
+
var _a, _b;
|
|
334
334
|
const { metatype, inject } = wrapper;
|
|
335
335
|
const inquirerId = this.getInquirerId(inquirer);
|
|
336
336
|
const instanceHost = targetMetatype.getInstanceByContextId(this.getContextId(contextId, targetMetatype), inquirerId);
|
|
@@ -338,7 +338,7 @@ class Injector {
|
|
|
338
338
|
wrapper.isInRequestScope(contextId, inquirer) ||
|
|
339
339
|
wrapper.isLazyTransient(contextId, inquirer) ||
|
|
340
340
|
wrapper.isExplicitlyRequested(contextId, inquirer);
|
|
341
|
-
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.preview) {
|
|
341
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.preview) && !((_b = wrapper.host) === null || _b === void 0 ? void 0 : _b.initOnPreview)) {
|
|
342
342
|
instanceHost.isResolved = true;
|
|
343
343
|
return instanceHost.instance;
|
|
344
344
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModuleTokenFactory = void 0;
|
|
4
4
|
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
|
5
5
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
|
-
const
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
7
|
const fast_safe_stringify_1 = require("fast-safe-stringify");
|
|
8
8
|
const CLASS_STR = 'class ';
|
|
9
9
|
const CLASS_STR_LEN = CLASS_STR.length;
|
|
@@ -53,7 +53,7 @@ class ModuleTokenFactory {
|
|
|
53
53
|
return metatype.name;
|
|
54
54
|
}
|
|
55
55
|
hashString(value) {
|
|
56
|
-
return (0,
|
|
56
|
+
return (0, crypto_1.createHash)('sha256').update(value).digest('hex');
|
|
57
57
|
}
|
|
58
58
|
replacer(key, value) {
|
|
59
59
|
if ((0, shared_utils_1.isFunction)(value)) {
|
package/injector/module.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class Module {
|
|
|
19
19
|
private readonly _controllers;
|
|
20
20
|
private readonly _exports;
|
|
21
21
|
private _distance;
|
|
22
|
+
private _initOnPreview;
|
|
22
23
|
private _isGlobal;
|
|
23
24
|
private _token;
|
|
24
25
|
constructor(_metatype: Type<any>, container: NestContainer);
|
|
@@ -28,6 +29,8 @@ export declare class Module {
|
|
|
28
29
|
get name(): string;
|
|
29
30
|
get isGlobal(): boolean;
|
|
30
31
|
set isGlobal(global: boolean);
|
|
32
|
+
get initOnPreview(): boolean;
|
|
33
|
+
set initOnPreview(initOnPreview: boolean);
|
|
31
34
|
get providers(): Map<InstanceToken, InstanceWrapper<Injectable>>;
|
|
32
35
|
get middlewares(): Map<InstanceToken, InstanceWrapper<Injectable>>;
|
|
33
36
|
get imports(): Set<Module>;
|
package/injector/module.js
CHANGED
|
@@ -24,6 +24,7 @@ class Module {
|
|
|
24
24
|
this._controllers = new Map();
|
|
25
25
|
this._exports = new Set();
|
|
26
26
|
this._distance = 0;
|
|
27
|
+
this._initOnPreview = false;
|
|
27
28
|
this._isGlobal = false;
|
|
28
29
|
this.addCoreProviders();
|
|
29
30
|
this._id = this.generateUuid();
|
|
@@ -46,6 +47,12 @@ class Module {
|
|
|
46
47
|
set isGlobal(global) {
|
|
47
48
|
this._isGlobal = global;
|
|
48
49
|
}
|
|
50
|
+
get initOnPreview() {
|
|
51
|
+
return this._initOnPreview;
|
|
52
|
+
}
|
|
53
|
+
set initOnPreview(initOnPreview) {
|
|
54
|
+
this._initOnPreview = initOnPreview;
|
|
55
|
+
}
|
|
49
56
|
get providers() {
|
|
50
57
|
return this._providers;
|
|
51
58
|
}
|
|
@@ -399,9 +406,9 @@ class Module {
|
|
|
399
406
|
}
|
|
400
407
|
generateUuid() {
|
|
401
408
|
var _a, _b, _c;
|
|
402
|
-
const
|
|
409
|
+
const prefix = 'M_';
|
|
403
410
|
const key = (_b = (_a = this.name) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : (_c = this.token) === null || _c === void 0 ? void 0 : _c.toString();
|
|
404
|
-
return key ? uuid_factory_1.UuidFactory.get(key
|
|
411
|
+
return key ? uuid_factory_1.UuidFactory.get(`${prefix}_${key}`) : (0, random_string_generator_util_1.randomStringGenerator)();
|
|
405
412
|
}
|
|
406
413
|
}
|
|
407
414
|
exports.Module = Module;
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DeterministicUuidRegistry = void 0;
|
|
4
|
-
const xxhash_1 = require("@node-rs/xxhash");
|
|
5
|
-
const DEFAULT_UUID_NAMESPACE = 'efa0df42-88af-474f-9cad-4206a2319f07';
|
|
6
4
|
class DeterministicUuidRegistry {
|
|
7
|
-
static get(str,
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const idAsString = `${id}`;
|
|
12
|
-
if (this.registry.has(idAsString)) {
|
|
13
|
-
return this.get(str, namespace, inc + 1);
|
|
5
|
+
static get(str, inc = 0) {
|
|
6
|
+
const key = inc ? `${str}_${inc}` : `${str}`;
|
|
7
|
+
if (this.registry.has(key)) {
|
|
8
|
+
return this.get(str, inc + 1);
|
|
14
9
|
}
|
|
15
|
-
this.
|
|
16
|
-
|
|
10
|
+
const id = this.hashCode(key);
|
|
11
|
+
this.registry.set(id, true);
|
|
12
|
+
return id;
|
|
17
13
|
}
|
|
18
14
|
static clear() {
|
|
19
15
|
this.registry.clear();
|
|
20
16
|
}
|
|
17
|
+
static hashCode(s) {
|
|
18
|
+
let h = 0;
|
|
19
|
+
for (let i = 0; i < s.length; i++)
|
|
20
|
+
h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;
|
|
21
|
+
return h.toString();
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
exports.DeterministicUuidRegistry = DeterministicUuidRegistry;
|
|
23
|
-
DeterministicUuidRegistry.registry = new
|
|
25
|
+
DeterministicUuidRegistry.registry = new Map();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitializeOnPreviewAllowlist = void 0;
|
|
4
|
+
class InitializeOnPreviewAllowlist {
|
|
5
|
+
static add(type) {
|
|
6
|
+
this.allowlist.set(type, true);
|
|
7
|
+
}
|
|
8
|
+
static has(type) {
|
|
9
|
+
return this.allowlist.has(type);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.InitializeOnPreviewAllowlist = InitializeOnPreviewAllowlist;
|
|
13
|
+
InitializeOnPreviewAllowlist.allowlist = new WeakMap();
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -83,8 +83,7 @@ class SerializedGraph {
|
|
|
83
83
|
return JSON.stringify(this.toJSON(), replacer, 2);
|
|
84
84
|
}
|
|
85
85
|
generateUuidByEdgeDefinition(edgeDefinition) {
|
|
86
|
-
|
|
87
|
-
return deterministic_uuid_registry_1.DeterministicUuidRegistry.get(JSON.stringify(edgeDefinition), UUID_NAMESPACE);
|
|
86
|
+
return deterministic_uuid_registry_1.DeterministicUuidRegistry.get(JSON.stringify(edgeDefinition));
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
89
|
exports.SerializedGraph = SerializedGraph;
|
|
@@ -12,9 +12,9 @@ class UuidFactory {
|
|
|
12
12
|
static set mode(value) {
|
|
13
13
|
this._mode = value;
|
|
14
14
|
}
|
|
15
|
-
static get(key = ''
|
|
15
|
+
static get(key = '') {
|
|
16
16
|
return this._mode === UuidFactoryMode.Deterministic
|
|
17
|
-
? deterministic_uuid_registry_1.DeterministicUuidRegistry.get(key
|
|
17
|
+
? deterministic_uuid_registry_1.DeterministicUuidRegistry.get(key)
|
|
18
18
|
: (0, random_string_generator_util_1.randomStringGenerator)();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -23,7 +23,7 @@ export declare class NestApplicationContext<TOptions extends NestApplicationCont
|
|
|
23
23
|
private readonly moduleCompiler;
|
|
24
24
|
private shutdownCleanupRef?;
|
|
25
25
|
private _instanceLinksHost;
|
|
26
|
-
private
|
|
26
|
+
private _moduleRefsForHooksByDistance?;
|
|
27
27
|
protected get instanceLinksHost(): InstanceLinksHost;
|
|
28
28
|
constructor(container: NestContainer, appOptions?: TOptions, contextModule?: Module, scope?: Type<any>[]);
|
|
29
29
|
selectContextModule(): void;
|
|
@@ -165,6 +165,6 @@ export declare class NestApplicationContext<TOptions extends NestApplicationCont
|
|
|
165
165
|
*/
|
|
166
166
|
protected callBeforeShutdownHook(signal?: string): Promise<void>;
|
|
167
167
|
protected assertNotInPreviewMode(methodName: string): void;
|
|
168
|
-
private
|
|
168
|
+
private getModulesToTriggerHooksOn;
|
|
169
169
|
private printInPreviewModeWarning;
|
|
170
170
|
}
|
|
@@ -219,10 +219,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
219
219
|
* modules and its children.
|
|
220
220
|
*/
|
|
221
221
|
async callInitHook() {
|
|
222
|
-
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
222
|
+
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
226
223
|
for (const module of modulesSortedByDistance) {
|
|
227
224
|
await (0, hooks_1.callModuleInitHook)(module);
|
|
228
225
|
}
|
|
@@ -232,10 +229,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
232
229
|
* modules and its children.
|
|
233
230
|
*/
|
|
234
231
|
async callDestroyHook() {
|
|
235
|
-
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
232
|
+
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
239
233
|
for (const module of modulesSortedByDistance) {
|
|
240
234
|
await (0, hooks_1.callModuleDestroyHook)(module);
|
|
241
235
|
}
|
|
@@ -245,10 +239,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
245
239
|
* modules and its children.
|
|
246
240
|
*/
|
|
247
241
|
async callBootstrapHook() {
|
|
248
|
-
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
242
|
+
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
252
243
|
for (const module of modulesSortedByDistance) {
|
|
253
244
|
await (0, hooks_1.callModuleBootstrapHook)(module);
|
|
254
245
|
}
|
|
@@ -258,10 +249,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
258
249
|
* modules and children.
|
|
259
250
|
*/
|
|
260
251
|
async callShutdownHook(signal) {
|
|
261
|
-
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
252
|
+
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
265
253
|
for (const module of modulesSortedByDistance) {
|
|
266
254
|
await (0, hooks_1.callAppShutdownHook)(module, signal);
|
|
267
255
|
}
|
|
@@ -271,10 +259,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
271
259
|
* modules and children.
|
|
272
260
|
*/
|
|
273
261
|
async callBeforeShutdownHook(signal) {
|
|
274
|
-
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const modulesSortedByDistance = this.getModulesSortedByDistance();
|
|
262
|
+
const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
|
|
278
263
|
for (const module of modulesSortedByDistance) {
|
|
279
264
|
await (0, hooks_1.callBeforeAppShutdownHook)(module, signal);
|
|
280
265
|
}
|
|
@@ -286,14 +271,18 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
286
271
|
throw new Error(error);
|
|
287
272
|
}
|
|
288
273
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
274
|
+
getModulesToTriggerHooksOn() {
|
|
275
|
+
var _a;
|
|
276
|
+
if (this._moduleRefsForHooksByDistance) {
|
|
277
|
+
return this._moduleRefsForHooksByDistance;
|
|
292
278
|
}
|
|
293
279
|
const modulesContainer = this.container.getModules();
|
|
294
280
|
const compareFn = (a, b) => b.distance - a.distance;
|
|
295
|
-
|
|
296
|
-
|
|
281
|
+
const modulesSortedByDistance = Array.from(modulesContainer.values()).sort(compareFn);
|
|
282
|
+
this._moduleRefsForHooksByDistance = ((_a = this.appOptions) === null || _a === void 0 ? void 0 : _a.preview)
|
|
283
|
+
? modulesSortedByDistance.filter(moduleRef => moduleRef.initOnPreview)
|
|
284
|
+
: modulesSortedByDistance;
|
|
285
|
+
return this._moduleRefsForHooksByDistance;
|
|
297
286
|
}
|
|
298
287
|
printInPreviewModeWarning() {
|
|
299
288
|
this.logger.warn('------------------------------------------------');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.6",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@node-rs/xxhash": "^1.3.0",
|
|
31
30
|
"@nuxtjs/opencollective": "0.3.2",
|
|
32
31
|
"fast-safe-stringify": "2.1.1",
|
|
33
32
|
"iterare": "1.2.1",
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
"uid": "2.0.1"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "9.3.
|
|
38
|
+
"@nestjs/common": "9.3.6"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
41
|
"@nestjs/common": "^9.0.0",
|