• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nestjs / nest / de00f050-29aa-4a07-94cd-4a5c3beeb9b5

05 Dec 2023 08:46AM UTC coverage: 92.992% (+0.7%) from 92.258%
de00f050-29aa-4a07-94cd-4a5c3beeb9b5

Pull #12880

circleci

이정현B
feat(core): add option to bind global
Pull Request #12880: fix(core): always bind global modules when scan for modules

2798 of 3460 branches covered (0.0%)

7 of 8 new or added lines in 1 file covered. (87.5%)

199 existing lines in 30 files now uncovered.

6555 of 7049 relevant lines covered (92.99%)

17.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/packages/core/services/reflector.service.ts
1
import { Type } from '@nestjs/common';
2
import { isEmpty, isObject } from '@nestjs/common/utils/shared.utils';
1✔
3

4
/**
5
 * Helper class providing Nest reflection capabilities.
6
 *
7
 * @see [Reflection](https://docs.nestjs.com/guards#putting-it-all-together)
8
 *
9
 * @publicApi
10
 */
11
export class Reflector {
1✔
12
  /**
13
   * Retrieve metadata for a specified key for a specified target.
14
   *
15
   * @example
16
   * `const roles = this.reflector.get<string[]>('roles', context.getHandler());`
17
   *
18
   * @param metadataKey lookup key for metadata to retrieve
19
   * @param target context (decorated object) to retrieve metadata from
20
   *
21
   */
22
  public get<TResult = any, TKey = any>(
23
    metadataKey: TKey,
24
    target: Type<any> | Function,
25
  ): TResult {
26
    return Reflect.getMetadata(metadataKey, target);
9✔
27
  }
28

29
  /**
30
   * Retrieve metadata for a specified key for a specified set of targets.
31
   *
32
   * @param metadataKey lookup key for metadata to retrieve
33
   * @param targets context (decorated objects) to retrieve metadata from
34
   *
35
   */
36
  public getAll<TResult extends any[] = any[], TKey = any>(
37
    metadataKey: TKey,
38
    targets: (Type<any> | Function)[],
39
  ): TResult {
40
    return (targets || []).map(target =>
5!
41
      this.get(metadataKey, target),
7✔
42
    ) as TResult;
43
  }
44

45
  /**
46
   * Retrieve metadata for a specified key for a specified set of targets and merge results.
47
   *
48
   * @param metadataKey lookup key for metadata to retrieve
49
   * @param targets context (decorated objects) to retrieve metadata from
50
   *
51
   */
52
  public getAllAndMerge<TResult extends any[] = any[], TKey = any>(
53
    metadataKey: TKey,
54
    targets: (Type<any> | Function)[],
55
  ): TResult {
56
    const metadataCollection = this.getAll<TResult, TKey>(
4✔
57
      metadataKey,
58
      targets,
59
    ).filter(item => item !== undefined);
6✔
60

61
    if (isEmpty(metadataCollection)) {
4✔
62
      return metadataCollection as TResult;
1✔
63
    }
64
    return metadataCollection.reduce((a, b) => {
3✔
65
      if (Array.isArray(a)) {
3✔
66
        return a.concat(b);
1✔
67
      }
68
      if (isObject(a) && isObject(b)) {
2✔
69
        return {
1✔
70
          ...a,
71
          ...b,
72
        };
73
      }
74
      return [a, b];
1✔
75
    });
76
  }
77

78
  /**
79
   * Retrieve metadata for a specified key for a specified set of targets and return a first not undefined value.
80
   *
81
   * @param metadataKey lookup key for metadata to retrieve
82
   * @param targets context (decorated objects) to retrieve metadata from
83
   *
84
   */
85
  public getAllAndOverride<TResult = any, TKey = any>(
86
    metadataKey: TKey,
87
    targets: (Type<any> | Function)[],
88
  ): TResult {
89
    for (const target of targets) {
1✔
90
      const result = this.get(metadataKey, target);
1✔
91
      if (result !== undefined) {
1!
92
        return result;
1✔
93
      }
94
    }
UNCOV
95
    return undefined;
×
96
  }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc