@nestjs/core
Version:
The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.
162 lines (161 loc) • 7.04 kB
TypeScript
import type { FactoryProvider, InjectionToken } from '@nestjs/common';
import { type Provider, Scope, type Type } from '@nestjs/common';
import { type EnhancerSubtype } from '@nestjs/common/internal';
import { Module } from './module.js';
import { SettlementSignal } from './settlement-signal.js';
export declare const INSTANCE_METADATA_SYMBOL: unique symbol;
export declare const INSTANCE_ID_SYMBOL: unique symbol;
export interface HostComponentInfo {
/**
* Injection token (or class reference)
*/
token: InjectionToken;
/**
* Flag that indicates whether DI subtree is durable
*/
isTreeDurable: boolean;
}
export interface ContextId {
readonly id: number;
payload?: unknown;
getParent?(info: HostComponentInfo): ContextId;
}
export interface InstancePerContext<T> {
instance: T;
isResolved?: boolean;
isPending?: boolean;
donePromise?: Promise<unknown>;
/**
* The signal of the load for this context. The wrapper's `settlementSignal`
* is the one of its latest load, which may belong to a concurrent request.
*/
settlementSignal?: SettlementSignal;
isConstructorCalled?: boolean;
}
export interface PropertyMetadata {
key: symbol | string;
wrapper: InstanceWrapper;
}
export declare class InstanceWrapper<T = any> {
readonly name: any;
readonly token: InjectionToken;
readonly async?: boolean;
readonly host?: Module;
isAlias: boolean;
readonly subtype?: EnhancerSubtype;
scope?: Scope;
metatype: Type<T> | Function | null;
inject?: FactoryProvider['inject'] | null;
forwardRef?: boolean;
durable?: boolean;
initTime?: number;
settlementSignal?: SettlementSignal;
private static logger;
private readonly values;
private readonly [INSTANCE_METADATA_SYMBOL];
private readonly [INSTANCE_ID_SYMBOL];
private transientMap?;
private isTreeStatic;
private isTreeDurable;
/**
* Whether either flag was computed since the last reset. Unlike the flags,
* it is not cleared by `invalidateDependencyTreeParents`, so a wrapper whose
* flag was only invalidated still passes a reset on to its parents.
*/
private isTreeIntrospected;
private _isDetached;
private _hierarchyLevel;
get hierarchyLevel(): number;
set hierarchyLevel(level: number);
/**
* The root inquirer reference. Present only if child instance wrapper
* is transient and has a parent inquirer.
*/
private rootInquirer;
constructor(metadata?: Partial<InstanceWrapper<T>> & Partial<InstancePerContext<T>> & {
[INSTANCE_ID_SYMBOL]?: string;
});
get id(): string;
set instance(value: T);
get instance(): T;
get isNotMetatype(): boolean;
get isFactory(): boolean;
get isTransient(): boolean;
getInstanceByContextId(contextId: ContextId, inquirerId?: string): InstancePerContext<T>;
getInstanceByInquirerId(contextId: ContextId, inquirerId: string): InstancePerContext<T>;
setInstanceByContextId(contextId: ContextId, value: InstancePerContext<T>, inquirerId?: string): void;
setInstanceByInquirerId(contextId: ContextId, inquirerId: string, value: InstancePerContext<T>): void;
removeInstanceByContextId(contextId: ContextId, inquirerId?: string): void;
removeInstanceByInquirerId(contextId: ContextId, inquirerId: string): void;
/**
* Returns the instances that exist for the given context, including those
* of every inquirer of a transient provider. Unlike `getInstanceByContextId`,
* it does not create one.
*/
getExistingInstancesByContextId(contextId: ContextId): InstancePerContext<T>[];
addCtorMetadata(index: number, wrapper: InstanceWrapper): void;
getCtorMetadata(): InstanceWrapper[];
addPropertiesMetadata(key: symbol | string, wrapper: InstanceWrapper): void;
getPropertiesMetadata(): PropertyMetadata[];
addEnhancerMetadata(wrapper: InstanceWrapper): void;
getEnhancersMetadata(): InstanceWrapper[];
isDependencyTreeDurable(lookupRegistry?: string[]): boolean;
introspectDepsAttribute(callback: (collection: InstanceWrapper[], lookupRegistry: string[]) => boolean, lookupRegistry?: string[]): boolean;
isDependencyTreeStatic(lookupRegistry?: string[]): boolean;
cloneStaticInstance(contextId: ContextId): InstancePerContext<T>;
cloneTransientInstance(contextId: ContextId, inquirerId: string): InstancePerContext<T>;
createPrototype(contextId: ContextId): any;
isInRequestScope(contextId: ContextId, inquirer?: InstanceWrapper): boolean;
isLazyTransient(contextId: ContextId, inquirer: InstanceWrapper | undefined): boolean;
isExplicitlyRequested(contextId: ContextId, inquirer?: InstanceWrapper): boolean;
isStatic(contextId: ContextId, inquirer: InstanceWrapper | undefined, rootInquirer?: InstanceWrapper): boolean;
/**
* Whether `detachFromDependencies` was called, i.e., the wrapper is no
* longer in use (e.g., its module was removed from the container, or it
* served a single `ModuleRef#create()` call).
*/
get isDetached(): boolean;
/**
* Makes the dependencies of this wrapper (constructor, property and
* enhancer ones) forget it: that it depends on them, and the transient
* instances they hold for it. The wrapper stays detached, so that a load of
* it that is still running does not register it as a dependent again.
*/
detachFromDependencies(): void;
/**
* Returns the wrappers that depend on this one, directly or through other
* wrappers (as a constructor, property or enhancer dependency).
*/
getDependents(): Set<InstanceWrapper>;
/**
* @deprecated The injector no longer reads the root inquirer from the
* wrapper (see `isStatic`), as it may be overwritten by a concurrent
* resolution for another consumer.
*/
attachRootInquirer(inquirer: InstanceWrapper): void;
/**
* @deprecated The injector no longer reads the root inquirer from the
* wrapper (see `isStatic`), as it may be overwritten by a concurrent
* resolution for another consumer.
*/
getRootInquirer(): InstanceWrapper | undefined;
getStaticTransientInstances(): (InstancePerContext<T> | undefined)[];
mergeWith(provider: Provider): void;
private resetStaticInstance;
private isNewable;
private registerDependencyTreeParent;
private getDependencyWrappers;
private removeTransientInstancesOf;
private resetDependencyTreeState;
/**
* In a circular dependency, the introspection skips a wrapper that is
* already being introspected, so the parents in between may cache `true`
* before that wrapper turns out not to be static (or durable). Clears what
* they cached, so it is computed again with the final answer.
*/
private invalidateDependencyTreeParents;
private initialize;
private printIntrospectedAsRequestScoped;
private printIntrospectedAsDurable;
private generateUuid;
}