///
import { inspect } from 'util';
import { Configuration } from './utils';
import { AssignOptions, EntityFactory, EntityRepository, EntityValidator, IdentifiedReference, Reference } from './entity';
import { UnitOfWork } from './unit-of-work';
import { CountOptions, DeleteOptions, EntityManagerType, FindOneOptions, FindOneOrFailOptions, FindOptions, IDatabaseDriver, UpdateOptions } from './drivers';
import { AnyEntity, Dictionary, EntityData, EntityName, FilterQuery, Loaded, Primary, Populate, New, GetRepository } from './typings';
import { LockMode, QueryOrderMap } from './enums';
import { MetadataStorage } from './metadata';
import { Transaction } from './connections';
import { EventManager } from './events';
import { EntityComparator } from './utils/EntityComparator';
/**
* The EntityManager is the central access point to ORM functionality. It is a facade to all different ORM subsystems
* such as UnitOfWork, Query Language and Repository API.
*/
export declare class EntityManager {
readonly config: Configuration;
private readonly driver;
private readonly metadata;
private readonly useContext;
private readonly eventManager;
private static counter;
readonly id: number;
private readonly validator;
private readonly repositoryMap;
private readonly entityLoader;
private readonly comparator;
private readonly unitOfWork;
private readonly entityFactory;
private filters;
private filterParams;
private transactionContext?;
constructor(config: Configuration, driver: D, metadata: MetadataStorage, useContext?: boolean, eventManager?: EventManager);
/**
* Gets the Driver instance used by this EntityManager
*/
getDriver(): D;
/**
* Gets the Connection instance, by default returns write connection
*/
getConnection(type?: 'read' | 'write'): ReturnType;
/**
* Gets repository for given entity. You can pass either string name or entity class reference.
*/
getRepository, U extends EntityRepository = EntityRepository>(entityName: EntityName): GetRepository;
/**
* Gets EntityValidator instance
*/
getValidator(): EntityValidator;
/**
* Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
*/
find, P extends Populate = any>(entityName: EntityName, where: FilterQuery, options?: FindOptions): Promise[]>;
/**
* Finds all entities matching your `where` query.
*/
find, P extends Populate = any>(entityName: EntityName, where: FilterQuery, populate?: P, orderBy?: QueryOrderMap, limit?: number, offset?: number): Promise[]>;
addFilter>(name: string, cond: FilterQuery | ((args: Dictionary) => FilterQuery), entityName?: EntityName | [EntityName], enabled?: boolean): void;
addFilter, T2 extends AnyEntity>(name: string, cond: FilterQuery | ((args: Dictionary) => FilterQuery), entityName?: [EntityName, EntityName], enabled?: boolean): void;
addFilter, T2 extends AnyEntity, T3 extends AnyEntity>(name: string, cond: FilterQuery | ((args: Dictionary) => FilterQuery), entityName?: [EntityName, EntityName, EntityName], enabled?: boolean): void;
setFilterParams(name: string, args: Dictionary): void;
getFilterParams(name: string): T;
protected applyFilters>(entityName: string, where: FilterQuery, options: Dictionary | string[] | boolean, type: 'read' | 'update' | 'delete'): Promise>;
/**
* Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
* where first element is the array of entities and the second is the count.
*/
findAndCount, P extends Populate = any>(entityName: EntityName, where: FilterQuery, options?: FindOptions): Promise<[Loaded[], number]>;
/**
* Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
* where first element is the array of entities and the second is the count.
*/
findAndCount, P extends Populate = any>(entityName: EntityName, where: FilterQuery, populate?: P, orderBy?: QueryOrderMap, limit?: number, offset?: number): Promise<[Loaded[], number]>;
/**
* Finds first entity matching your `where` query.
*/
findOne, P extends Populate = any>(entityName: EntityName, where: FilterQuery, options?: FindOneOptions): Promise | null>;
/**
* Finds first entity matching your `where` query.
*/
findOne, P extends Populate = any>(entityName: EntityName, where: FilterQuery, populate?: P, orderBy?: QueryOrderMap): Promise | null>;
/**
* Finds first entity matching your `where` query. If nothing found, it will throw an error.
* You can override the factory for creating this method via `options.failHandler` locally
* or via `Configuration.findOneOrFailHandler` globally.
*/
findOneOrFail, P extends Populate = any>(entityName: EntityName, where: FilterQuery, options?: FindOneOrFailOptions): Promise>;
/**
* Finds first entity matching your `where` query. If nothing found, it will throw an error.
* You can override the factory for creating this method via `options.failHandler` locally
* or via `Configuration.findOneOrFailHandler` globally.
*/
findOneOrFail, P extends Populate = any>(entityName: EntityName, where: FilterQuery, populate?: P, orderBy?: QueryOrderMap): Promise>;
/**
* Runs your callback wrapped inside a database transaction.
*/
transactional(cb: (em: D[typeof EntityManagerType]) => Promise, ctx?: any): Promise;
/**
* Starts new transaction bound to this EntityManager. Use `ctx` parameter to provide the parent when nesting transactions.
*/
begin(ctx?: Transaction): Promise;
/**
* Commits the transaction bound to this EntityManager. Flushes before doing the actual commit query.
*/
commit(): Promise;
/**
* Rollbacks the transaction bound to this EntityManager.
*/
rollback(): Promise;
/**
* Runs your callback wrapped inside a database transaction.
*/
lock(entity: AnyEntity, lockMode: LockMode, lockVersion?: number | Date): Promise;
/**
* Fires native insert query. Calling this has no side effects on the context (identity map).
*/
nativeInsert>(entity: T): Promise>;
/**
* Fires native insert query. Calling this has no side effects on the context (identity map).
*/
nativeInsert>(entityName: EntityName, data: EntityData): Promise>;
/**
* Fires native update query. Calling this has no side effects on the context (identity map).
*/
nativeUpdate>(entityName: EntityName, where: FilterQuery, data: EntityData, options?: UpdateOptions): Promise;
/**
* Fires native delete query. Calling this has no side effects on the context (identity map).
*/
nativeDelete>(entityName: EntityName, where: FilterQuery, options?: DeleteOptions): Promise;
/**
* Maps raw database result to an entity and merges it to this EntityManager.
*/
map>(entityName: EntityName, result: EntityData): T;
/**
* Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities
* via second parameter. By default it will return already loaded entities without modifying them.
*/
merge>(entity: T, refresh?: boolean): T;
/**
* Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities
* via second parameter. By default it will return already loaded entities without modifying them.
*/
merge>(entityName: EntityName, data: EntityData, refresh?: boolean, convertCustomTypes?: boolean): T;
/**
* Creates new instance of given entity and populates it with given data
*/
create, P extends Populate = any>(entityName: EntityName, data: EntityData): New;
/**
* Shortcut for `wrap(entity).assign(data, { em })`
*/
assign>(entity: T, data: EntityData, options?: AssignOptions): T;
/**
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
*/
getReference, PK extends keyof T>(entityName: EntityName, id: Primary, wrapped: true, convertCustomTypes?: boolean): IdentifiedReference;
/**
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
*/
getReference>(entityName: EntityName, id: Primary | Primary[]): T;
/**
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
*/
getReference>(entityName: EntityName, id: Primary, wrapped: false, convertCustomTypes?: boolean): T;
/**
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
*/
getReference>(entityName: EntityName, id: Primary, wrapped?: boolean, convertCustomTypes?: boolean): T | Reference;
/**
* Returns total number of entities matching your `where` query.
*/
count>(entityName: EntityName, where?: FilterQuery, options?: CountOptions): Promise;
/**
* Tells the EntityManager to make an instance managed and persistent.
* The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
*/
persist(entity: AnyEntity | Reference | (AnyEntity | Reference)[]): this;
/**
* Persists your entity immediately, flushing all not yet persisted changes to the database too.
* Equivalent to `em.persist(e).flush()`.
*/
persistAndFlush(entity: AnyEntity | Reference | (AnyEntity | Reference)[]): Promise;
/**
* Tells the EntityManager to make an instance managed and persistent.
* The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
*
* @deprecated use `persist()`
*/
persistLater(entity: AnyEntity | AnyEntity[]): void;
/**
* Marks entity for removal.
* A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
*
* To remove entities by condition, use `em.nativeDelete()`.
*/
remove>(entity: T | Reference | (T | Reference)[]): this;
/**
* Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
* Equivalent to `em.remove(e).flush()`
*/
removeAndFlush(entity: AnyEntity | Reference): Promise;
/**
* Marks entity for removal.
* A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
*
* @deprecated use `remove()`
*/
removeLater(entity: AnyEntity): void;
/**
* Flushes all changes to objects that have been queued up to now to the database.
* This effectively synchronizes the in-memory state of managed objects with the database.
*/
flush(): Promise;
/**
* Clears the EntityManager. All entities that are currently managed by this EntityManager become detached.
*/
clear(): void;
/**
* Checks whether given property can be populated on the entity.
*/
canPopulate>(entityName: EntityName, property: string): boolean;
populate, P extends string | keyof T | Populate>(entities: T, populate: P, where?: FilterQuery, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise>;
populate, P extends string | keyof T | Populate>(entities: T[], populate: P, where?: FilterQuery, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise[]>;
populate, P extends string | keyof T | Populate>(entities: T | T[], populate: P, where?: FilterQuery, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise | Loaded[]>;
/**
* Returns new EntityManager instance with its own identity map
*
* @param clear do we want clear identity map? defaults to true
* @param useContext use request context? should be used only for top level request scope EM, defaults to false
*/
fork(clear?: boolean, useContext?: boolean): D[typeof EntityManagerType];
/**
* Gets the UnitOfWork used by the EntityManager to coordinate operations.
*/
getUnitOfWork(): UnitOfWork;
/**
* Gets the EntityFactory used by the EntityManager.
*/
getEntityFactory(): EntityFactory;
getEventManager(): EventManager;
/**
* Checks whether this EntityManager is currently operating inside a database transaction.
*/
isInTransaction(): boolean;
/**
* Gets the transaction context (driver dependent object used to make sure queries are executed on same connection).
*/
getTransactionContext(): T | undefined;
/**
* Gets the MetadataStorage.
*/
getMetadata(): MetadataStorage;
getComparator(): EntityComparator;
private checkLockRequirements;
private lockAndPopulate;
private preparePopulate;
private preparePopulateObject;
[inspect.custom](): string;
}