lakutata
Version:
An IoC-based universal application framework.
269 lines (257 loc) • 8.53 kB
TypeScript
import { EntityManager } from './TypeDef.internal.35.js';
import { DataSource } from './TypeDef.internal.33.js';
import { QueryRunner } from './TypeDef.internal.40.js';
import { EntityMetadata, ColumnMetadata, RelationMetadata } from './TypeDef.internal.47.js';
import { ObjectLiteral } from './TypeDef.internal.36.js';
/**
* TransactionCommitEvent is an object that broadcaster sends to the entity subscriber when an transaction is committed.
*/
interface TransactionCommitEvent {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
}
/**
* TransactionRollbackEvent is an object that broadcaster sends to the entity subscriber on transaction rollback.
*/
interface TransactionRollbackEvent {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
}
/**
* TransactionStartEvent is an object that broadcaster sends to the entity subscriber before transaction is started.
*/
interface TransactionStartEvent {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
}
/**
* UpdateEvent is an object that broadcaster sends to the entity subscriber when entity is being updated in the database.
*/
interface UpdateEvent<Entity> {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
/**
* Updating entity.
*
* Contains the same data that was passed to the updating method, be it the instance of an entity or the partial entity.
*/
entity: ObjectLiteral | undefined;
/**
* Metadata of the entity.
*/
metadata: EntityMetadata;
/**
* Updating entity in the database.
*
* Is set only when one of the following methods are used: .save(), .remove(), .softRemove(), and .recover()
*/
databaseEntity: Entity;
/**
* List of updated columns. In query builder has no affected
*/
updatedColumns: ColumnMetadata[];
/**
* List of updated relations. In query builder has no affected
*/
updatedRelations: RelationMetadata[];
}
/**
* RemoveEvent is an object that broadcaster sends to the entity subscriber when entity is being removed to the database.
*/
interface RemoveEvent<Entity> {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
/**
* Entity that is being removed.
* This may absent if entity is removed without being loaded (for examples by cascades).
*/
entity?: Entity;
/**
* Metadata of the entity.
*/
metadata: EntityMetadata;
/**
* Database representation of entity that is being removed.
*/
databaseEntity: Entity;
/**
* Id or ids of the entity that is being removed.
*/
entityId?: any;
}
/**
* InsertEvent is an object that broadcaster sends to the entity subscriber when entity is inserted to the database.
*/
interface InsertEvent<Entity> {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
/**
* Inserting event.
*/
entity: Entity;
/**
* Id or ids of the entity being inserted.
*/
entityId?: ObjectLiteral;
/**
* Metadata of the entity.
*/
metadata: EntityMetadata;
}
/**
* LoadEvent is an object that broadcaster sends to the entity subscriber when an entity is loaded from the database.
*/
interface LoadEvent<Entity> {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
/**
* Loaded entity.
*/
entity: Entity;
/**
* Metadata of the entity.
*/
metadata: EntityMetadata;
}
/**
* SoftRemoveEvent is an object that broadcaster sends to the entity subscriber when entity is being soft removed to the database.
*/
interface SoftRemoveEvent<Entity> extends RemoveEvent<Entity> {
}
/**
* RecoverEvent is an object that broadcaster sends to the entity subscriber when entity is being recovered in the database.
*/
interface RecoverEvent<Entity> extends RemoveEvent<Entity> {
}
/**
* BeforeQueryEvent is an object that broadcaster sends to the entity subscriber before query is ran against the database.
*/
interface QueryEvent<Entity> {
/**
* Connection used in the event.
*/
connection: DataSource;
/**
* QueryRunner used in the event transaction.
* All database operations in the subscribed event listener should be performed using this query runner instance.
*/
queryRunner: QueryRunner;
/**
* EntityManager used in the event transaction.
* All database operations in the subscribed event listener should be performed using this entity manager instance.
*/
manager: EntityManager;
/**
* Query that is being executed.
*/
query: string;
/**
* Parameters used in the query.
*/
parameters?: any[];
}
interface BeforeQueryEvent<Entity> extends QueryEvent<Entity> {
}
interface AfterQueryEvent<Entity> extends QueryEvent<Entity> {
/**
* Whether the query was successful.
*/
success: boolean;
/**
* The duration of the query execution, in milliseconds.
*/
executionTime?: number;
/**
* The raw results from the database if the query was successful.
*/
rawResults?: any;
/**
* The error thrown if the query was unsuccessful.
*/
error?: any;
}
export type { AfterQueryEvent, BeforeQueryEvent, InsertEvent, LoadEvent, RecoverEvent, RemoveEvent, SoftRemoveEvent, TransactionCommitEvent, TransactionRollbackEvent, TransactionStartEvent, UpdateEvent };