Skip to content

Commit 035348e

Browse files
fix(core): remove object-hash in handler metadata
1 parent bf244c2 commit 035348e

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/core/helpers/handler-metadata-storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller } from '@nestjs/common/interfaces';
2-
import * as hash from 'object-hash';
2+
import { CONTROLLER_ID_KEY } from '../injector/constants';
33
import { ContextId } from '../injector/instance-wrapper';
44
import { ParamProperties } from './context-utils';
55

@@ -37,7 +37,7 @@ export class HandlerMetadataStorage<TValue = HandlerMetadata, TKey = any> {
3737

3838
private getMetadataKey(controller: Controller, methodName: string): string {
3939
const ctor = controller.constructor;
40-
const controllerKey = ctor && hash(ctor);
40+
const controllerKey = ctor && (ctor[CONTROLLER_ID_KEY] || ctor.name);
4141
return controllerKey + methodName;
4242
}
4343
}

packages/core/injector/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ContextId } from './instance-wrapper';
22

3+
export const CONTROLLER_ID_KEY = 'CONTROLLER_ID';
4+
35
const STATIC_CONTEXT_ID = 1;
46
export const STATIC_CONTEXT: ContextId = Object.freeze({
57
id: STATIC_CONTEXT_ID,

packages/core/injector/module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { InvalidClassException } from '../errors/exceptions/invalid-class.except
2626
import { RuntimeException } from '../errors/exceptions/runtime.exception';
2727
import { UnknownExportException } from '../errors/exceptions/unknown-export.exception';
2828
import { createContextId } from '../helpers';
29+
import { CONTROLLER_ID_KEY } from './constants';
2930
import { NestContainer } from './container';
3031
import { InstanceWrapper } from './instance-wrapper';
3132
import { ModuleRef } from './module-ref';
@@ -410,6 +411,17 @@ export class Module {
410411
host: this,
411412
}),
412413
);
414+
415+
this.assignControllerUniqueId(controller);
416+
}
417+
418+
public assignControllerUniqueId(controller: Type<Controller>) {
419+
Object.defineProperty(controller, CONTROLLER_ID_KEY, {
420+
enumerable: false,
421+
writable: false,
422+
configurable: true,
423+
value: randomStringGenerator(),
424+
});
413425
}
414426

415427
public addRelatedModule(module: Module) {

0 commit comments

Comments
 (0)