chore(deps): update typeorm

This commit is contained in:
renovate[bot] 2022-06-25 13:48:25 +00:00 committed by Julian Tölle
parent 9900bc641d
commit ef84800ce8
22 changed files with 232 additions and 242 deletions

View file

@ -0,0 +1,4 @@
This module restores the classes-based custom Repository functionality from
typeorm v0.2.
Directly adapted from anchan828: https://gist.github.com/anchan828/9e569f076e7bc18daf21c652f7c3d012

View file

@ -0,0 +1,7 @@
import { SetMetadata } from "@nestjs/common";
export const TYPEORM_ENTITY_REPOSITORY = "TYPEORM_ENTITY_REPOSITORY";
export function EntityRepository(entity: Function): ClassDecorator {
return SetMetadata(TYPEORM_ENTITY_REPOSITORY, entity);
}

View file

@ -0,0 +1,3 @@
import { EntityRepository } from "./entity-repository.decorator";
export { EntityRepository };

View file

@ -0,0 +1,39 @@
import { DynamicModule, Provider } from "@nestjs/common";
import { getDataSourceToken } from "@nestjs/typeorm";
import { DataSource } from "typeorm";
import { TYPEORM_ENTITY_REPOSITORY } from "./entity-repository.decorator";
export class TypeOrmRepositoryModule {
public static for<T extends new (...args: any[]) => any>(
repositories: T[]
): DynamicModule {
const providers: Provider[] = [];
for (const repository of repositories) {
const entity = Reflect.getMetadata(TYPEORM_ENTITY_REPOSITORY, repository);
if (!entity) {
continue;
}
providers.push({
inject: [getDataSourceToken()],
provide: repository,
useFactory: (dataSource: DataSource): typeof repository => {
const baseRepository = dataSource.getRepository<any>(entity);
return new repository(
baseRepository.target,
baseRepository.manager,
baseRepository.queryRunner
);
},
});
}
return {
exports: providers,
module: TypeOrmRepositoryModule,
providers,
};
}
}