lakutata
Version:
An IoC-based universal application framework.
327 lines (323 loc) • 10.8 kB
TypeScript
import { Component } from './TypeDef.internal.96.js';
import { DataSourceOptions, DataSource } from './TypeDef.internal.33.js';
import { Driver } from './TypeDef.internal.45.js';
import { EntityManager } from './TypeDef.internal.35.js';
import { NamingStrategyInterface } from './TypeDef.internal.43.js';
import { EntitySubscriberInterface } from './TypeDef.internal.46.js';
import { EntityMetadata } from './TypeDef.internal.47.js';
import { EntityTarget, ObjectLiteral } from './TypeDef.internal.36.js';
import { Migration } from './TypeDef.internal.48.js';
import { Repository, TreeRepository, MongoRepository } from './TypeDef.internal.37.js';
import { QueryRunner } from './TypeDef.internal.40.js';
import { SelectQueryBuilder } from './TypeDef.internal.38.js';
import { IsolationLevel, ReplicationMode } from './TypeDef.internal.44.js';
import { QueryResultCache } from './TypeDef.internal.39.js';
/**
* Logger component
*/
declare class Logger extends Component {
#private;
/**
* Format pretty log message
* @protected
*/
protected readonly pretty: boolean;
/**
* Log level
* @protected
*/
protected readonly level: string;
/**
* If set to true, will add color information to the formatted output message.
* @protected
*/
protected readonly colorize: boolean;
/**
* Makes messaging synchronous.
* @protected
*/
protected readonly sync: boolean;
/**
* Stream to write to
* @protected
*/
protected readonly destinations: NodeJS.WritableStream[];
/**
* Initializer
* @protected
*/
protected init(): Promise<void>;
/**
* Write a 'error' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
error<T extends object>(obj: T, msg?: string, ...args: any[]): void;
/**
* Write a 'error' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
error(obj: unknown, msg?: string, ...args: any[]): void;
/**
* Write a 'error' level log, if the configured level allows for it.
* @param msg
* @param args
*/
error(msg: string, ...args: any[]): void;
/**
* Write a 'warn' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
warn<T extends object>(obj: T, msg?: string, ...args: any[]): void;
/**
* Write a 'warn' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
warn(obj: unknown, msg?: string, ...args: any[]): void;
/**
* Write a 'warn' level log, if the configured level allows for it.
* @param msg
* @param args
*/
warn(msg: string, ...args: any[]): void;
/**
* Write a 'info' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
info<T extends object>(obj: T, msg?: string, ...args: any[]): void;
/**
* Write a 'info' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
info(obj: unknown, msg?: string, ...args: any[]): void;
/**
* Write a 'info' level log, if the configured level allows for it.
* @param msg
* @param args
*/
info(msg: string, ...args: any[]): void;
/**
* Write a 'debug' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
debug<T extends object>(obj: T, msg?: string, ...args: any[]): void;
/**
* Write a 'debug' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
debug(obj: unknown, msg?: string, ...args: any[]): void;
/**
* Write a 'debug' level log, if the configured level allows for it.
* @param msg
* @param args
*/
debug(msg: string, ...args: any[]): void;
/**
* Write a 'trace' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
trace<T extends object>(obj: T, msg?: string, ...args: any[]): void;
/**
* Write a 'trace' level log, if the configured level allows for it.
* @param obj
* @param msg
* @param args
*/
trace(obj: unknown, msg?: string, ...args: any[]): void;
/**
* Write a 'trace' level log, if the configured level allows for it.
* @param msg
* @param args
*/
trace(msg: string, ...args: any[]): void;
}
/**
* Build database connection options
* @param options
* @constructor
*/
declare const BuildDatabaseOptions: (options: DataSourceOptions) => {
class: typeof Database;
options: DataSourceOptions;
};
/**
* Database component
*/
declare class Database extends Component {
#private;
static databaseSymbol: symbol;
/**
* Connection options
*/
protected readonly options: DataSourceOptions;
/**
* Datasource instance
* @protected
*/
protected get datasource(): DataSource;
/**
* Connection driver
*/
get driver(): Driver;
/**
* EntityManager of this connection.
*/
get manager(): EntityManager;
/**
* Set naming strategy used in the connection.
* @param instance
*/
set namingStrategy(instance: NamingStrategyInterface);
/**
* Get naming strategy used in the connection.
*/
get namingStrategy(): NamingStrategyInterface;
/**
* Entity subscriber instances that are registered for this connection.
*/
get subscribers(): EntitySubscriberInterface<any>[];
/**
* All entity metadatas that are registered for this connection.
*/
get entityMetadatas(): EntityMetadata[];
/**
* All entity metadatas that are registered for this connection.
* This is a copy of #.entityMetadatas property -> used for more performant searches.
*/
get entityMetadatasMap(): Map<EntityTarget<any>, EntityMetadata>;
/**
* Used to work with query result cache.
*/
get queryResultCache(): QueryResultCache | undefined;
/**
* Initializer
* @protected
*/
protected init(): Promise<void>;
/**
* Destroyer
* @protected
*/
protected destroy(): Promise<void>;
/**
* Creates database schema for all entities registered in this connection.
* Can be used only after connection to the database is established.
*
* @param dropBeforeSync If set to true then it drops the database with all its tables and data
*/
synchronize(dropBeforeSync?: boolean): Promise<void>;
/**
* Runs all pending migrations.
* Can be used only after connection to the database is established.
* @param options
*/
runMigrations(options?: {
transaction?: 'all' | 'none' | 'each';
fake?: boolean;
}): Promise<Migration[]>;
/**
* Reverts last executed migration.
* Can be used only after connection to the database is established.
* @param options
*/
undoLastMigration(options?: {
transaction?: 'all' | 'none' | 'each';
fake?: boolean;
}): Promise<void>;
/**
* Lists all migrations and whether they have been run.
* Returns true if there are pending migrations
*/
showMigrations(): Promise<boolean>;
/**
* Checks if entity metadata exist for the given entity class, target name or table name.
* @param target
*/
hasMetadata(target: EntityTarget<any>): boolean;
/**
* Gets entity metadata for the given entity class or schema name.
* @param target
*/
getMetadata(target: EntityTarget<any>): EntityMetadata;
/**
* Gets repository for the given entity.
* @param target
*/
getRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): Repository<Entity>;
/**
* Gets tree repository for the given entity class or name.
* Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.
* @param target
*/
getTreeRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): TreeRepository<Entity>;
/**
* Gets mongodb-specific repository for the given entity class or name.
* Works only if connection is mongodb-specific.
* @param target
*/
getMongoRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): MongoRepository<Entity>;
/**
* Wraps given function execution (and all operations made there) into a transaction.
* All database operations must be executed using provided entity manager.
* @param runInTransaction
*/
transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
/**
* Executes raw SQL query and returns raw database results.
* @param query
* @param parameters
* @param queryRunner
*/
query<T = any>(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<T>;
/**
* Creates a new query builder that can be used to build a SQL query.
* @param entityClass
* @param alias
* @param queryRunner
*/
createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;
/**
* Creates a query runner used for perform queries on a single database connection.
* Using query runners you can control your queries to execute using single database connection and
* manually control your database transaction.
*
* Mode is used in replication mode and indicates whatever you want to connect
* to master database or any of slave databases.
* If you perform writes you must use master database,
* if you perform reads you can use slave databases.
*
* @param mode
*/
createQueryRunner(mode?: ReplicationMode): QueryRunner;
/**
* Gets entity metadata of the junction table (many-to-many table).
* @param entityTarget
* @param relationPropertyPath
*/
getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string): EntityMetadata | undefined;
/**
* Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.
* @param queryRunner
*/
createEntityManager(queryRunner?: QueryRunner): EntityManager;
}
export { BuildDatabaseOptions, Database, Logger };