import { ObjectLiteral , EntityManager , QueryRunner , DeepPartial , SaveOptions , RemoveOptions , InsertResult , ObjectID , FindConditions , UpdateResult , DeleteResult , FindManyOptions , FindOneOptions , EntitySchema , Connection , } from 'typeorm' ; import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity' ; export class BaseRepository < Entity extends ObjectLiteral > { readonly manager : EntityManager ; readonly queryRunner ? : QueryRunner ; readonly entitySchema : EntitySchema < Entity > ; constructor ( connection , entity ) { this . queryRunner = connection . createQueryRunner ( ) ; this . manager = this . queryRunner . manager ; this . entitySchema = entity ; } hasId ( entity ) { return this . manager . hasId ( entity ) ; } getId ( entity ) { return this . manager . getId ( entity ) ; } create ( ) ; create ( entityLikeArray ) ; create ( entityLike ) ; create ( plainEntityLikeOrPlainEntityLikes ? ) { return this . manager . create < any > ( this . entitySchema as any , plainEntityLikeOrPlainEntityLikes as any ) ; } merge ( mergeIntoEntity , ... entityLikes ) { return this . manager . merge ( this . entitySchema as any , mergeIntoEntity , ... entityLikes ) ; } preload ( entityLike ) { return this . manager . preload ( this . entitySchema as any , entityLike ) ; } save < T extends DeepPartial < Entity > > ( entities , options ) ; save < T extends DeepPartial < Entity > > ( entities , options ? ) ; save < T extends DeepPartial < Entity > > ( entity , options ) ; save < T extends DeepPartial < Entity > > ( entity , options ? ) ; save < T extends DeepPartial < Entity > > ( entityOrEntities , options ? ) { return this . manager . save < T > ( this . entitySchema as any , entityOrEntities as any , options ) ; } remove ( entities , options ? ) ; remove ( entity , options ? ) ; remove ( entityOrEntities , options ? ) { return this . manager . remove ( this . entitySchema as any , entityOrEntities as any , options ) ; } softRemove < T extends DeepPartial < Entity > > ( entities , options ) ; softRemove < T extends DeepPartial < Entity > > ( entities , options ? ) ; softRemove < T extends DeepPartial < Entity > > ( entity , options ) ; softRemove < T extends DeepPartial < Entity > > ( entity , options ? ) ; softRemove < T extends DeepPartial < Entity > > ( entityOrEntities , options ? ) { return this . manager . softRemove < T > ( this . entitySchema as any , entityOrEntities as any , options ) ; } recover < T extends DeepPartial < Entity > > ( entities , options ) ; recover < T extends DeepPartial < Entity > > ( entities , options ? ) ; recover < T extends DeepPartial < Entity > > ( entity , options ) ; recover < T extends DeepPartial < Entity > > ( entity , options ? ) ; recover < T extends DeepPartial < Entity > > ( entityOrEntities , options ? ) { return this . manager . recover < T > ( this . entitySchema as any , entityOrEntities as any , options ) ; } insert ( entity ) { return this . manager . insert ( this . entitySchema as any , entity ) ; } update ( criteria , partialEntity ) { return this . manager . update ( this . entitySchema as any , criteria as any , partialEntity ) ; } delete ( criteria ) { return this . manager . delete ( this . entitySchema as any , criteria as any ) ; } softDelete ( criteria ) { return this . manager . softDelete ( this . entitySchema as any , criteria as any ) ; } restore ( criteria ) { return this . manager . restore ( this . entitySchema as any , criteria as any ) ; } count ( options ? ) ; count ( conditions ? ) ; count ( optionsOrConditions ? ) { return this . manager . count ( this . entitySchema as any , optionsOrConditions as any ) ; } find ( options ? ) ; find ( conditions ? ) ; find ( optionsOrConditions ? ) { return this . manager . find ( this . entitySchema as any , optionsOrConditions as any ) ; } findAndCount ( options ? ) ; findAndCount ( conditions ? ) ; findAndCount ( optionsOrConditions ? ) { return this . manager . findAndCount ( this . entitySchema as any , optionsOrConditions as any ) ; } findByIds ( ids , options ? ) ; findByIds ( ids , conditions ? ) ; findByIds ( ids , optionsOrConditions ? ) { return this . manager . findByIds ( this . entitySchema as any , ids , optionsOrConditions as any ) ; } findOne ( id ? , options ? ) ; findOne ( options ? ) ; findOne ( conditions ? , options ? ) ; findOne ( optionsOrConditions ? , maybeOptions ? ) { return this . manager . findOne ( this . entitySchema as any , optionsOrConditions as any , maybeOptions ) ; } findOneOrFail ( id ? , options ? ) ; findOneOrFail ( options ? ) ; findOneOrFail ( conditions ? , options ? ) ; findOneOrFail ( optionsOrConditions ? , maybeOptions ? ) { return this . manager . findOneOrFail ( this . entitySchema as any , optionsOrConditions as any , maybeOptions ) ; } query ( query , parameters ? ) { return this . manager . query ( query , parameters ) ; } clear ( ) { return this . manager . clear ( this . entitySchema ) ; } increment ( conditions , propertyPath , value ) { return this . manager . increment ( this . entitySchema , conditions , propertyPath , value ) ; } decrement ( conditions , propertyPath , value ) { return this . manager . decrement ( this . entitySchema , conditions , propertyPath , value ) ; } async transaction < T > ( operation ) { await this . queryRunner . connect ( ) ; await this . queryRunner . startTransaction ( ) ; try { const result = await operation ( ) ; await this . queryRunner . commitTransaction ( ) ; return result ; } catch ( err ) { await this . queryRunner . rollbackTransaction ( ) ; } finally { await this . queryRunner . release ( ) ; } } }