UNPKG

971 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 instanceof Function &&
10 (entity.prototype instanceof typeorm_1.Repository ||
11 entity.prototype instanceof typeorm_1.AbstractRepository)) {
12 return connection.getCustomRepository(entity);
13 }
14 return connection.options.type === 'mongodb'
15 ? connection.getMongoRepository(entity)
16 : connection.getRepository(entity);
17 },
18 inject: [typeorm_utils_1.getConnectionToken(connection)],
19 }));
20}
21exports.createTypeOrmProviders = createTypeOrmProviders;