UNPKG

4.89 kBTypeScriptView Raw
1import { IntrospectionResult, Type } from '@nestjs/common';
2import { AbstractInstanceResolver } from './abstract-instance-resolver';
3import { NestContainer } from './container';
4import { Injector } from './injector';
5import { InstanceLinksHost } from './instance-links-host';
6import { ContextId } from './instance-wrapper';
7import { Module } from './module';
8export interface ModuleRefGetOrResolveOpts {
9 /**
10 * If enabled, lookup will only be performed in the host module.
11 * @default true
12 */
13 strict?: boolean;
14 /**
15 * If enabled, instead of returning a first instance registered under a given token,
16 * a list of instances will be returned.
17 * @default false
18 */
19 each?: boolean;
20}
21export declare abstract class ModuleRef extends AbstractInstanceResolver {
22 protected readonly container: NestContainer;
23 protected readonly injector: Injector;
24 private _instanceLinksHost;
25 protected get instanceLinksHost(): InstanceLinksHost;
26 constructor(container: NestContainer);
27 /**
28 * Retrieves an instance of either injectable or controller, otherwise, throws exception.
29 * @returns {TResult}
30 */
31 abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
32 /**
33 * Retrieves an instance of either injectable or controller, otherwise, throws exception.
34 * @returns {TResult}
35 */
36 abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
37 /**
38 * If enabled, lookup will only be performed in the host module.
39 * @default true
40 */
41 strict?: boolean;
42 /** This indicates that only the first instance registered will be returned. */
43 each?: undefined | false;
44 }): TResult;
45 /**
46 * Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
47 * @returns {Array<TResult>}
48 */
49 abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
50 /**
51 * If enabled, lookup will only be performed in the host module.
52 * @default true
53 */
54 strict?: boolean;
55 /** This indicates that a list of instances will be returned. */
56 each: true;
57 }): Array<TResult>;
58 /**
59 * Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
60 * @returns {TResult | Array<TResult>}
61 */
62 abstract get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?: ModuleRefGetOrResolveOpts): TResult | Array<TResult>;
63 /**
64 * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
65 * @returns {Array<TResult>}
66 */
67 abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
68 /**
69 * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
70 * @returns {Array<TResult>}
71 */
72 abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
73 id: number;
74 }): Promise<TResult>;
75 /**
76 * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
77 * @returns {Array<TResult>}
78 */
79 abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
80 id: number;
81 }, options?: {
82 strict?: boolean;
83 each?: undefined | false;
84 }): Promise<TResult>;
85 /**
86 * Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
87 * @returns {Array<TResult>}
88 */
89 abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
90 id: number;
91 }, options?: {
92 strict?: boolean;
93 each: true;
94 }): Promise<Array<TResult>>;
95 /**
96 * Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
97 * @returns {Promise<TResult | Array<TResult>>}
98 */
99 abstract resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
100 id: number;
101 }, options?: ModuleRefGetOrResolveOpts): Promise<TResult | Array<TResult>>;
102 abstract create<T = any>(type: Type<T>): Promise<T>;
103 introspect<T = any>(token: Type<T> | string | symbol): IntrospectionResult;
104 registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
105 protected instantiateClass<T = any>(type: Type<T>, moduleRef: Module): Promise<T>;
106}