forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata-scanner.ts
More file actions
27 lines (26 loc) · 779 Bytes
/
Copy pathmetadata-scanner.ts
File metadata and controls
27 lines (26 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import iterate from 'iterare';
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
import {
isConstructor,
isFunction,
isNil,
} from '@nestjs/common/utils/shared.utils';
export class MetadataScanner {
public scanFromPrototype<T extends Injectable, R>(
instance: T,
prototype,
callback: (name: string) => R,
): R[] {
return iterate(Object.getOwnPropertyNames(prototype))
.filter(method => {
const descriptor = Object.getOwnPropertyDescriptor(prototype, method);
if (descriptor.set || descriptor.get) {
return false;
}
return !isConstructor(method) && isFunction(prototype[method]);
})
.map(callback)
.filter(metadata => !isNil(metadata))
.toArray();
}
}