UNPKG

917 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const typeorm_1 = require("typeorm");
4const typeorm_utils_1 = require("./common/typeorm.utils");
5function createTypeOrmProviders(entities, connection) {
6 return (entities || []).map(entity => ({
7 provide: typeorm_utils_1.getRepositoryToken(entity, connection),
8 useFactory: (connection) => {
9 if (entity.prototype instanceof typeorm_1.Repository ||
10 entity.prototype instanceof typeorm_1.AbstractRepository) {
11 return connection.getCustomRepository(entity);
12 }
13 return connection.options.type === 'mongodb'
14 ? connection.getMongoRepository(entity)
15 : connection.getRepository(entity);
16 },
17 inject: [typeorm_utils_1.getConnectionToken(connection)],
18 }));
19}
20exports.createTypeOrmProviders = createTypeOrmProviders;