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ED;;OAEG;IACO,gBAAgB,CACtB,MAAqB;QAErB,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7C,CAAC;IAED;;OAEG;IACO,oBAAoB,CAC1B,MAAqB;QAErB,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IAED,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAE5E;;;OAGG;IACK,yBAAyB,CAC7B,gBAAqB;QAErB,MAAM,4BAA4B,GAC9B,IAAA,gCAAsB,GAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;YAC5D,OAAO,CACH,UAAU,CAAC,MAAM;gBACjB,CAAC,OAAO,gBAAgB,KAAK,UAAU;oBACnC,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAE,gBAAwB,CAAC,WAAW,CAAC,CAC/C,CAAA;QACL,CAAC,CAAC,CAAA;QACN,IAAI,CAAC,4BAA4B;YAC7B,MAAM,IAAI,6DAA6B,CAAC,gBAAgB,CAAC,CAAA;QAE7D,OAAO,4BAA4B,CAAC,MAAM,CAAA;IAC9C,CAAC;CACJ;AA7GD,gDA6GC","file":"AbstractRepository.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { Repository } from \"./Repository\"\nimport { TreeRepository } from \"./TreeRepository\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { CustomRepositoryDoesNotHaveEntityError } from \"../error/CustomRepositoryDoesNotHaveEntityError\"\nimport { getMetadataArgsStorage } from \"../globals\"\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 * @deprecated use Repository.extend function to create a custom repository\n */\nexport class AbstractRepository {\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 {\n const target = this.getCustomRepositoryTarget(this as any)\n if (!target)\n throw new CustomRepositoryDoesNotHaveEntityError(this.constructor)\n\n return this.manager.getRepository(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 {\n const target = this.getCustomRepositoryTarget(this as any)\n if (!target)\n throw new CustomRepositoryDoesNotHaveEntityError(this.constructor)\n\n return this.manager.getTreeRepository(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 {\n const target = this.getCustomRepositoryTarget(this.constructor)\n if (!target)\n throw new CustomRepositoryDoesNotHaveEntityError(this.constructor)\n\n return this.manager\n .getRepository(target)\n .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(\n entity: ObjectType,\n alias: string,\n ): SelectQueryBuilder {\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(\n entity: ObjectType,\n ): Repository {\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(\n entity: ObjectType,\n ): TreeRepository {\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(\n customRepository: any,\n ): EntityTarget | undefined {\n const entityRepositoryMetadataArgs =\n getMetadataArgsStorage().entityRepositories.find((repository) => {\n return (\n repository.target ===\n (typeof customRepository === \"function\"\n ? customRepository\n : (customRepository as any).constructor)\n )\n })\n if (!entityRepositoryMetadataArgs)\n throw new CustomRepositoryNotFoundError(customRepository)\n\n return entityRepositoryMetadataArgs.entity\n }\n}\n"],"sourceRoot":".."}