@@ -58,7 +58,7 @@ export class MetadataStorage {
5858
5959 authorizedFields : AuthorizedMetadata [ ] = [ ] ;
6060
61- authorizedFieldsByTargetAndFieldCache = new Map < string , AuthorizedMetadata > ( ) ;
61+ authorizedFieldsByTargetAndFieldCache = new Map < Function , Map < string , AuthorizedMetadata > > ( ) ;
6262
6363 authorizedResolver : AuthorizedClassMetadata [ ] = [ ] ;
6464
@@ -70,7 +70,7 @@ export class MetadataStorage {
7070
7171 middlewares : MiddlewareMetadata [ ] = [ ] ;
7272
73- middlewaresByTargetAndFieldCache = new Map < string , Set < MiddlewareMetadata > > ( ) ;
73+ middlewaresByTargetAndFieldCache = new Map < Function , Map < string , Set < MiddlewareMetadata > > > ( ) ;
7474
7575 resolverMiddlewares : ResolverMiddlewareMetadata [ ] = [ ] ;
7676
@@ -82,7 +82,7 @@ export class MetadataStorage {
8282
8383 fieldDirectives : DirectiveFieldMetadata [ ] = [ ] ;
8484
85- fieldDirectivesByTargetAndFieldCache = new Map < string , DirectiveFieldMetadata [ ] > ( ) ;
85+ fieldDirectivesByTargetAndFieldCache = new Map < Function , Map < string , DirectiveFieldMetadata [ ] > > ( ) ;
8686
8787 argumentDirectives : DirectiveArgumentMetadata [ ] = [ ] ;
8888
@@ -100,7 +100,7 @@ export class MetadataStorage {
100100
101101 params : ParamMetadata [ ] = [ ] ;
102102
103- paramsCache = new Map < string , ParamMetadata [ ] > ( ) ;
103+ paramsCache = new Map < Function , Map < string , ParamMetadata [ ] > > ( ) ;
104104
105105 collectQueryHandlerMetadata ( definition : ResolverMetadata ) {
106106 this . queries . push ( definition ) ;
@@ -206,23 +206,40 @@ export class MetadataStorage {
206206
207207 if ( this . params ?. length ) {
208208 this . params . forEach ( param => {
209- const key = `${ param . target } #${ param . methodName } ` ;
210- if ( ! this . paramsCache . has ( key ) ) {
211- this . paramsCache . set ( key , [ ] ) ;
209+ if ( ! this . paramsCache . has ( param . target ) ) {
210+ this . paramsCache . set ( param . target , new Map ( ) ) ;
212211 }
213- this . paramsCache . get ( key ) ! . push ( param ) ;
212+ if ( ! this . paramsCache . get ( param . target ) ! . has ( param . methodName ) ) {
213+ this . paramsCache . get ( param . target ) ! . set ( param . methodName , [ ] ) ;
214+ }
215+ this . paramsCache . get ( param . target ) ! . get ( param . methodName ) ! . push ( param ) ;
214216 } ) ;
215217 }
216218
217219 if ( this . middlewares ?. length ) {
218220 this . middlewares . forEach ( middleware => {
219- const key = `${ middleware . target } #${ middleware . fieldName } ` ;
220- if ( ! this . middlewaresByTargetAndFieldCache . has ( key ) ) {
221- this . middlewaresByTargetAndFieldCache . set ( key , new Set ( ) ) ;
221+ if ( ! this . middlewaresByTargetAndFieldCache . has ( middleware . target ) ) {
222+ this . middlewaresByTargetAndFieldCache . set ( middleware . target , new Map ( ) ) ;
223+ }
224+
225+ if (
226+ ! this . middlewaresByTargetAndFieldCache . get ( middleware . target ) ! . has ( middleware . fieldName )
227+ ) {
228+ this . middlewaresByTargetAndFieldCache
229+ . get ( middleware . target ) !
230+ . set ( middleware . fieldName , new Set ( ) ) ;
222231 }
223232
224- if ( ! this . middlewaresByTargetAndFieldCache . get ( key ) ! . has ( middleware ) ) {
225- this . middlewaresByTargetAndFieldCache . get ( key ) ! . add ( middleware ) ;
233+ if (
234+ ! this . middlewaresByTargetAndFieldCache
235+ . get ( middleware . target ) !
236+ . get ( middleware . fieldName ) !
237+ . has ( middleware )
238+ ) {
239+ this . middlewaresByTargetAndFieldCache
240+ . get ( middleware . target ) !
241+ . get ( middleware . fieldName ) !
242+ . add ( middleware ) ;
226243 }
227244 } ) ;
228245 }
@@ -242,11 +259,20 @@ export class MetadataStorage {
242259
243260 if ( this . fieldDirectives ?. length ) {
244261 this . fieldDirectives . forEach ( directive => {
245- const key = `${ directive . target } #${ directive . fieldName } ` ;
246- if ( ! this . fieldDirectivesByTargetAndFieldCache . has ( key ) ) {
247- this . fieldDirectivesByTargetAndFieldCache . set ( key , [ ] ) ;
262+ if ( ! this . fieldDirectivesByTargetAndFieldCache . has ( directive . target ) ) {
263+ this . fieldDirectivesByTargetAndFieldCache . set ( directive . target , new Map ( ) ) ;
248264 }
249- this . fieldDirectivesByTargetAndFieldCache . get ( key ) ! . push ( directive ) ;
265+ if (
266+ ! this . fieldDirectivesByTargetAndFieldCache . get ( directive . target ) ! . has ( directive . fieldName )
267+ ) {
268+ this . fieldDirectivesByTargetAndFieldCache
269+ . get ( directive . target ) !
270+ . set ( directive . fieldName , [ ] ) ;
271+ }
272+ this . fieldDirectivesByTargetAndFieldCache
273+ . get ( directive . target ) !
274+ . get ( directive . fieldName ) !
275+ . push ( directive ) ;
250276 } ) ;
251277 }
252278
@@ -262,9 +288,11 @@ export class MetadataStorage {
262288
263289 if ( this . authorizedFields ?. length ) {
264290 this . authorizedFields . forEach ( field => {
265- const key = `${ field . target } #${ field . fieldName } ` ;
266- if ( ! this . authorizedFieldsByTargetAndFieldCache . has ( key ) ) {
267- this . authorizedFieldsByTargetAndFieldCache . set ( key , field ) ;
291+ if ( ! this . authorizedFieldsByTargetAndFieldCache . has ( field . target ) ) {
292+ this . authorizedFieldsByTargetAndFieldCache . set ( field . target , new Map ( ) ) ;
293+ }
294+ if ( ! this . authorizedFieldsByTargetAndFieldCache . get ( field . target ) ! . has ( field . fieldName ) ) {
295+ this . authorizedFieldsByTargetAndFieldCache . get ( field . target ) ! . set ( field . fieldName , field ) ;
268296 }
269297 } ) ;
270298 }
@@ -368,17 +396,17 @@ export class MetadataStorage {
368396 const fields = this . fieldsCache . get ( def . target ) || [ ] ;
369397 fields . forEach ( field => {
370398 field . roles = this . findFieldRoles ( field . target , field . name ) ;
371- field . params = this . paramsCache . get ( ` ${ field . target } # ${ field . name } ` ) || [ ] ;
399+ field . params = this . paramsCache . get ( field . target ) ?. get ( field . name ) || [ ] ;
372400 field . middlewares = [
373401 ...mapMiddlewareMetadataToArray ( [
374402 ...( this . resolverMiddlewaresByTargetCache . get ( field . target ) || [ ] ) ,
375403 ] ) ,
376404 ...mapMiddlewareMetadataToArray ( [
377- ...( this . middlewaresByTargetAndFieldCache . get ( ` ${ field . target } # ${ field . name } ` ) || [ ] ) ,
405+ ...( this . middlewaresByTargetAndFieldCache . get ( field . target ) ?. get ( field . name ) || [ ] ) ,
378406 ] ) ,
379407 ] ;
380408 field . directives = (
381- this . fieldDirectivesByTargetAndFieldCache . get ( ` ${ field . target } # ${ field . name } ` ) || [ ]
409+ this . fieldDirectivesByTargetAndFieldCache . get ( field . target ) ?. get ( field . name ) || [ ]
382410 ) . map ( it => it . directive ) ;
383411 field . extensions = this . findExtensions ( field . target , field . name ) ;
384412 } ) ;
@@ -398,19 +426,19 @@ export class MetadataStorage {
398426 private buildResolversMetadata ( definitions : BaseResolverMetadata [ ] ) {
399427 definitions . forEach ( def => {
400428 def . resolverClassMetadata = this . resolverClassesCache . get ( def . target ) ;
401- def . params = this . paramsCache . get ( ` ${ def . target } # ${ def . methodName } ` ) || [ ] ;
429+ def . params = this . paramsCache . get ( def . target ) ?. get ( def . methodName ) || [ ] ;
402430 def . roles = this . findFieldRoles ( def . target , def . methodName ) ;
403431 def . middlewares = [
404432 ...mapMiddlewareMetadataToArray ( [
405433 ...( this . resolverMiddlewaresByTargetCache . get ( def . target ) || [ ] ) ,
406434 ] ) ,
407435 ...mapMiddlewareMetadataToArray ( [
408- ...( this . middlewaresByTargetAndFieldCache . get ( ` ${ def . target } # ${ def . methodName } ` ) || [ ] ) ,
436+ ...( this . middlewaresByTargetAndFieldCache . get ( def . target ) ?. get ( def . methodName ) || [ ] ) ,
409437 ] ) ,
410438 ] ;
411439
412440 def . directives = (
413- this . fieldDirectivesByTargetAndFieldCache . get ( ` ${ def . target } # ${ def . methodName } ` ) || [ ]
441+ this . fieldDirectivesByTargetAndFieldCache . get ( def . target ) ?. get ( def . methodName ) || [ ]
414442 ) . map ( it => it . directive ) ;
415443 def . extensions = this . findExtensions ( def . target , def . methodName ) ;
416444 } ) ;
@@ -424,7 +452,7 @@ export class MetadataStorage {
424452 definitions . forEach ( def => {
425453 def . roles = this . findFieldRoles ( def . target , def . methodName ) ;
426454 def . directives = (
427- this . fieldDirectivesByTargetAndFieldCache . get ( ` ${ def . target } # ${ def . methodName } ` ) || [ ]
455+ this . fieldDirectivesByTargetAndFieldCache . get ( def . target ) ?. get ( def . methodName ) || [ ]
428456 ) . map ( it => it . directive ) ;
429457 def . extensions = this . findExtensions ( def . target , def . methodName ) ;
430458 def . getObjectType =
@@ -513,7 +541,7 @@ export class MetadataStorage {
513541
514542 private findFieldRoles ( target : Function , fieldName : string ) : any [ ] | undefined {
515543 const authorizedField =
516- this . authorizedFieldsByTargetAndFieldCache . get ( ` ${ target } # ${ fieldName } ` ) ||
544+ this . authorizedFieldsByTargetAndFieldCache . get ( target ) ?. get ( fieldName ) ||
517545 this . authorizedResolverByTargetCache . get ( target ) ;
518546 if ( ! authorizedField ) {
519547 return undefined ;
0 commit comments