UNPKG

3 kBTypeScriptView Raw
1import { CustomDecorator } from '@nestjs/common';
2import { InstanceWrapper } from '../injector/instance-wrapper';
3import { Module } from '../injector/module';
4import { ModulesContainer } from '../injector/modules-container';
5/**
6 * @publicApi
7 */
8export interface FilterByInclude {
9 /**
10 * List of modules to include (whitelist) into the discovery process.
11 */
12 include?: Function[];
13}
14/**
15 * @publicApi
16 */
17export interface FilterByMetadataKey {
18 /**
19 * A key to filter controllers and providers by.
20 * Only instance wrappers with the specified metadata key will be returned.
21 */
22 metadataKey?: string;
23}
24/**
25 * @publicApi
26 */
27export type DiscoveryOptions = FilterByInclude | FilterByMetadataKey;
28/**
29 * @publicApi
30 */
31export type DiscoverableDecorator<T> = ((opts?: T) => CustomDecorator) & {
32 KEY: string;
33};
34/**
35 * @publicApi
36 */
37export declare class DiscoveryService {
38 private readonly modulesContainer;
39 constructor(modulesContainer: ModulesContainer);
40 /**
41 * Creates a decorator that can be used to decorate classes and methods with metadata.
42 * The decorator will also add the class to the collection of discoverable classes (by metadata key).
43 * Decorated classes can be discovered using the `getProviders` and `getControllers` methods.
44 * @returns A decorator function.
45 */
46 static createDecorator<T>(): DiscoverableDecorator<T>;
47 /**
48 * Returns an array of instance wrappers (providers).
49 * Depending on the options, the array will contain either all providers or only providers with the specified metadata key.
50 * @param options Discovery options.
51 * @param modules A list of modules to filter by.
52 * @returns An array of instance wrappers (providers).
53 */
54 getProviders(options?: DiscoveryOptions, modules?: Module[]): InstanceWrapper[];
55 /**
56 * Returns an array of instance wrappers (controllers).
57 * Depending on the options, the array will contain either all controllers or only controllers with the specified metadata key.
58 * @param options Discovery options.
59 * @param modules A list of modules to filter by.
60 * @returns An array of instance wrappers (controllers).
61 */
62 getControllers(options?: DiscoveryOptions, modules?: Module[]): InstanceWrapper[];
63 /**
64 * Retrieves metadata from the specified instance wrapper.
65 * @param decorator The decorator to retrieve metadata of.
66 * @param instanceWrapper Reference to the instance wrapper.
67 * @param methodKey An optional method key to retrieve metadata from.
68 * @returns Discovered metadata.
69 */
70 getMetadataByDecorator<T extends DiscoverableDecorator<any>>(decorator: T, instanceWrapper: InstanceWrapper, methodKey?: string): T extends DiscoverableDecorator<infer R> ? R | undefined : T | undefined;
71 /**
72 * Returns a list of modules to be used for discovery.
73 */
74 protected getModules(options?: DiscoveryOptions): Module[];
75 private includeWhitelisted;
76}
77
\No newline at end of file