1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.MetadataScanner = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | class MetadataScanner {
|
6 | constructor() {
|
7 | this.cachedScannedPrototypes = new Map();
|
8 | }
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 | scanFromPrototype(instance, prototype, callback) {
|
15 | if (!prototype) {
|
16 | return [];
|
17 | }
|
18 | const visitedNames = new Map();
|
19 | const result = [];
|
20 | do {
|
21 | for (const property of Object.getOwnPropertyNames(prototype)) {
|
22 | if (visitedNames.has(property)) {
|
23 | continue;
|
24 | }
|
25 | visitedNames.set(property, true);
|
26 |
|
27 | const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
|
28 | if (descriptor.set ||
|
29 | descriptor.get ||
|
30 | (0, shared_utils_1.isConstructor)(property) ||
|
31 | !(0, shared_utils_1.isFunction)(prototype[property])) {
|
32 | continue;
|
33 | }
|
34 | const value = callback(property);
|
35 | if ((0, shared_utils_1.isNil)(value)) {
|
36 | continue;
|
37 | }
|
38 | result.push(value);
|
39 | }
|
40 | } while ((prototype = Reflect.getPrototypeOf(prototype)) &&
|
41 | prototype !== Object.prototype);
|
42 | return result;
|
43 | }
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 | *getAllFilteredMethodNames(prototype) {
|
50 | yield* this.getAllMethodNames(prototype);
|
51 | }
|
52 | getAllMethodNames(prototype) {
|
53 | if (!prototype) {
|
54 | return [];
|
55 | }
|
56 | if (this.cachedScannedPrototypes.has(prototype)) {
|
57 | return this.cachedScannedPrototypes.get(prototype);
|
58 | }
|
59 | const visitedNames = new Map();
|
60 | const result = [];
|
61 | this.cachedScannedPrototypes.set(prototype, result);
|
62 | do {
|
63 | for (const property of Object.getOwnPropertyNames(prototype)) {
|
64 | if (visitedNames.has(property)) {
|
65 | continue;
|
66 | }
|
67 | visitedNames.set(property, true);
|
68 |
|
69 | const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
|
70 | if (descriptor.set ||
|
71 | descriptor.get ||
|
72 | (0, shared_utils_1.isConstructor)(property) ||
|
73 | !(0, shared_utils_1.isFunction)(prototype[property])) {
|
74 | continue;
|
75 | }
|
76 | result.push(property);
|
77 | }
|
78 | } while ((prototype = Reflect.getPrototypeOf(prototype)) &&
|
79 | prototype !== Object.prototype);
|
80 | return result;
|
81 | }
|
82 | }
|
83 | exports.MetadataScanner = MetadataScanner;
|