@nestjs/core 9.3.2 → 9.3.3

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/Readme.md CHANGED
@@ -11,7 +11,6 @@
11
11
  <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12
12
  <a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13
13
  <a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14
- <a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15
14
  <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16
15
  <a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17
16
  <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
@@ -109,9 +109,11 @@ class InstanceWrapper {
109
109
  if (!(0, shared_utils_1.isUndefined)(this.isTreeDurable)) {
110
110
  return this.isTreeDurable;
111
111
  }
112
- if (this.durable === true) {
113
- this.isTreeDurable = true;
114
- this.printIntrospectedAsDurable();
112
+ if (this.scope === common_1.Scope.REQUEST) {
113
+ this.isTreeDurable = this.durable === undefined ? false : this.durable;
114
+ if (this.isTreeDurable) {
115
+ this.printIntrospectedAsDurable();
116
+ }
115
117
  return this.isTreeDurable;
116
118
  }
117
119
  const isStatic = this.isDependencyTreeStatic();
@@ -120,7 +122,7 @@ class InstanceWrapper {
120
122
  }
121
123
  const isTreeNonDurable = this.introspectDepsAttribute((collection, registry) => collection.some((item) => !item.isDependencyTreeStatic() &&
122
124
  !item.isDependencyTreeDurable(registry)), lookupRegistry);
123
- this.isTreeDurable = !isTreeNonDurable && this.durable !== false;
125
+ this.isTreeDurable = !isTreeNonDurable;
124
126
  if (this.isTreeDurable) {
125
127
  this.printIntrospectedAsDurable();
126
128
  }
@@ -128,24 +130,23 @@ class InstanceWrapper {
128
130
  }
129
131
  introspectDepsAttribute(callback, lookupRegistry = []) {
130
132
  if (lookupRegistry.includes(this[exports.INSTANCE_ID_SYMBOL])) {
131
- return true;
133
+ return false;
132
134
  }
133
135
  lookupRegistry = lookupRegistry.concat(this[exports.INSTANCE_ID_SYMBOL]);
134
136
  const { dependencies, properties, enhancers } = this[exports.INSTANCE_METADATA_SYMBOL];
135
- let introspectionResult = (dependencies && callback(dependencies, lookupRegistry)) || !dependencies;
136
- if (!introspectionResult || !(properties || enhancers)) {
137
+ let introspectionResult = dependencies
138
+ ? callback(dependencies, lookupRegistry)
139
+ : false;
140
+ if (introspectionResult || !(properties || enhancers)) {
137
141
  return introspectionResult;
138
142
  }
139
- const propertiesHosts = (properties || []).map(item => item.wrapper);
140
- introspectionResult =
141
- introspectionResult &&
142
- ((properties &&
143
- callback(properties.map(item => item.wrapper), lookupRegistry)) ||
144
- !properties);
145
- if (!introspectionResult || !enhancers) {
143
+ introspectionResult = properties
144
+ ? callback(properties.map(item => item.wrapper), lookupRegistry)
145
+ : false;
146
+ if (introspectionResult || !enhancers) {
146
147
  return introspectionResult;
147
148
  }
148
- return callback(enhancers, lookupRegistry);
149
+ return enhancers ? callback(enhancers, lookupRegistry) : false;
149
150
  }
150
151
  isDependencyTreeStatic(lookupRegistry = []) {
151
152
  if (!(0, shared_utils_1.isUndefined)(this.isTreeStatic)) {
@@ -156,7 +157,7 @@ class InstanceWrapper {
156
157
  this.printIntrospectedAsRequestScoped();
157
158
  return this.isTreeStatic;
158
159
  }
159
- this.isTreeStatic = this.introspectDepsAttribute((collection, registry) => collection.every((item) => item.isDependencyTreeStatic(registry)), lookupRegistry);
160
+ this.isTreeStatic = !this.introspectDepsAttribute((collection, registry) => collection.some((item) => !item.isDependencyTreeStatic(registry)), lookupRegistry);
160
161
  if (!this.isTreeStatic) {
161
162
  this.printIntrospectedAsRequestScoped();
162
163
  }
@@ -1,10 +1,13 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
2
  import { Type } from '@nestjs/common/interfaces/type.interface';
3
3
  export declare class ModuleTokenFactory {
4
+ private readonly moduleTokenCache;
4
5
  private readonly moduleIdsCache;
5
6
  create(metatype: Type<unknown>, dynamicModuleMetadata?: Partial<DynamicModule> | undefined): string;
6
- getDynamicMetadataToken(dynamicModuleMetadata: Partial<DynamicModule> | undefined): string;
7
+ getStaticModuleToken(moduleId: string, moduleName: string): string;
8
+ getStringifiedOpaqueToken(opaqueToken: object | undefined): string;
7
9
  getModuleId(metatype: Type<unknown>): string;
8
10
  getModuleName(metatype: Type<any>): string;
11
+ private hashString;
9
12
  private replacer;
10
13
  }
@@ -3,28 +3,42 @@ 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 xxhash_1 = require("@node-rs/xxhash");
6
7
  const fast_safe_stringify_1 = require("fast-safe-stringify");
7
- const hash = require("object-hash");
8
+ const CLASS_STR = 'class ';
9
+ const CLASS_STR_LEN = CLASS_STR.length;
8
10
  class ModuleTokenFactory {
9
11
  constructor() {
12
+ this.moduleTokenCache = new Map();
10
13
  this.moduleIdsCache = new WeakMap();
11
14
  }
12
15
  create(metatype, dynamicModuleMetadata) {
13
16
  const moduleId = this.getModuleId(metatype);
17
+ if (!dynamicModuleMetadata) {
18
+ return this.getStaticModuleToken(moduleId, this.getModuleName(metatype));
19
+ }
14
20
  const opaqueToken = {
15
21
  id: moduleId,
16
22
  module: this.getModuleName(metatype),
17
- dynamic: this.getDynamicMetadataToken(dynamicModuleMetadata),
23
+ dynamic: dynamicModuleMetadata,
18
24
  };
19
- return hash(opaqueToken, { ignoreUnknown: true });
25
+ const opaqueTokenString = this.getStringifiedOpaqueToken(opaqueToken);
26
+ return this.hashString(opaqueTokenString);
27
+ }
28
+ getStaticModuleToken(moduleId, moduleName) {
29
+ const key = `${moduleId}_${moduleName}`;
30
+ if (this.moduleTokenCache.has(key)) {
31
+ return this.moduleTokenCache.get(key);
32
+ }
33
+ const hash = this.hashString(key);
34
+ this.moduleTokenCache.set(key, hash);
35
+ return hash;
20
36
  }
21
- getDynamicMetadataToken(dynamicModuleMetadata) {
37
+ getStringifiedOpaqueToken(opaqueToken) {
22
38
  // Uses safeStringify instead of JSON.stringify to support circular dynamic modules
23
39
  // The replacer function is also required in order to obtain real class names
24
40
  // instead of the unified "Function" key
25
- return dynamicModuleMetadata
26
- ? (0, fast_safe_stringify_1.default)(dynamicModuleMetadata, this.replacer)
27
- : '';
41
+ return opaqueToken ? (0, fast_safe_stringify_1.default)(opaqueToken, this.replacer) : '';
28
42
  }
29
43
  getModuleId(metatype) {
30
44
  let moduleId = this.moduleIdsCache.get(metatype);
@@ -38,14 +52,17 @@ class ModuleTokenFactory {
38
52
  getModuleName(metatype) {
39
53
  return metatype.name;
40
54
  }
55
+ hashString(value) {
56
+ return (0, xxhash_1.xxh32)(value).toString();
57
+ }
41
58
  replacer(key, value) {
42
59
  if ((0, shared_utils_1.isFunction)(value)) {
43
60
  const funcAsString = value.toString();
44
- const isClass = /^class\s/.test(funcAsString);
61
+ const isClass = funcAsString.slice(0, CLASS_STR_LEN) === CLASS_STR;
45
62
  if (isClass) {
46
63
  return value.name;
47
64
  }
48
- return hash(funcAsString, { ignoreUnknown: true });
65
+ return funcAsString;
49
66
  }
50
67
  if ((0, shared_utils_1.isSymbol)(value)) {
51
68
  return value.toString();
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModulesContainer = void 0;
4
- const uuid_1 = require("uuid");
4
+ const uid_1 = require("uid");
5
5
  class ModulesContainer extends Map {
6
6
  constructor() {
7
7
  super(...arguments);
8
- this._applicationId = (0, uuid_1.v4)();
8
+ this._applicationId = (0, uid_1.uid)(21);
9
9
  }
10
10
  get applicationId() {
11
11
  return this._applicationId;
@@ -1,16 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeterministicUuidRegistry = void 0;
4
- const uuid_1 = require("uuid");
4
+ const xxhash_1 = require("@node-rs/xxhash");
5
5
  const DEFAULT_UUID_NAMESPACE = 'efa0df42-88af-474f-9cad-4206a2319f07';
6
6
  class DeterministicUuidRegistry {
7
7
  static get(str, namespace = DEFAULT_UUID_NAMESPACE, inc = 0) {
8
- const id = inc ? (0, uuid_1.v5)(str + `${inc}`, namespace) : (0, uuid_1.v5)(str, namespace);
9
- if (this.registry.has(id)) {
8
+ const id = inc
9
+ ? (0, xxhash_1.xxh32)(`${namespace}_${str}_${inc}`)
10
+ : (0, xxhash_1.xxh32)(`${namespace}_${str}`);
11
+ const idAsString = `${id}`;
12
+ if (this.registry.has(idAsString)) {
10
13
  return this.get(str, namespace, inc + 1);
11
14
  }
12
- this.registry.add(id);
13
- return id;
15
+ this.registry.add(idAsString);
16
+ return idAsString;
14
17
  }
15
18
  static clear() {
16
19
  this.registry.clear();
@@ -1,5 +1,13 @@
1
1
  import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
2
2
  export declare class MetadataScanner {
3
+ private readonly cachedScannedPrototypes;
4
+ /**
5
+ * @deprecated Use {@link getAllMethodNames} instead.
6
+ */
3
7
  scanFromPrototype<T extends Injectable, R = any>(instance: T, prototype: object, callback: (name: string) => R): R[];
8
+ /**
9
+ * @deprecated Use {@link getAllMethodNames} instead.
10
+ */
4
11
  getAllFilteredMethodNames(prototype: object): IterableIterator<string>;
12
+ getAllMethodNames(prototype: object | null): string[];
5
13
  }
@@ -2,29 +2,78 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MetadataScanner = void 0;
4
4
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
- const iterare_1 = require("iterare");
6
5
  class MetadataScanner {
6
+ constructor() {
7
+ this.cachedScannedPrototypes = new Map();
8
+ }
9
+ /**
10
+ * @deprecated Use {@link getAllMethodNames} instead.
11
+ */
7
12
  scanFromPrototype(instance, prototype, callback) {
8
- const methodNames = new Set(this.getAllFilteredMethodNames(prototype));
9
- return (0, iterare_1.iterate)(methodNames)
10
- .map(callback)
11
- .filter(metadata => !(0, shared_utils_1.isNil)(metadata))
12
- .toArray();
13
+ if (!prototype) {
14
+ return [];
15
+ }
16
+ const visitedNames = new Map();
17
+ const result = [];
18
+ do {
19
+ for (const property of Object.getOwnPropertyNames(prototype)) {
20
+ if (visitedNames.has(property)) {
21
+ continue;
22
+ }
23
+ visitedNames.set(property, true);
24
+ // reason: https://github.com/nestjs/nest/pull/10821#issuecomment-1411916533
25
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
26
+ if (descriptor.set ||
27
+ descriptor.get ||
28
+ (0, shared_utils_1.isConstructor)(property) ||
29
+ !(0, shared_utils_1.isFunction)(prototype[property])) {
30
+ continue;
31
+ }
32
+ const value = callback(property);
33
+ if ((0, shared_utils_1.isNil)(value)) {
34
+ continue;
35
+ }
36
+ result.push(value);
37
+ }
38
+ } while ((prototype = Reflect.getPrototypeOf(prototype)) &&
39
+ prototype !== Object.prototype);
40
+ return result;
13
41
  }
42
+ /**
43
+ * @deprecated Use {@link getAllMethodNames} instead.
44
+ */
14
45
  *getAllFilteredMethodNames(prototype) {
15
- const isMethod = (prop) => {
16
- const descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
17
- if (descriptor.set || descriptor.get) {
18
- return false;
19
- }
20
- return !(0, shared_utils_1.isConstructor)(prop) && (0, shared_utils_1.isFunction)(prototype[prop]);
21
- };
46
+ yield* this.getAllMethodNames(prototype);
47
+ }
48
+ getAllMethodNames(prototype) {
49
+ if (!prototype) {
50
+ return [];
51
+ }
52
+ if (this.cachedScannedPrototypes.has(prototype)) {
53
+ return this.cachedScannedPrototypes.get(prototype);
54
+ }
55
+ const visitedNames = new Map();
56
+ const result = [];
57
+ this.cachedScannedPrototypes.set(prototype, result);
22
58
  do {
23
- yield* (0, iterare_1.iterate)(Object.getOwnPropertyNames(prototype))
24
- .filter(isMethod)
25
- .toArray();
59
+ for (const property of Object.getOwnPropertyNames(prototype)) {
60
+ if (visitedNames.has(property)) {
61
+ continue;
62
+ }
63
+ visitedNames.set(property, true);
64
+ // reason: https://github.com/nestjs/nest/pull/10821#issuecomment-1411916533
65
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
66
+ if (descriptor.set ||
67
+ descriptor.get ||
68
+ (0, shared_utils_1.isConstructor)(property) ||
69
+ !(0, shared_utils_1.isFunction)(prototype[property])) {
70
+ continue;
71
+ }
72
+ result.push(property);
73
+ }
26
74
  } while ((prototype = Reflect.getPrototypeOf(prototype)) &&
27
75
  prototype !== Object.prototype);
76
+ return result;
28
77
  }
29
78
  }
30
79
  exports.MetadataScanner = MetadataScanner;
@@ -1,11 +1,13 @@
1
1
  import { HttpServer, MiddlewareConsumer, Type } from '@nestjs/common/interfaces';
2
2
  import { MiddlewareConfigProxy, MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware';
3
+ import { RouteInfoPathExtractor } from './route-info-path-extractor';
3
4
  import { RoutesMapper } from './routes-mapper';
4
5
  export declare class MiddlewareBuilder implements MiddlewareConsumer {
5
6
  private readonly routesMapper;
6
7
  private readonly httpAdapter;
8
+ private readonly routeInfoPathExtractor;
7
9
  private readonly middlewareCollection;
8
- constructor(routesMapper: RoutesMapper, httpAdapter: HttpServer);
10
+ constructor(routesMapper: RoutesMapper, httpAdapter: HttpServer, routeInfoPathExtractor: RouteInfoPathExtractor);
9
11
  apply(...middleware: Array<Type<any> | Function | any>): MiddlewareConfigProxy;
10
12
  build(): MiddlewareConfiguration[];
11
13
  getHttpAdapter(): HttpServer;
@@ -5,13 +5,14 @@ const dependencies_decorator_1 = require("@nestjs/common/decorators/core/depende
5
5
  const iterare_1 = require("iterare");
6
6
  const utils_1 = require("./utils");
7
7
  class MiddlewareBuilder {
8
- constructor(routesMapper, httpAdapter) {
8
+ constructor(routesMapper, httpAdapter, routeInfoPathExtractor) {
9
9
  this.routesMapper = routesMapper;
10
10
  this.httpAdapter = httpAdapter;
11
+ this.routeInfoPathExtractor = routeInfoPathExtractor;
11
12
  this.middlewareCollection = new Set();
12
13
  }
13
14
  apply(...middleware) {
14
- return new MiddlewareBuilder.ConfigProxy(this, (0, dependencies_decorator_1.flatten)(middleware));
15
+ return new MiddlewareBuilder.ConfigProxy(this, (0, dependencies_decorator_1.flatten)(middleware), this.routeInfoPathExtractor);
15
16
  }
16
17
  build() {
17
18
  return [...this.middlewareCollection];
@@ -22,16 +23,17 @@ class MiddlewareBuilder {
22
23
  }
23
24
  exports.MiddlewareBuilder = MiddlewareBuilder;
24
25
  MiddlewareBuilder.ConfigProxy = class {
25
- constructor(builder, middleware) {
26
+ constructor(builder, middleware, routeInfoPathExtractor) {
26
27
  this.builder = builder;
27
28
  this.middleware = middleware;
29
+ this.routeInfoPathExtractor = routeInfoPathExtractor;
28
30
  this.excludedRoutes = [];
29
31
  }
30
32
  getExcludedRoutes() {
31
33
  return this.excludedRoutes;
32
34
  }
33
35
  exclude(...routes) {
34
- this.excludedRoutes = this.getRoutesFlatList(routes);
36
+ this.excludedRoutes = this.getRoutesFlatList(routes).map(route => (Object.assign(Object.assign({}, route), { path: this.routeInfoPathExtractor.extractPathFrom(route) })));
35
37
  return this;
36
38
  }
37
39
  forRoutes(...routes) {
@@ -50,7 +50,7 @@ class MiddlewareModule {
50
50
  if (!instance.configure) {
51
51
  return;
52
52
  }
53
- const middlewareBuilder = new builder_1.MiddlewareBuilder(this.routesMapper, this.httpAdapter);
53
+ const middlewareBuilder = new builder_1.MiddlewareBuilder(this.routesMapper, this.httpAdapter, this.routeInfoPathExtractor);
54
54
  try {
55
55
  await instance.configure(middlewareBuilder);
56
56
  }
@@ -3,6 +3,13 @@ import { ApplicationConfig } from '../application-config';
3
3
  export declare class RouteInfoPathExtractor {
4
4
  private readonly applicationConfig;
5
5
  private routePathFactory;
6
+ private readonly prefixPath;
7
+ private readonly excludedGlobalPrefixRoutes;
8
+ private readonly versioningConfig?;
6
9
  constructor(applicationConfig: ApplicationConfig);
7
10
  extractPathsFrom({ path, method, version }: RouteInfo): string[];
11
+ extractPathFrom(route: RouteInfo): string;
12
+ private isAWildcard;
13
+ private extractNonWildcardPathFrom;
14
+ private extractVersionPathFrom;
8
15
  }
@@ -9,30 +9,46 @@ class RouteInfoPathExtractor {
9
9
  constructor(applicationConfig) {
10
10
  this.applicationConfig = applicationConfig;
11
11
  this.routePathFactory = new route_path_factory_1.RoutePathFactory(applicationConfig);
12
+ this.prefixPath = (0, shared_utils_1.stripEndSlash)((0, shared_utils_1.addLeadingSlash)(this.applicationConfig.getGlobalPrefix()));
13
+ this.excludedGlobalPrefixRoutes =
14
+ this.applicationConfig.getGlobalPrefixOptions().exclude;
15
+ this.versioningConfig = this.applicationConfig.getVersioning();
12
16
  }
13
17
  extractPathsFrom({ path, method, version }) {
14
- const prefixPath = (0, shared_utils_1.stripEndSlash)((0, shared_utils_1.addLeadingSlash)(this.applicationConfig.getGlobalPrefix()));
15
- const excludedRoutes = this.applicationConfig.getGlobalPrefixOptions().exclude;
16
- const applicationVersioningConfig = this.applicationConfig.getVersioning();
17
- let versionPath = '';
18
- if (version && (applicationVersioningConfig === null || applicationVersioningConfig === void 0 ? void 0 : applicationVersioningConfig.type) === common_1.VersioningType.URI) {
19
- const versionPrefix = this.routePathFactory.getVersionPrefix(applicationVersioningConfig);
20
- versionPath = (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString());
21
- }
22
- const isAWildcard = ['*', '/*', '/*/', '(.*)', '/(.*)'].includes(path);
23
- if (isAWildcard) {
24
- return Array.isArray(excludedRoutes)
18
+ const versionPath = this.extractVersionPathFrom(version);
19
+ if (this.isAWildcard(path)) {
20
+ return Array.isArray(this.excludedGlobalPrefixRoutes)
25
21
  ? [
26
- prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path),
27
- ...excludedRoutes.map(route => versionPath + (0, shared_utils_1.addLeadingSlash)(route.path)),
22
+ this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path),
23
+ ...this.excludedGlobalPrefixRoutes.map(route => versionPath + (0, shared_utils_1.addLeadingSlash)(route.path)),
28
24
  ]
29
- : [prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
25
+ : [this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
26
+ }
27
+ return [this.extractNonWildcardPathFrom({ path, method, version })];
28
+ }
29
+ extractPathFrom(route) {
30
+ if (this.isAWildcard(route.path) && !route.version) {
31
+ return (0, shared_utils_1.addLeadingSlash)(route.path);
30
32
  }
31
- if (Array.isArray(excludedRoutes) &&
32
- (0, utils_1.isRouteExcluded)(excludedRoutes, path, method)) {
33
- return [versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
33
+ return this.extractNonWildcardPathFrom(route);
34
+ }
35
+ isAWildcard(path) {
36
+ return ['*', '/*', '/*/', '(.*)', '/(.*)'].includes(path);
37
+ }
38
+ extractNonWildcardPathFrom({ path, method, version, }) {
39
+ const versionPath = this.extractVersionPathFrom(version);
40
+ if (Array.isArray(this.excludedGlobalPrefixRoutes) &&
41
+ (0, utils_1.isRouteExcluded)(this.excludedGlobalPrefixRoutes, path, method)) {
42
+ return versionPath + (0, shared_utils_1.addLeadingSlash)(path);
34
43
  }
35
- return [prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
44
+ return this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path);
45
+ }
46
+ extractVersionPathFrom(version) {
47
+ var _a;
48
+ if (!version || ((_a = this.versioningConfig) === null || _a === void 0 ? void 0 : _a.type) !== common_1.VersioningType.URI)
49
+ return '';
50
+ const versionPrefix = this.routePathFactory.getVersionPrefix(this.versioningConfig);
51
+ return (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString());
36
52
  }
37
53
  }
38
54
  exports.RouteInfoPathExtractor = RouteInfoPathExtractor;
@@ -4,5 +4,5 @@ export declare const mapToExcludeRoute: (routes: (string | RouteInfo)[]) => Excl
4
4
  export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], routes: RouteInfo[], httpAdapter: HttpServer) => Type<any>[];
5
5
  export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer) => Type<any>;
6
6
  export declare function isMiddlewareClass(middleware: any): middleware is Type<any>;
7
- export declare function assignToken(metatype: Type<any>, token?: any): Type<any>;
7
+ export declare function assignToken(metatype: Type<any>, token?: string): Type<any>;
8
8
  export declare function isMiddlewareRouteExcluded(req: Record<string, any>, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer): boolean;
@@ -5,7 +5,7 @@ const common_1 = require("@nestjs/common");
5
5
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
6
  const iterare_1 = require("iterare");
7
7
  const pathToRegexp = require("path-to-regexp");
8
- const uuid_1 = require("uuid");
8
+ const uid_1 = require("uid");
9
9
  const utils_1 = require("../router/utils");
10
10
  const mapToExcludeRoute = (routes) => {
11
11
  return routes.map(route => {
@@ -76,7 +76,7 @@ function isMiddlewareClass(middleware) {
76
76
  (0, shared_utils_1.isFunction)((_b = middleware.prototype) === null || _b === void 0 ? void 0 : _b.use));
77
77
  }
78
78
  exports.isMiddlewareClass = isMiddlewareClass;
79
- function assignToken(metatype, token = (0, uuid_1.v4)()) {
79
+ function assignToken(metatype, token = (0, uid_1.uid)(21)) {
80
80
  Object.defineProperty(metatype, 'name', { value: token });
81
81
  return metatype;
82
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "9.3.2",
3
+ "version": "9.3.3",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -27,16 +27,15 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
+ "@node-rs/xxhash": "^1.3.0",
30
31
  "@nuxtjs/opencollective": "0.3.2",
31
32
  "fast-safe-stringify": "2.1.1",
32
33
  "iterare": "1.2.1",
33
- "object-hash": "3.0.0",
34
34
  "path-to-regexp": "3.2.0",
35
- "tslib": "2.5.0",
36
- "uuid": "9.0.0"
35
+ "tslib": "2.5.0"
37
36
  },
38
37
  "devDependencies": {
39
- "@nestjs/common": "9.3.2"
38
+ "@nestjs/common": "9.3.3"
40
39
  },
41
40
  "peerDependencies": {
42
41
  "@nestjs/common": "^9.0.0",
@@ -18,7 +18,7 @@ class MethodsReplFn extends repl_function_1.ReplFunction {
18
18
  const proto = typeof token !== 'function'
19
19
  ? Object.getPrototypeOf(this.ctx.app.get(token))
20
20
  : token === null || token === void 0 ? void 0 : token.prototype;
21
- const methods = new Set(this.metadataScanner.getAllFilteredMethodNames(proto));
21
+ const methods = this.metadataScanner.getAllMethodNames(proto);
22
22
  this.ctx.writeToStdout('\n');
23
23
  this.ctx.writeToStdout(`${cli_colors_util_1.clc.green('Methods')}:\n`);
24
24
  methods.forEach(methodName => this.ctx.writeToStdout(` ${cli_colors_util_1.clc.yellow('◻')} ${methodName}\n`));
@@ -14,5 +14,5 @@ export declare class PathsExplorer {
14
14
  private readonly metadataScanner;
15
15
  constructor(metadataScanner: MetadataScanner);
16
16
  scanForPaths(instance: Controller, prototype?: object): RouteDefinition[];
17
- exploreMethodMetadata(instance: Controller, prototype: object, methodName: string): RouteDefinition;
17
+ exploreMethodMetadata(instance: Controller, prototype: object, methodName: string): RouteDefinition | null;
18
18
  }
@@ -11,7 +11,15 @@ class PathsExplorer {
11
11
  const instancePrototype = (0, shared_utils_1.isUndefined)(prototype)
12
12
  ? Object.getPrototypeOf(instance)
13
13
  : prototype;
14
- return this.metadataScanner.scanFromPrototype(instance, instancePrototype, method => this.exploreMethodMetadata(instance, instancePrototype, method));
14
+ return this.metadataScanner
15
+ .getAllMethodNames(instancePrototype)
16
+ .reduce((acc, method) => {
17
+ const route = this.exploreMethodMetadata(instance, instancePrototype, method);
18
+ if (route) {
19
+ acc.push(route);
20
+ }
21
+ return acc;
22
+ }, []);
15
23
  }
16
24
  exploreMethodMetadata(instance, prototype, methodName) {
17
25
  const instanceCallback = instance[methodName];
package/scanner.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare class DependenciesScanner {
28
28
  reflectKeyMetadata(component: Type<Injectable>, key: string, methodKey: string): {
29
29
  methodKey: string;
30
30
  metadata: any;
31
- };
31
+ } | undefined;
32
32
  calculateModulesDistance(): void;
33
33
  insertImport(related: any, token: string, context: string): Promise<void>;
34
34
  isCustomProvider(provider: Provider): provider is ClassProvider | ValueProvider | FactoryProvider | ExistingProvider;
package/scanner.js CHANGED
@@ -133,19 +133,27 @@ class DependenciesScanner {
133
133
  }
134
134
  reflectInjectables(component, token, metadataKey) {
135
135
  const controllerInjectables = this.reflectMetadata(metadataKey, component);
136
- const methodInjectables = this.metadataScanner.scanFromPrototype(null, component.prototype, this.reflectKeyMetadata.bind(this, component, metadataKey));
136
+ const methodInjectables = this.metadataScanner
137
+ .getAllMethodNames(component.prototype)
138
+ .reduce((acc, method) => {
139
+ const methodInjectable = this.reflectKeyMetadata(component, metadataKey, method);
140
+ if (methodInjectable) {
141
+ acc.push(methodInjectable);
142
+ }
143
+ return acc;
144
+ }, []);
137
145
  controllerInjectables.forEach(injectable => this.insertInjectable(injectable, token, component, constants_1.ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey]));
138
- methodInjectables.forEach(({ methodKey, metadata }) => metadata.forEach(injectable => this.insertInjectable(injectable, token, component, constants_1.ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey], methodKey)));
146
+ methodInjectables.forEach(methodInjectable => {
147
+ methodInjectable.metadata.forEach(injectable => this.insertInjectable(injectable, token, component, constants_1.ENHANCER_KEY_TO_SUBTYPE_MAP[metadataKey], methodInjectable.methodKey));
148
+ });
139
149
  }
140
150
  reflectParamInjectables(component, token, metadataKey) {
141
- const paramsMetadata = this.metadataScanner.scanFromPrototype(null, component.prototype, methodKey => {
151
+ const paramsMethods = this.metadataScanner.getAllMethodNames(component.prototype);
152
+ paramsMethods.forEach(methodKey => {
142
153
  const metadata = Reflect.getMetadata(metadataKey, component, methodKey);
143
154
  if (!metadata) {
144
155
  return;
145
156
  }
146
- return { methodKey, metadata };
147
- });
148
- paramsMetadata.forEach(({ methodKey, metadata }) => {
149
157
  const params = Object.values(metadata);
150
158
  params
151
159
  .map(item => item.pipes)