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AI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACO,6CAAgB,GAA1B,UAA8B,MAAqB;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACO,iDAAoB,GAA9B,UAAkC,MAAqB;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAE5E;;;OAGG;IACK,sDAAyB,GAAjC,UAAkC,gBAAqB;QACnD,IAAM,4BAA4B,GAAG,8BAAsB,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAA,UAAU;YAC5F,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,gBAAgB,YAAY,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAE,gBAAwB,CAAC,WAAW,CAAC,CAAC;QACnI,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,4BAA4B;YAC7B,MAAM,IAAI,6DAA6B,CAAC,gBAAgB,CAAC,CAAC;QAE9D,OAAO,4BAA4B,CAAC,MAAM,CAAC;IAC/C,CAAC;IAEL,yBAAC;AAAD,CA9FA,AA8FC,IAAA;AA9FY,gDAAkB","file":"AbstractRepository.js","sourcesContent":["import {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {Repository} from \"./Repository\";\nimport {TreeRepository} from \"./TreeRepository\";\nimport {ObjectType} from \"../common/ObjectType\";\nimport {CustomRepositoryDoesNotHaveEntityError} from \"../error/CustomRepositoryDoesNotHaveEntityError\";\nimport {getMetadataArgsStorage} from \"../index\";\nimport {CustomRepositoryNotFoundError} from \"../error/CustomRepositoryNotFoundError\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\n\n/**\n * Provides abstract class for custom repositories that do not inherit from original orm Repository.\n * Contains all most-necessary methods to simplify code in the custom repository.\n * All methods are protected thus not exposed and it allows to create encapsulated custom repository.\n *\n * @experimental\n */\nexport class AbstractRepository<Entity extends ObjectLiteral> {\n\n // -------------------------------------------------------------------------\n // Protected Methods Set Dynamically\n // -------------------------------------------------------------------------\n\n /**\n * Gets entity manager that allows to perform repository operations with any entity.\n */\n protected manager: EntityManager;\n\n // -------------------------------------------------------------------------\n // Protected Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Gets the original ORM repository for the entity that is managed by this repository.\n * If current repository does not manage any entity, then exception will be thrown.\n */\n protected get repository(): Repository<Entity> {\n const target = this.getCustomRepositoryTarget(this as any);\n if (!target)\n throw new CustomRepositoryDoesNotHaveEntityError(this.constructor);\n\n return this.manager.getRepository<Entity>(target);\n }\n\n /**\n * Gets the original ORM tree repository for the entity that is managed by this repository.\n * If current repository does not manage any entity, then exception will be thrown.\n */\n protected get treeRepository(): TreeRepository<Entity> {\n const target = this.getCustomRepositoryTarget(this as any);\n if (!target)\n throw new CustomRepositoryDoesNotHaveEntityError(this.constructor);\n\n return this.manager.getTreeRepository<Entity>(target);\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder for the repository's entity that can be used to build a sql query.\n * If current repository does not manage any entity, then exception will be thrown.\n */\n protected createQueryBuilder(alias: string): SelectQueryBuilder<Entity> {\n const target = this.getCustomRepositoryTarget(this.constructor);\n if (!target)\n throw new CustomRepositoryDoesNotHaveEntityError(this.constructor);\n\n return this.manager.getRepository<Entity>(target).createQueryBuilder(alias);\n }\n\n /**\n * Creates a new query builder for the given entity that can be used to build a sql query.\n */\n protected createQueryBuilderFor<T>(entity: ObjectType<T>, alias: string): SelectQueryBuilder<T> {\n return this.getRepositoryFor(entity).createQueryBuilder(alias);\n }\n\n /**\n * Gets the original ORM repository for the given entity class.\n */\n protected getRepositoryFor<T>(entity: ObjectType<T>): Repository<T> {\n return this.manager.getRepository(entity);\n }\n\n /**\n * Gets the original ORM tree repository for the given entity class.\n */\n protected getTreeRepositoryFor<T>(entity: ObjectType<T>): TreeRepository<T> {\n return this.manager.getTreeRepository(entity);\n }\n\n // -------------------------------------------------------------------------\n // Private Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets custom repository's managed entity.\n * If given custom repository does not manage any entity then undefined will be returned.\n */\n private getCustomRepositoryTarget(customRepository: any): Function|string|undefined {\n const entityRepositoryMetadataArgs = getMetadataArgsStorage().entityRepositories.find(repository => {\n return repository.target === (customRepository instanceof Function ? customRepository : (customRepository as any).constructor);\n });\n if (!entityRepositoryMetadataArgs)\n throw new CustomRepositoryNotFoundError(customRepository);\n\n return entityRepositoryMetadataArgs.entity;\n }\n\n}"],"sourceRoot":".."}
\No newline at end of file