1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createTypeOrmProviders = void 0;
|
4 | const typeorm_1 = require("typeorm");
|
5 | const typeorm_utils_1 = require("./common/typeorm.utils");
|
6 | function 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 |
|
22 |
|
23 |
|
24 |
|
25 | targetEntitySchema: (0, typeorm_1.getMetadataArgsStorage)().tables.find((item) => item.target === entity),
|
26 | }));
|
27 | }
|
28 | exports.createTypeOrmProviders = createTypeOrmProviders;
|