Skip to content

Commit

Permalink
feat(): upgrade to v8
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 7, 2021
1 parent 5bb2449 commit 8c55173
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 84 deletions.
10 changes: 6 additions & 4 deletions lib/common/typeorm.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
ConnectionOptions,
EntityManager,
EntitySchema,
Repository,
Repository
} from 'typeorm';
import { isNullOrUndefined } from 'util';
import { v4 as uuid } from 'uuid';
import { CircularDependencyException } from '../exceptions/circular-dependency.exception';
import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type';
Expand All @@ -27,7 +26,7 @@ export function getRepositoryToken(
entity: EntityClassOrSchema,
connection: Connection | ConnectionOptions | string = DEFAULT_CONNECTION_NAME,
) {
if (isNullOrUndefined(entity)) {
if (entity === null || entity === undefined) {
throw new CircularDependencyException('@InjectRepository()');
}
const connectionPrefix = getConnectionPrefix(connection);
Expand All @@ -36,6 +35,9 @@ export function getRepositoryToken(
(entity.prototype instanceof Repository ||
entity.prototype instanceof AbstractRepository)
) {
if (!connectionPrefix) {
return entity;
}
return `${connectionPrefix}${getCustomRepositoryToken(entity)}`;
}

Expand All @@ -53,7 +55,7 @@ export function getRepositoryToken(
* @returns {string} The Repository injection token
*/
export function getCustomRepositoryToken(repository: Function) {
if (isNullOrUndefined(repository)) {
if (repository === null || repository === undefined) {
throw new CircularDependencyException('@InjectRepository()');
}
return repository.name;
Expand Down
19 changes: 8 additions & 11 deletions lib/typeorm-core.module.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
import {
DynamicModule,
Global,
Inject,
Module,
Inject, Logger, Module,
OnApplicationShutdown,
Provider,
Type,
Logger,
Type
} from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { defer } from 'rxjs';
import { defer, lastValueFrom } from 'rxjs';
import {
Connection,
ConnectionOptions,
createConnection,
getConnectionManager,
getConnectionManager
} from 'typeorm';
import {
generateString,
getConnectionName,
getConnectionToken,
getEntityManagerToken,
handleRetry,
handleRetry
} from './common/typeorm.utils';
import { EntitiesMetadataStorage } from './entities-metadata.storage';
import {
TypeOrmModuleAsyncOptions,
TypeOrmModuleOptions,
TypeOrmOptionsFactory,
TypeOrmOptionsFactory
} from './interfaces/typeorm-options.interface';
import { TYPEORM_MODULE_ID, TYPEORM_MODULE_OPTIONS } from './typeorm.constants';

Expand Down Expand Up @@ -181,7 +179,7 @@ export class TypeOrmCoreModule implements OnApplicationShutdown {
} catch {}

const connectionToken = getConnectionName(options as ConnectionOptions);
return await defer(() => {
return lastValueFrom(defer(() => {
if (!options.type) {
return createConnection();
}
Expand Down Expand Up @@ -212,7 +210,6 @@ export class TypeOrmCoreModule implements OnApplicationShutdown {
options.verboseRetryLog,
options.toRetry,
),
)
.toPromise();
))
}
}
128 changes: 71 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"devDependencies": {
"@commitlint/cli": "12.1.4",
"@commitlint/config-angular": "12.1.4",
"@nestjs/common": "7.6.18",
"@nestjs/core": "7.6.18",
"@nestjs/platform-express": "7.6.18",
"@nestjs/testing": "7.6.18",
"@nestjs/common": "8.0.0",
"@nestjs/core": "8.0.0",
"@nestjs/platform-express": "8.0.0",
"@nestjs/testing": "8.0.0",
"@types/jest": "26.0.24",
"@types/node": "14.17.4",
"@types/node": "16.0.0",
"@types/supertest": "2.0.11",
"@types/uuid": "8.3.1",
"@typescript-eslint/eslint-plugin": "4.28.2",
Expand All @@ -42,8 +42,7 @@
"prettier": "2.3.2",
"reflect-metadata": "0.1.13",
"release-it": "14.10.0",
"rxjs": "6.6.7",
"rxjs-compat": "6.6.7",
"rxjs": "7.2.0",
"supertest": "6.1.3",
"ts-jest": "27.0.3",
"typeorm": "0.2.34",
Expand All @@ -53,11 +52,11 @@
"uuid": "8.3.2"
},
"peerDependencies": {
"@nestjs/common": "^6.7.0 || ^7.0.0",
"@nestjs/core": "^6.7.0 || ^7.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.0.0",
"typeorm": "^0.2.7"
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"typeorm": "^0.2.34"
},
"lint-staged": {
"*.ts": [
Expand Down

0 comments on commit 8c55173

Please sign in to comment.