@nestjs/core 9.3.0-beta.3 → 9.3.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.
- package/helpers/context-id-factory.d.ts +1 -1
- package/helpers/external-context-creator.d.ts +3 -6
- package/helpers/external-context-creator.js +9 -12
- package/helpers/handler-metadata-storage.d.ts +3 -3
- package/helpers/interfaces/external-handler-metadata.interface.d.ts +1 -1
- package/helpers/interfaces/params-metadata.interface.d.ts +1 -1
- package/injector/injector.d.ts +1 -1
- package/injector/injector.js +1 -1
- package/injector/instance-wrapper.js +8 -4
- package/injector/module-ref.d.ts +25 -3
- package/injector/module-ref.js +5 -5
- package/injector/module.d.ts +1 -1
- package/injector/module.js +14 -10
- package/inspector/interfaces/edge.interface.d.ts +3 -3
- package/inspector/interfaces/entrypoint.interface.d.ts +3 -3
- package/inspector/interfaces/node.interface.d.ts +3 -3
- package/inspector/noop-graph-inspector.js +1 -0
- package/inspector/serialized-graph.d.ts +1 -1
- package/inspector/uuid-factory.d.ts +9 -0
- package/inspector/uuid-factory.js +22 -0
- package/middleware/middleware-module.d.ts +1 -0
- package/middleware/middleware-module.js +20 -12
- package/middleware/utils.js +1 -0
- package/nest-application-context.d.ts +1 -1
- package/nest-application-context.js +17 -10
- package/nest-application.d.ts +1 -0
- package/nest-application.js +12 -0
- package/nest-factory.js +4 -0
- package/package.json +2 -2
- package/repl/native-functions/debug-repl-fn.js +1 -1
- package/repl/repl-context.d.ts +3 -3
- package/repl/repl-native-commands.d.ts +3 -0
- package/repl/repl-native-commands.js +47 -0
- package/repl/repl.interfaces.d.ts +2 -2
- package/repl/repl.js +2 -0
- package/router/interfaces/exclude-route-metadata.interface.d.ts +1 -0
- package/router/interfaces/routes.interface.d.ts +1 -1
- package/router/router-explorer.js +14 -15
- package/router/router-proxy.d.ts +3 -3
- package/router/router-proxy.js +2 -0
- package/router/sse-stream.d.ts +3 -3
- package/scanner.d.ts +1 -4
- package/scanner.js +2 -2
- package/test/utils/string.cleaner.d.ts +0 -1
- package/test/utils/string.cleaner.js +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContextId, HostComponentInfo } from '../injector/instance-wrapper';
|
|
2
2
|
export declare function createContextId(): ContextId;
|
|
3
|
-
export
|
|
3
|
+
export type ContextIdResolverFn = (info: HostComponentInfo) => ContextId;
|
|
4
4
|
export interface ContextIdResolver {
|
|
5
5
|
/**
|
|
6
6
|
* Payload associated with the custom context id
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { ParamData } from '@nestjs/common';
|
|
2
2
|
import { ContextType, Controller, PipeTransform } from '@nestjs/common/interfaces';
|
|
3
3
|
import { ExternalExceptionFilterContext } from '../exceptions/external-exception-filter-context';
|
|
4
|
-
import { GuardsConsumer } from '../guards
|
|
5
|
-
import { GuardsContextCreator } from '../guards/guards-context-creator';
|
|
4
|
+
import { GuardsConsumer, GuardsContextCreator } from '../guards';
|
|
6
5
|
import { NestContainer } from '../injector/container';
|
|
7
6
|
import { ContextId } from '../injector/instance-wrapper';
|
|
8
7
|
import { ModulesContainer } from '../injector/modules-container';
|
|
9
|
-
import { InterceptorsConsumer } from '../interceptors
|
|
10
|
-
import {
|
|
11
|
-
import { PipesConsumer } from '../pipes/pipes-consumer';
|
|
12
|
-
import { PipesContextCreator } from '../pipes/pipes-context-creator';
|
|
8
|
+
import { InterceptorsConsumer, InterceptorsContextCreator } from '../interceptors';
|
|
9
|
+
import { PipesConsumer, PipesContextCreator } from '../pipes';
|
|
13
10
|
import { ParamProperties } from './context-utils';
|
|
14
11
|
import { ExternalHandlerMetadata } from './interfaces/external-handler-metadata.interface';
|
|
15
12
|
import { ParamsMetadata } from './interfaces/params-metadata.interface';
|
|
@@ -7,13 +7,10 @@ const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
|
7
7
|
const rxjs_1 = require("rxjs");
|
|
8
8
|
const external_exception_filter_context_1 = require("../exceptions/external-exception-filter-context");
|
|
9
9
|
const constants_2 = require("../guards/constants");
|
|
10
|
-
const
|
|
11
|
-
const guards_context_creator_1 = require("../guards/guards-context-creator");
|
|
10
|
+
const guards_1 = require("../guards");
|
|
12
11
|
const constants_3 = require("../injector/constants");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const pipes_consumer_1 = require("../pipes/pipes-consumer");
|
|
16
|
-
const pipes_context_creator_1 = require("../pipes/pipes-context-creator");
|
|
12
|
+
const interceptors_1 = require("../interceptors");
|
|
13
|
+
const pipes_1 = require("../pipes");
|
|
17
14
|
const context_utils_1 = require("./context-utils");
|
|
18
15
|
const external_proxy_1 = require("./external-proxy");
|
|
19
16
|
const handler_metadata_storage_1 = require("./handler-metadata-storage");
|
|
@@ -32,12 +29,12 @@ class ExternalContextCreator {
|
|
|
32
29
|
this.handlerMetadataStorage = new handler_metadata_storage_1.HandlerMetadataStorage();
|
|
33
30
|
}
|
|
34
31
|
static fromContainer(container) {
|
|
35
|
-
const guardsContextCreator = new
|
|
36
|
-
const guardsConsumer = new
|
|
37
|
-
const interceptorsContextCreator = new
|
|
38
|
-
const interceptorsConsumer = new
|
|
39
|
-
const pipesContextCreator = new
|
|
40
|
-
const pipesConsumer = new
|
|
32
|
+
const guardsContextCreator = new guards_1.GuardsContextCreator(container, container.applicationConfig);
|
|
33
|
+
const guardsConsumer = new guards_1.GuardsConsumer();
|
|
34
|
+
const interceptorsContextCreator = new interceptors_1.InterceptorsContextCreator(container, container.applicationConfig);
|
|
35
|
+
const interceptorsConsumer = new interceptors_1.InterceptorsConsumer();
|
|
36
|
+
const pipesContextCreator = new pipes_1.PipesContextCreator(container, container.applicationConfig);
|
|
37
|
+
const pipesConsumer = new pipes_1.PipesConsumer();
|
|
41
38
|
const filtersContextCreator = new external_exception_filter_context_1.ExternalExceptionFilterContext(container, container.applicationConfig);
|
|
42
39
|
const externalContextCreator = new ExternalContextCreator(guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, container.getModules(), pipesContextCreator, pipesConsumer, filtersContextCreator);
|
|
43
40
|
externalContextCreator.container = container;
|
|
@@ -6,9 +6,9 @@ import { ContextId } from '../injector/instance-wrapper';
|
|
|
6
6
|
import { HeaderStream } from '../router/sse-stream';
|
|
7
7
|
import { ParamProperties } from './context-utils';
|
|
8
8
|
export declare const HANDLER_METADATA_SYMBOL: unique symbol;
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
9
|
+
export type HandleResponseFn = HandlerResponseBasicFn | HandleSseResponseFn;
|
|
10
|
+
export type HandlerResponseBasicFn = <TResult, TResponse>(result: TResult, res: TResponse, req?: any) => any;
|
|
11
|
+
export type HandleSseResponseFn = <TResult extends Observable<unknown> = any, TResponse extends HeaderStream = any, TRequest extends IncomingMessage = any>(result: TResult, res: TResponse, req: TRequest) => any;
|
|
12
12
|
export interface HandlerMetadata {
|
|
13
13
|
argsLength: number;
|
|
14
14
|
paramtypes: any[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContextId } from '../../injector';
|
|
2
2
|
import { ParamProperties } from '../context-utils';
|
|
3
|
-
|
|
3
|
+
type ParamPropertiesWithMetatype<T = any> = ParamProperties & {
|
|
4
4
|
metatype?: T;
|
|
5
5
|
};
|
|
6
6
|
export interface ExternalHandlerMetadata {
|
package/injector/injector.d.ts
CHANGED
package/injector/injector.js
CHANGED
|
@@ -162,7 +162,7 @@ class Injector {
|
|
|
162
162
|
];
|
|
163
163
|
}
|
|
164
164
|
reflectConstructorParams(type) {
|
|
165
|
-
const paramtypes = Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) || [];
|
|
165
|
+
const paramtypes = [...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) || [])];
|
|
166
166
|
const selfParams = this.reflectSelfParams(type);
|
|
167
167
|
selfParams.forEach(({ index, param }) => (paramtypes[index] = param));
|
|
168
168
|
return paramtypes;
|
|
@@ -8,7 +8,7 @@ const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
|
|
8
8
|
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
|
9
9
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
10
10
|
const iterare_1 = require("iterare");
|
|
11
|
-
const
|
|
11
|
+
const uuid_factory_1 = require("../inspector/uuid-factory");
|
|
12
12
|
const constants_1 = require("./constants");
|
|
13
13
|
const provider_classifier_1 = require("./helpers/provider-classifier");
|
|
14
14
|
exports.INSTANCE_METADATA_SYMBOL = Symbol.for('instance_metadata:cache');
|
|
@@ -118,7 +118,8 @@ class InstanceWrapper {
|
|
|
118
118
|
if (isStatic) {
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
|
-
const isTreeNonDurable = this.introspectDepsAttribute((collection, registry) => collection.
|
|
121
|
+
const isTreeNonDurable = this.introspectDepsAttribute((collection, registry) => collection.some((item) => !item.isDependencyTreeStatic() &&
|
|
122
|
+
!item.isDependencyTreeDurable(registry)), lookupRegistry);
|
|
122
123
|
this.isTreeDurable = !isTreeNonDurable && this.durable !== false;
|
|
123
124
|
if (this.isTreeDurable) {
|
|
124
125
|
this.printIntrospectedAsDurable();
|
|
@@ -137,7 +138,10 @@ class InstanceWrapper {
|
|
|
137
138
|
}
|
|
138
139
|
const propertiesHosts = (properties || []).map(item => item.wrapper);
|
|
139
140
|
introspectionResult =
|
|
140
|
-
introspectionResult &&
|
|
141
|
+
introspectionResult &&
|
|
142
|
+
((properties &&
|
|
143
|
+
callback(properties.map(item => item.wrapper), lookupRegistry)) ||
|
|
144
|
+
!properties);
|
|
141
145
|
if (!introspectionResult || !enhancers) {
|
|
142
146
|
return introspectionResult;
|
|
143
147
|
}
|
|
@@ -278,7 +282,7 @@ class InstanceWrapper {
|
|
|
278
282
|
var _b, _c, _d, _e, _f;
|
|
279
283
|
let key = (_c = (_b = this.name) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : (_d = this.token) === null || _d === void 0 ? void 0 : _d.toString();
|
|
280
284
|
key += (_f = (_e = this.host) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '';
|
|
281
|
-
return key ?
|
|
285
|
+
return key ? uuid_factory_1.UuidFactory.get(key) : (0, random_string_generator_util_1.randomStringGenerator)();
|
|
282
286
|
}
|
|
283
287
|
}
|
|
284
288
|
exports.InstanceWrapper = InstanceWrapper;
|
package/injector/module-ref.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { IntrospectionResult, Type } from '@nestjs/common';
|
|
2
|
-
import { GetOrResolveOptions } from '@nestjs/common/interfaces';
|
|
3
2
|
import { AbstractInstanceResolver } from './abstract-instance-resolver';
|
|
4
3
|
import { NestContainer } from './container';
|
|
5
4
|
import { Injector } from './injector';
|
|
6
5
|
import { InstanceLinksHost } from './instance-links-host';
|
|
7
6
|
import { ContextId } from './instance-wrapper';
|
|
8
7
|
import { Module } from './module';
|
|
8
|
+
export interface ModuleRefGetOrResolveOpts {
|
|
9
|
+
/**
|
|
10
|
+
* If enabled, lookup will only be performed in the host module.
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
strict?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* If enabled, instead of returning a first instance registered under a given token,
|
|
16
|
+
* a list of instances will be returned.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
each?: boolean;
|
|
20
|
+
}
|
|
9
21
|
export declare abstract class ModuleRef extends AbstractInstanceResolver {
|
|
10
22
|
protected readonly container: NestContainer;
|
|
11
23
|
protected readonly injector: Injector;
|
|
@@ -22,7 +34,12 @@ export declare abstract class ModuleRef extends AbstractInstanceResolver {
|
|
|
22
34
|
* @returns {TResult}
|
|
23
35
|
*/
|
|
24
36
|
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
37
|
+
/**
|
|
38
|
+
* If enabled, lookup will only be performed in the host module.
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
25
41
|
strict?: boolean;
|
|
42
|
+
/** This indicates that only the first instance registered will be returned. */
|
|
26
43
|
each?: undefined | false;
|
|
27
44
|
}): TResult;
|
|
28
45
|
/**
|
|
@@ -30,14 +47,19 @@ export declare abstract class ModuleRef extends AbstractInstanceResolver {
|
|
|
30
47
|
* @returns {Array<TResult>}
|
|
31
48
|
*/
|
|
32
49
|
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
50
|
+
/**
|
|
51
|
+
* If enabled, lookup will only be performed in the host module.
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
33
54
|
strict?: boolean;
|
|
55
|
+
/** This indicates that a list of instances will be returned. */
|
|
34
56
|
each: true;
|
|
35
57
|
}): Array<TResult>;
|
|
36
58
|
/**
|
|
37
59
|
* Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
38
60
|
* @returns {TResult | Array<TResult>}
|
|
39
61
|
*/
|
|
40
|
-
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?:
|
|
62
|
+
abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?: ModuleRefGetOrResolveOpts): TResult | Array<TResult>;
|
|
41
63
|
/**
|
|
42
64
|
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
43
65
|
* @returns {Array<TResult>}
|
|
@@ -76,7 +98,7 @@ export declare abstract class ModuleRef extends AbstractInstanceResolver {
|
|
|
76
98
|
*/
|
|
77
99
|
abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
78
100
|
id: number;
|
|
79
|
-
}, options?:
|
|
101
|
+
}, options?: ModuleRefGetOrResolveOpts): Promise<TResult | Array<TResult>>;
|
|
80
102
|
abstract create<T = any>(type: Type<T>): Promise<T>;
|
|
81
103
|
introspect<T = any>(token: Type<T> | string | symbol): IntrospectionResult;
|
|
82
104
|
registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
|
package/injector/module-ref.js
CHANGED
|
@@ -9,17 +9,17 @@ const injector_1 = require("./injector");
|
|
|
9
9
|
const instance_links_host_1 = require("./instance-links-host");
|
|
10
10
|
const instance_wrapper_1 = require("./instance-wrapper");
|
|
11
11
|
class ModuleRef extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
12
|
-
constructor(container) {
|
|
13
|
-
super();
|
|
14
|
-
this.container = container;
|
|
15
|
-
this.injector = new injector_1.Injector();
|
|
16
|
-
}
|
|
17
12
|
get instanceLinksHost() {
|
|
18
13
|
if (!this._instanceLinksHost) {
|
|
19
14
|
this._instanceLinksHost = new instance_links_host_1.InstanceLinksHost(this.container);
|
|
20
15
|
}
|
|
21
16
|
return this._instanceLinksHost;
|
|
22
17
|
}
|
|
18
|
+
constructor(container) {
|
|
19
|
+
super();
|
|
20
|
+
this.container = container;
|
|
21
|
+
this.injector = new injector_1.Injector();
|
|
22
|
+
}
|
|
23
23
|
introspect(token) {
|
|
24
24
|
const { wrapperRef } = this.instanceLinksHost.get(token);
|
|
25
25
|
let scope = common_1.Scope.DEFAULT;
|
package/injector/module.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { ModuleRef } from './module-ref';
|
|
|
7
7
|
* @note
|
|
8
8
|
* Left for backward compatibility
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type InstanceToken = InjectionToken;
|
|
11
11
|
export declare class Module {
|
|
12
12
|
private readonly _metatype;
|
|
13
13
|
private readonly container;
|
package/injector/module.js
CHANGED
|
@@ -9,7 +9,7 @@ const exceptions_1 = require("../errors/exceptions");
|
|
|
9
9
|
const context_id_factory_1 = require("../helpers/context-id-factory");
|
|
10
10
|
const get_class_scope_1 = require("../helpers/get-class-scope");
|
|
11
11
|
const is_durable_1 = require("../helpers/is-durable");
|
|
12
|
-
const
|
|
12
|
+
const uuid_factory_1 = require("../inspector/uuid-factory");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
const instance_wrapper_1 = require("./instance-wrapper");
|
|
15
15
|
const module_ref_1 = require("./module-ref");
|
|
@@ -372,15 +372,21 @@ class Module {
|
|
|
372
372
|
constructor() {
|
|
373
373
|
super(self.container);
|
|
374
374
|
}
|
|
375
|
-
get(typeOrToken, options = {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
375
|
+
get(typeOrToken, options = {}) {
|
|
376
|
+
var _a, _b;
|
|
377
|
+
(_a = options.strict) !== null && _a !== void 0 ? _a : (options.strict = true);
|
|
378
|
+
(_b = options.each) !== null && _b !== void 0 ? _b : (options.each = false);
|
|
379
|
+
return this.find(typeOrToken, options.strict
|
|
380
|
+
? {
|
|
379
381
|
moduleId: self.id,
|
|
380
382
|
each: options.each,
|
|
381
|
-
}
|
|
383
|
+
}
|
|
384
|
+
: options);
|
|
382
385
|
}
|
|
383
|
-
resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = {
|
|
386
|
+
resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = {}) {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
(_a = options.strict) !== null && _a !== void 0 ? _a : (options.strict = true);
|
|
389
|
+
(_b = options.each) !== null && _b !== void 0 ? _b : (options.each = false);
|
|
384
390
|
return this.resolvePerContext(typeOrToken, self, contextId, options);
|
|
385
391
|
}
|
|
386
392
|
async create(type) {
|
|
@@ -395,9 +401,7 @@ class Module {
|
|
|
395
401
|
var _a, _b, _c;
|
|
396
402
|
const UUID_NAMESPACE = 'fb848993-0c82-4b9e-ae95-3c3c1dbe3d6b';
|
|
397
403
|
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();
|
|
398
|
-
return key
|
|
399
|
-
? deterministic_uuid_registry_1.DeterministicUuidRegistry.get(key, UUID_NAMESPACE)
|
|
400
|
-
: (0, random_string_generator_util_1.randomStringGenerator)();
|
|
404
|
+
return key ? uuid_factory_1.UuidFactory.get(key, UUID_NAMESPACE) : (0, random_string_generator_util_1.randomStringGenerator)();
|
|
401
405
|
}
|
|
402
406
|
}
|
|
403
407
|
exports.Module = Module;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { InjectionToken } from '@nestjs/common';
|
|
2
|
-
|
|
2
|
+
type CommonEdgeMetadata = {
|
|
3
3
|
sourceModuleName: string;
|
|
4
4
|
targetModuleName: string;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
type ModuleToModuleEdgeMetadata = {
|
|
7
7
|
type: 'module-to-module';
|
|
8
8
|
} & CommonEdgeMetadata;
|
|
9
|
-
|
|
9
|
+
type ClassToClassEdgeMetadata = {
|
|
10
10
|
type: 'class-to-class';
|
|
11
11
|
sourceClassName: string;
|
|
12
12
|
targetClassName: string;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { RequestMethod } from '@nestjs/common';
|
|
2
2
|
import { VersionValue } from '@nestjs/common/interfaces';
|
|
3
|
-
export
|
|
3
|
+
export type HttpEntrypointMetadata = {
|
|
4
4
|
path: string;
|
|
5
5
|
requestMethod: keyof typeof RequestMethod;
|
|
6
6
|
methodVersion?: VersionValue;
|
|
7
7
|
controllerVersion?: VersionValue;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type MiddlewareEntrypointMetadata = {
|
|
10
10
|
path: string;
|
|
11
11
|
requestMethod: keyof typeof RequestMethod;
|
|
12
12
|
version?: VersionValue;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type Entrypoint<T> = {
|
|
15
15
|
id?: string;
|
|
16
16
|
type: string;
|
|
17
17
|
methodName: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InjectionToken, Scope } from '@nestjs/common';
|
|
2
2
|
import { EnhancerSubtype } from '@nestjs/common/constants';
|
|
3
|
-
export
|
|
3
|
+
export type ModuleNode = {
|
|
4
4
|
metadata: {
|
|
5
5
|
type: 'module';
|
|
6
6
|
global: boolean;
|
|
@@ -8,7 +8,7 @@ export declare type ModuleNode = {
|
|
|
8
8
|
internal: boolean;
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type ClassNode = {
|
|
12
12
|
parent: string;
|
|
13
13
|
metadata: {
|
|
14
14
|
type: 'provider' | 'controller' | 'middleware' | 'injectable';
|
|
@@ -41,7 +41,7 @@ export declare type ClassNode = {
|
|
|
41
41
|
internal?: boolean;
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
export
|
|
44
|
+
export type Node = {
|
|
45
45
|
id: string;
|
|
46
46
|
label: string;
|
|
47
47
|
} & (ClassNode | ModuleNode);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NoopGraphInspector = void 0;
|
|
4
4
|
const graph_inspector_1 = require("./graph-inspector");
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5
6
|
const noop = () => { };
|
|
6
7
|
exports.NoopGraphInspector = new Proxy(graph_inspector_1.GraphInspector.prototype, {
|
|
7
8
|
get: () => noop,
|
|
@@ -3,7 +3,7 @@ import { Edge } from './interfaces/edge.interface';
|
|
|
3
3
|
import { Entrypoint } from './interfaces/entrypoint.interface';
|
|
4
4
|
import { Extras, OrphanedEnhancerDefinition } from './interfaces/extras.interface';
|
|
5
5
|
import { Node } from './interfaces/node.interface';
|
|
6
|
-
|
|
6
|
+
type WithOptionalId<T extends Record<'id', string>> = Omit<T, 'id'> & Partial<Pick<T, 'id'>>;
|
|
7
7
|
export declare class SerializedGraph {
|
|
8
8
|
private readonly nodes;
|
|
9
9
|
private readonly edges;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UuidFactory = exports.UuidFactoryMode = void 0;
|
|
4
|
+
const random_string_generator_util_1 = require("../../common/utils/random-string-generator.util");
|
|
5
|
+
const deterministic_uuid_registry_1 = require("./deterministic-uuid-registry");
|
|
6
|
+
var UuidFactoryMode;
|
|
7
|
+
(function (UuidFactoryMode) {
|
|
8
|
+
UuidFactoryMode["Random"] = "random";
|
|
9
|
+
UuidFactoryMode["Deterministic"] = "deterministic";
|
|
10
|
+
})(UuidFactoryMode = exports.UuidFactoryMode || (exports.UuidFactoryMode = {}));
|
|
11
|
+
class UuidFactory {
|
|
12
|
+
static set mode(value) {
|
|
13
|
+
this._mode = value;
|
|
14
|
+
}
|
|
15
|
+
static get(key = '', namespace) {
|
|
16
|
+
return this._mode === UuidFactoryMode.Deterministic
|
|
17
|
+
? deterministic_uuid_registry_1.DeterministicUuidRegistry.get(key, namespace)
|
|
18
|
+
: (0, random_string_generator_util_1.randomStringGenerator)();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.UuidFactory = UuidFactory;
|
|
22
|
+
UuidFactory._mode = UuidFactoryMode.Random;
|
|
@@ -129,18 +129,10 @@ class MiddlewareModule {
|
|
|
129
129
|
const proxy = await this.createProxy(instance);
|
|
130
130
|
return this.registerHandler(applicationRef, routeInfo, proxy);
|
|
131
131
|
}
|
|
132
|
+
const isTreeDurable = wrapper.isDependencyTreeDurable();
|
|
132
133
|
await this.registerHandler(applicationRef, routeInfo, async (req, res, next) => {
|
|
133
134
|
try {
|
|
134
|
-
const contextId =
|
|
135
|
-
if (!req[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
136
|
-
Object.defineProperty(req, request_constants_1.REQUEST_CONTEXT_ID, {
|
|
137
|
-
value: contextId,
|
|
138
|
-
enumerable: false,
|
|
139
|
-
writable: false,
|
|
140
|
-
configurable: false,
|
|
141
|
-
});
|
|
142
|
-
this.container.registerRequestProvider(contextId.getParent ? contextId.payload : req, contextId);
|
|
143
|
-
}
|
|
135
|
+
const contextId = this.getContextId(req, isTreeDurable);
|
|
144
136
|
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, collection, contextId);
|
|
145
137
|
const proxy = await this.createProxy(contextInstance, contextId);
|
|
146
138
|
return proxy(req, res, next);
|
|
@@ -164,9 +156,10 @@ class MiddlewareModule {
|
|
|
164
156
|
async registerHandler(applicationRef, { path, method, version }, proxy) {
|
|
165
157
|
const prefix = this.config.getGlobalPrefix();
|
|
166
158
|
const excludedRoutes = this.config.getGlobalPrefixOptions().exclude;
|
|
159
|
+
const isAWildcard = ['*', '/*', '(.*)', '/(.*)'].includes(path);
|
|
167
160
|
if ((Array.isArray(excludedRoutes) &&
|
|
168
161
|
(0, utils_1.isRouteExcluded)(excludedRoutes, path, method)) ||
|
|
169
|
-
|
|
162
|
+
isAWildcard) {
|
|
170
163
|
path = (0, shared_utils_1.addLeadingSlash)(path);
|
|
171
164
|
}
|
|
172
165
|
else {
|
|
@@ -186,14 +179,29 @@ class MiddlewareModule {
|
|
|
186
179
|
const isMethodAll = (0, utils_1.isRequestMethodAll)(method);
|
|
187
180
|
const requestMethod = request_method_enum_1.RequestMethod[method];
|
|
188
181
|
const router = await applicationRef.createMiddlewareFactory(method);
|
|
189
|
-
|
|
182
|
+
const middlewareFunction = isMethodAll
|
|
190
183
|
? proxy
|
|
191
184
|
: (req, res, next) => {
|
|
192
185
|
if (applicationRef.getRequestMethod(req) === requestMethod) {
|
|
193
186
|
return proxy(req, res, next);
|
|
194
187
|
}
|
|
195
188
|
return next();
|
|
189
|
+
};
|
|
190
|
+
router(path, middlewareFunction);
|
|
191
|
+
}
|
|
192
|
+
getContextId(request, isTreeDurable) {
|
|
193
|
+
const contextId = context_id_factory_1.ContextIdFactory.getByRequest(request);
|
|
194
|
+
if (!request[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
195
|
+
Object.defineProperty(request, request_constants_1.REQUEST_CONTEXT_ID, {
|
|
196
|
+
value: contextId,
|
|
197
|
+
enumerable: false,
|
|
198
|
+
writable: false,
|
|
199
|
+
configurable: false,
|
|
196
200
|
});
|
|
201
|
+
const requestProviderValue = isTreeDurable ? contextId.payload : request;
|
|
202
|
+
this.container.registerRequestProvider(requestProviderValue, contextId);
|
|
203
|
+
}
|
|
204
|
+
return contextId;
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
exports.MiddlewareModule = MiddlewareModule;
|
package/middleware/utils.js
CHANGED
|
@@ -101,7 +101,7 @@ export declare class NestApplicationContext<TOptions extends NestApplicationCont
|
|
|
101
101
|
* Terminates the application
|
|
102
102
|
* @returns {Promise<void>}
|
|
103
103
|
*/
|
|
104
|
-
close(): Promise<void>;
|
|
104
|
+
close(signal?: string): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Sets custom logger service.
|
|
107
107
|
* Flushes buffered logs if auto flush is on.
|
|
@@ -16,6 +16,12 @@ const instance_links_host_1 = require("./injector/instance-links-host");
|
|
|
16
16
|
* @publicApi
|
|
17
17
|
*/
|
|
18
18
|
class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
19
|
+
get instanceLinksHost() {
|
|
20
|
+
if (!this._instanceLinksHost) {
|
|
21
|
+
this._instanceLinksHost = new instance_links_host_1.InstanceLinksHost(this.container);
|
|
22
|
+
}
|
|
23
|
+
return this._instanceLinksHost;
|
|
24
|
+
}
|
|
19
25
|
constructor(container, appOptions = {}, contextModule = null, scope = new Array()) {
|
|
20
26
|
super();
|
|
21
27
|
this.container = container;
|
|
@@ -34,12 +40,6 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
34
40
|
this.printInPreviewModeWarning();
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
|
-
get instanceLinksHost() {
|
|
38
|
-
if (!this._instanceLinksHost) {
|
|
39
|
-
this._instanceLinksHost = new instance_links_host_1.InstanceLinksHost(this.container);
|
|
40
|
-
}
|
|
41
|
-
return this._instanceLinksHost;
|
|
42
|
-
}
|
|
43
43
|
selectContextModule() {
|
|
44
44
|
const modules = this.container.getModules().values();
|
|
45
45
|
this.contextModule = modules.next().value;
|
|
@@ -107,11 +107,11 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
107
107
|
* Terminates the application
|
|
108
108
|
* @returns {Promise<void>}
|
|
109
109
|
*/
|
|
110
|
-
async close() {
|
|
110
|
+
async close(signal) {
|
|
111
111
|
await this.callDestroyHook();
|
|
112
|
-
await this.callBeforeShutdownHook();
|
|
112
|
+
await this.callBeforeShutdownHook(signal);
|
|
113
113
|
await this.dispose();
|
|
114
|
-
await this.callShutdownHook();
|
|
114
|
+
await this.callShutdownHook(signal);
|
|
115
115
|
this.unsubscribeFromProcessSignals();
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
@@ -176,13 +176,20 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
|
|
|
176
176
|
* @param {string[]} signals The system signals it should listen to
|
|
177
177
|
*/
|
|
178
178
|
listenToShutdownSignals(signals) {
|
|
179
|
+
let receivedSignal = false;
|
|
179
180
|
const cleanup = async (signal) => {
|
|
180
181
|
try {
|
|
181
|
-
|
|
182
|
+
if (receivedSignal) {
|
|
183
|
+
// If we receive another signal while we're waiting
|
|
184
|
+
// for the server to stop, just ignore it.
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
receivedSignal = true;
|
|
182
188
|
await this.callDestroyHook();
|
|
183
189
|
await this.callBeforeShutdownHook(signal);
|
|
184
190
|
await this.dispose();
|
|
185
191
|
await this.callShutdownHook(signal);
|
|
192
|
+
signals.forEach(sig => process.removeListener(sig, cleanup));
|
|
186
193
|
process.kill(process.pid, signal);
|
|
187
194
|
}
|
|
188
195
|
catch (err) {
|
package/nest-application.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export declare class NestApplication extends NestApplicationContext<NestApplicat
|
|
|
41
41
|
getHttpServer(): any;
|
|
42
42
|
startAllMicroservices(): Promise<this>;
|
|
43
43
|
use(...args: [any, any?]): this;
|
|
44
|
+
useBodyParser(...args: [any, any?]): this;
|
|
44
45
|
enableCors(options?: CorsOptions | CorsOptionsDelegate<any>): void;
|
|
45
46
|
enableVersioning(options?: VersioningOptions): this;
|
|
46
47
|
listen(port: number | string): Promise<any>;
|
package/nest-application.js
CHANGED
|
@@ -147,6 +147,16 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
147
147
|
this.httpAdapter.use(...args);
|
|
148
148
|
return this;
|
|
149
149
|
}
|
|
150
|
+
useBodyParser(...args) {
|
|
151
|
+
if (!('useBodyParser' in this.httpAdapter)) {
|
|
152
|
+
this.logger.warn('Your HTTP Adapter does not support `.useBodyParser`.');
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
const [parserType, ...otherArgs] = args;
|
|
156
|
+
const rawBody = !!this.appOptions.rawBody;
|
|
157
|
+
this.httpAdapter.useBodyParser(...[parserType, rawBody, ...otherArgs]);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
150
160
|
enableCors(options) {
|
|
151
161
|
this.httpAdapter.enableCors(options);
|
|
152
162
|
}
|
|
@@ -229,11 +239,13 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
229
239
|
return {
|
|
230
240
|
requestMethod: common_1.RequestMethod.ALL,
|
|
231
241
|
pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route)),
|
|
242
|
+
path: route,
|
|
232
243
|
};
|
|
233
244
|
}
|
|
234
245
|
return {
|
|
235
246
|
requestMethod: route.method,
|
|
236
247
|
pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route.path)),
|
|
248
|
+
path: route.path,
|
|
237
249
|
};
|
|
238
250
|
});
|
|
239
251
|
this.config.setGlobalPrefixOptions(Object.assign(Object.assign({}, options), { exclude }));
|
package/nest-factory.js
CHANGED
|
@@ -14,6 +14,7 @@ const injector_1 = require("./injector/injector");
|
|
|
14
14
|
const instance_loader_1 = require("./injector/instance-loader");
|
|
15
15
|
const graph_inspector_1 = require("./inspector/graph-inspector");
|
|
16
16
|
const noop_graph_inspector_1 = require("./inspector/noop-graph-inspector");
|
|
17
|
+
const uuid_factory_1 = require("./inspector/uuid-factory");
|
|
17
18
|
const metadata_scanner_1 = require("./metadata-scanner");
|
|
18
19
|
const nest_application_1 = require("./nest-application");
|
|
19
20
|
const nest_application_context_1 = require("./nest-application-context");
|
|
@@ -90,6 +91,9 @@ class NestFactoryStatic {
|
|
|
90
91
|
return this.createProxy(instance);
|
|
91
92
|
}
|
|
92
93
|
async initialize(module, container, graphInspector, config = new application_config_1.ApplicationConfig(), options = {}, httpServer = null) {
|
|
94
|
+
uuid_factory_1.UuidFactory.mode = options.snapshot
|
|
95
|
+
? uuid_factory_1.UuidFactoryMode.Deterministic
|
|
96
|
+
: uuid_factory_1.UuidFactoryMode.Random;
|
|
93
97
|
const injector = new injector_1.Injector({ preview: options.preview });
|
|
94
98
|
const instanceLoader = new instance_loader_1.InstanceLoader(container, injector, graphInspector);
|
|
95
99
|
const metadataScanner = new metadata_scanner_1.MetadataScanner();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.1",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"uuid": "9.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "
|
|
39
|
+
"@nestjs/common": "9.3.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@nestjs/common": "^9.0.0",
|
|
@@ -8,7 +8,7 @@ class DebugReplFn extends repl_function_1.ReplFunction {
|
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this.fnDefinition = {
|
|
10
10
|
name: 'debug',
|
|
11
|
-
description: 'Print all registered modules as a list together with their controllers and providers
|
|
11
|
+
description: 'Print all registered modules as a list together with their controllers and providers.\nIf the argument is passed in, for example, "debug(MyModule)" then it will only print components of this specific module.',
|
|
12
12
|
signature: '(moduleCls?: ClassRef | string) => void',
|
|
13
13
|
};
|
|
14
14
|
}
|
package/repl/repl-context.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { INestApplicationContext, InjectionToken, Logger } from '@nestjs/common';
|
|
2
2
|
import { ReplFunction } from './repl-function';
|
|
3
3
|
import type { ReplFunctionClass } from './repl.interfaces';
|
|
4
|
-
|
|
5
|
-
export
|
|
4
|
+
type ModuleKey = string;
|
|
5
|
+
export type ModuleDebugEntry = {
|
|
6
6
|
controllers: Record<string, InjectionToken>;
|
|
7
7
|
providers: Record<string, InjectionToken>;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type ReplScope = Record<string, any>;
|
|
10
10
|
export declare class ReplContext {
|
|
11
11
|
readonly app: INestApplicationContext;
|
|
12
12
|
readonly logger: Logger;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineDefaultCommandsOnRepl = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Displays a list of available commands in the REPL alongside with their
|
|
6
|
+
* descriptions.
|
|
7
|
+
* (c) This code was inspired by the 'help' command from Node.js core:
|
|
8
|
+
* {@link https://github.com/nodejs/node/blob/58b60c1393dd65cd228a8b0084a19acd2c1d16aa/lib/repl.js#L1741-L1759}
|
|
9
|
+
*/
|
|
10
|
+
function listAllCommands(replServer) {
|
|
11
|
+
Object.keys(replServer.commands)
|
|
12
|
+
.sort()
|
|
13
|
+
.forEach(name => {
|
|
14
|
+
const cmd = replServer.commands[name];
|
|
15
|
+
if (cmd) {
|
|
16
|
+
replServer.output.write(`${name}\t${cmd.help || ''}\n`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function defineDefaultCommandsOnRepl(replServer) {
|
|
21
|
+
replServer.defineCommand('help', {
|
|
22
|
+
help: 'Show REPL options',
|
|
23
|
+
action(name) {
|
|
24
|
+
this.clearBufferedCommand();
|
|
25
|
+
if (name) {
|
|
26
|
+
// Considering native commands before native nestjs injected functions.
|
|
27
|
+
const nativeCommandOrFunction = this.commands[name] || this.context[name];
|
|
28
|
+
// NOTE: If the command was retrieve from the context, it will have a `help`
|
|
29
|
+
// getter property that outputs the helper message and returns undefined.
|
|
30
|
+
// But if the command was retrieve from the `commands` object, it will
|
|
31
|
+
// have a `help` property that returns the helper message.
|
|
32
|
+
const helpMessage = nativeCommandOrFunction === null || nativeCommandOrFunction === void 0 ? void 0 : nativeCommandOrFunction.help;
|
|
33
|
+
if (helpMessage) {
|
|
34
|
+
this.output.write(`${helpMessage}\n`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
listAllCommands(this);
|
|
39
|
+
this.output.write('\n\n');
|
|
40
|
+
this.context.help();
|
|
41
|
+
this.output.write('\nPress Ctrl+C to abort current expression, Ctrl+D to exit the REPL\n');
|
|
42
|
+
}
|
|
43
|
+
this.displayPrompt();
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.defineDefaultCommandsOnRepl = defineDefaultCommandsOnRepl;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReplContext } from './repl-context';
|
|
2
2
|
import type { ReplFunction } from './repl-function';
|
|
3
|
-
export
|
|
3
|
+
export type ReplFnDefinition = {
|
|
4
4
|
/** Function's name. Note that this should be a valid JavaScript function name. */
|
|
5
5
|
name: string;
|
|
6
6
|
/** Alternative names to the function. */
|
|
@@ -13,4 +13,4 @@ export declare type ReplFnDefinition = {
|
|
|
13
13
|
*/
|
|
14
14
|
signature: string;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type ReplFunctionClass = new (replContext: ReplContext) => ReplFunction;
|
package/repl/repl.js
CHANGED
|
@@ -8,6 +8,7 @@ const assign_to_object_util_1 = require("./assign-to-object.util");
|
|
|
8
8
|
const constants_1 = require("./constants");
|
|
9
9
|
const repl_context_1 = require("./repl-context");
|
|
10
10
|
const repl_logger_1 = require("./repl-logger");
|
|
11
|
+
const repl_native_commands_1 = require("./repl-native-commands");
|
|
11
12
|
async function repl(module) {
|
|
12
13
|
const app = await nest_factory_1.NestFactory.createApplicationContext(module, {
|
|
13
14
|
abortOnError: false,
|
|
@@ -22,6 +23,7 @@ async function repl(module) {
|
|
|
22
23
|
ignoreUndefined: true,
|
|
23
24
|
});
|
|
24
25
|
(0, assign_to_object_util_1.assignToObject)(replServer.context, replContext.globalScope);
|
|
26
|
+
(0, repl_native_commands_1.defineDefaultCommandsOnRepl)(replServer);
|
|
25
27
|
return replServer;
|
|
26
28
|
}
|
|
27
29
|
exports.repl = repl;
|
|
@@ -8,17 +8,14 @@ const logger_service_1 = require("@nestjs/common/services/logger.service");
|
|
|
8
8
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
9
9
|
const pathToRegexp = require("path-to-regexp");
|
|
10
10
|
const unknown_request_mapping_exception_1 = require("../errors/exceptions/unknown-request-mapping.exception");
|
|
11
|
-
const
|
|
12
|
-
const guards_context_creator_1 = require("../guards/guards-context-creator");
|
|
11
|
+
const guards_1 = require("../guards");
|
|
13
12
|
const context_id_factory_1 = require("../helpers/context-id-factory");
|
|
14
13
|
const execution_context_host_1 = require("../helpers/execution-context-host");
|
|
15
14
|
const messages_1 = require("../helpers/messages");
|
|
16
15
|
const router_method_factory_1 = require("../helpers/router-method-factory");
|
|
17
16
|
const constants_2 = require("../injector/constants");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const pipes_consumer_1 = require("../pipes/pipes-consumer");
|
|
21
|
-
const pipes_context_creator_1 = require("../pipes/pipes-context-creator");
|
|
17
|
+
const interceptors_1 = require("../interceptors");
|
|
18
|
+
const pipes_1 = require("../pipes");
|
|
22
19
|
const paths_explorer_1 = require("./paths-explorer");
|
|
23
20
|
const request_constants_1 = require("./request/request-constants");
|
|
24
21
|
const route_params_factory_1 = require("./route-params-factory");
|
|
@@ -38,12 +35,12 @@ class RouterExplorer {
|
|
|
38
35
|
this.exceptionFiltersCache = new WeakMap();
|
|
39
36
|
this.pathsExplorer = new paths_explorer_1.PathsExplorer(metadataScanner);
|
|
40
37
|
const routeParamsFactory = new route_params_factory_1.RouteParamsFactory();
|
|
41
|
-
const pipesContextCreator = new
|
|
42
|
-
const pipesConsumer = new
|
|
43
|
-
const guardsContextCreator = new
|
|
44
|
-
const guardsConsumer = new
|
|
45
|
-
const interceptorsContextCreator = new
|
|
46
|
-
const interceptorsConsumer = new
|
|
38
|
+
const pipesContextCreator = new pipes_1.PipesContextCreator(container, config);
|
|
39
|
+
const pipesConsumer = new pipes_1.PipesConsumer();
|
|
40
|
+
const guardsContextCreator = new guards_1.GuardsContextCreator(container, config);
|
|
41
|
+
const guardsConsumer = new guards_1.GuardsConsumer();
|
|
42
|
+
const interceptorsContextCreator = new interceptors_1.InterceptorsContextCreator(container, config);
|
|
43
|
+
const interceptorsConsumer = new interceptors_1.InterceptorsConsumer();
|
|
47
44
|
this.executionContextCreator = new router_execution_context_1.RouterExecutionContext(routeParamsFactory, pipesContextCreator, pipesConsumer, guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, container.getHttpAdapterRef());
|
|
48
45
|
}
|
|
49
46
|
explore(instanceWrapper, moduleKey, applicationRef, host, routePathMetadata) {
|
|
@@ -161,9 +158,10 @@ class RouterExplorer {
|
|
|
161
158
|
createRequestScopedHandler(instanceWrapper, requestMethod, moduleRef, moduleKey, methodName) {
|
|
162
159
|
const { instance } = instanceWrapper;
|
|
163
160
|
const collection = moduleRef.controllers;
|
|
161
|
+
const isTreeDurable = instanceWrapper.isDependencyTreeDurable();
|
|
164
162
|
return async (req, res, next) => {
|
|
165
163
|
try {
|
|
166
|
-
const contextId = this.getContextId(req);
|
|
164
|
+
const contextId = this.getContextId(req, isTreeDurable);
|
|
167
165
|
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, collection, contextId);
|
|
168
166
|
await this.createCallbackProxy(contextInstance, contextInstance[methodName], methodName, moduleKey, requestMethod, contextId, instanceWrapper.id)(req, res, next);
|
|
169
167
|
}
|
|
@@ -178,7 +176,7 @@ class RouterExplorer {
|
|
|
178
176
|
}
|
|
179
177
|
};
|
|
180
178
|
}
|
|
181
|
-
getContextId(request) {
|
|
179
|
+
getContextId(request, isTreeDurable) {
|
|
182
180
|
const contextId = context_id_factory_1.ContextIdFactory.getByRequest(request);
|
|
183
181
|
if (!request[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
184
182
|
Object.defineProperty(request, request_constants_1.REQUEST_CONTEXT_ID, {
|
|
@@ -187,7 +185,8 @@ class RouterExplorer {
|
|
|
187
185
|
writable: false,
|
|
188
186
|
configurable: false,
|
|
189
187
|
});
|
|
190
|
-
|
|
188
|
+
const requestProviderValue = isTreeDurable ? contextId.payload : request;
|
|
189
|
+
this.container.registerRequestProvider(requestProviderValue, contextId);
|
|
191
190
|
}
|
|
192
191
|
return contextId;
|
|
193
192
|
}
|
package/router/router-proxy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExceptionsHandler } from '../exceptions/exceptions-handler';
|
|
2
|
-
export
|
|
2
|
+
export type RouterProxyCallback = <TRequest, TResponse>(req?: TRequest, res?: TResponse, next?: () => void) => void;
|
|
3
3
|
export declare class RouterProxy {
|
|
4
|
-
createProxy(targetCallback: RouterProxyCallback, exceptionsHandler: ExceptionsHandler): <TRequest, TResponse>(req: TRequest, res: TResponse, next: () => void) => Promise<
|
|
5
|
-
createExceptionLayerProxy(targetCallback: <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => void, exceptionsHandler: ExceptionsHandler): <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => Promise<
|
|
4
|
+
createProxy(targetCallback: RouterProxyCallback, exceptionsHandler: ExceptionsHandler): <TRequest, TResponse>(req: TRequest, res: TResponse, next: () => void) => Promise<TResponse>;
|
|
5
|
+
createExceptionLayerProxy(targetCallback: <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => void, exceptionsHandler: ExceptionsHandler): <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => Promise<TResponse>;
|
|
6
6
|
}
|
package/router/router-proxy.js
CHANGED
|
@@ -11,6 +11,7 @@ class RouterProxy {
|
|
|
11
11
|
catch (e) {
|
|
12
12
|
const host = new execution_context_host_1.ExecutionContextHost([req, res, next]);
|
|
13
13
|
exceptionsHandler.next(e, host);
|
|
14
|
+
return res;
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
17
|
}
|
|
@@ -22,6 +23,7 @@ class RouterProxy {
|
|
|
22
23
|
catch (e) {
|
|
23
24
|
const host = new execution_context_host_1.ExecutionContextHost([req, res, next]);
|
|
24
25
|
exceptionsHandler.next(e, host);
|
|
26
|
+
return res;
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
29
|
}
|
package/router/sse-stream.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { MessageEvent } from '@nestjs/common/interfaces';
|
|
5
5
|
import { IncomingMessage, OutgoingHttpHeaders } from 'http';
|
|
6
6
|
import { Transform } from 'stream';
|
|
7
|
-
export
|
|
7
|
+
export type AdditionalHeaders = Record<string, string[] | string | number | undefined>;
|
|
8
8
|
interface ReadHeaders {
|
|
9
9
|
getHeaders?(): AdditionalHeaders;
|
|
10
10
|
}
|
|
@@ -14,8 +14,8 @@ interface WriteHeaders {
|
|
|
14
14
|
writeHead?(statusCode: number, headers?: OutgoingHttpHeaders): void;
|
|
15
15
|
flushHeaders?(): void;
|
|
16
16
|
}
|
|
17
|
-
export
|
|
18
|
-
export
|
|
17
|
+
export type WritableHeaderStream = NodeJS.WritableStream & WriteHeaders;
|
|
18
|
+
export type HeaderStream = WritableHeaderStream & ReadHeaders;
|
|
19
19
|
/**
|
|
20
20
|
* Adapted from https://raw.githubusercontent.com/EventSource/node-ssestream
|
|
21
21
|
* Transforms "messages" to W3C event stream content.
|
package/scanner.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { DynamicModule, ForwardReference, Provider } from '@nestjs/common';
|
|
2
2
|
import { EnhancerSubtype } from '@nestjs/common/constants';
|
|
3
|
-
import { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider } from '@nestjs/common/interfaces';
|
|
4
|
-
import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface';
|
|
5
|
-
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
|
|
6
|
-
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
3
|
+
import { ClassProvider, ExistingProvider, FactoryProvider, ValueProvider, Controller, Injectable, Type } from '@nestjs/common/interfaces';
|
|
7
4
|
import { ApplicationConfig } from './application-config';
|
|
8
5
|
import { NestContainer } from './injector/container';
|
|
9
6
|
import { InstanceWrapper } from './injector/instance-wrapper';
|
package/scanner.js
CHANGED
|
@@ -13,7 +13,7 @@ const invalid_module_exception_1 = require("./errors/exceptions/invalid-module.e
|
|
|
13
13
|
const undefined_module_exception_1 = require("./errors/exceptions/undefined-module.exception");
|
|
14
14
|
const get_class_scope_1 = require("./helpers/get-class-scope");
|
|
15
15
|
const internal_core_module_factory_1 = require("./injector/internal-core-module/internal-core-module-factory");
|
|
16
|
-
const
|
|
16
|
+
const uuid_factory_1 = require("./inspector/uuid-factory");
|
|
17
17
|
class DependenciesScanner {
|
|
18
18
|
constructor(container, metadataScanner, graphInspector, applicationConfig = new application_config_1.ApplicationConfig()) {
|
|
19
19
|
this.container = container;
|
|
@@ -214,7 +214,7 @@ class DependenciesScanner {
|
|
|
214
214
|
if (!providersKeys.includes(type)) {
|
|
215
215
|
return this.container.addProvider(provider, token);
|
|
216
216
|
}
|
|
217
|
-
const uuid =
|
|
217
|
+
const uuid = uuid_factory_1.UuidFactory.get(type.toString());
|
|
218
218
|
const providerToken = `${type} (UUID: ${uuid})`;
|
|
219
219
|
let scope = provider.scope;
|
|
220
220
|
if ((0, shared_utils_1.isNil)(scope) && provider.useClass) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function stringCleaner(str: string): string;
|