UNPKG

1.4 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.createTypeOrmProviders = void 0;
4const typeorm_1 = require("typeorm");
5const typeorm_utils_1 = require("./common/typeorm.utils");
6function createTypeOrmProviders(entities, connection) {
7 return (entities || []).map((entity) => ({
8 provide: (0, typeorm_utils_1.getRepositoryToken)(entity, connection),
9 useFactory: (connection) => {
10 if (entity instanceof Function &&
11 (entity.prototype instanceof typeorm_1.Repository ||
12 entity.prototype instanceof typeorm_1.AbstractRepository)) {
13 return connection.getCustomRepository(entity);
14 }
15 return connection.options.type === 'mongodb'
16 ? connection.getMongoRepository(entity)
17 : connection.getRepository(entity);
18 },
19 inject: [(0, typeorm_utils_1.getConnectionToken)(connection)],
20 /**
21 * Extra property to workaround dynamic modules serialisation issue
22 * that occurs when "TypeOrm#forFeature()" method is called with the same number
23 * of arguments and all entities share the same class names.
24 */
25 targetEntitySchema: (0, typeorm_1.getMetadataArgsStorage)().tables.find((item) => item.target === entity),
26 }));
27}
28exports.createTypeOrmProviders = createTypeOrmProviders;