Skip to content

Commit b924800

Browse files
committed
Merge remote-tracking branch 'origin/master' into style/eslint-prefer-nullish-coalescing
2 parents 29d9ea9 + cab8fcb commit b924800

129 files changed

Lines changed: 1417 additions & 1803 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎eslint.config.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default defineConfig([
3737
// custom rules
3838
"@typescript-eslint/consistent-type-exports": "error",
3939
"@typescript-eslint/consistent-type-imports": "error",
40+
"@typescript-eslint/prefer-nullish-coalescing": "error",
41+
"@typescript-eslint/prefer-optional-chain": "error",
4042
"@typescript-eslint/prefer-string-starts-ends-with": "error",
4143

4244
// exceptions from typescript-eslint/recommended

‎src/cache/DbQueryResultCache.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class DbQueryResultCache implements QueryResultCache {
3232
typeof this.dataSource.options.cache === "object"
3333
? this.dataSource.options.cache
3434
: {}
35-
const cacheTableName = cacheOptions.tableName || "query-result-cache"
35+
const tableName =
36+
cacheOptions.tableName === "" ? undefined : cacheOptions.tableName
37+
const cacheTableName = tableName ?? "query-result-cache"
3638

3739
this.queryResultCacheDatabase = database
3840
this.queryResultCacheSchema = schema
@@ -244,7 +246,7 @@ export class DbQueryResultCache implements QueryResultCache {
244246
}
245247
}
246248

247-
if (savedCache && savedCache.identifier) {
249+
if (savedCache?.identifier) {
248250
// if exist then update
249251
const qb = queryRunner.manager
250252
.createQueryBuilder()
@@ -255,7 +257,7 @@ export class DbQueryResultCache implements QueryResultCache {
255257
condition: insertedValues.identifier,
256258
})
257259
await qb.execute()
258-
} else if (savedCache && savedCache.query) {
260+
} else if (savedCache?.query) {
259261
// if exist then update
260262
const qb = queryRunner.manager
261263
.createQueryBuilder()
@@ -317,7 +319,7 @@ export class DbQueryResultCache implements QueryResultCache {
317319
identifiers: string[],
318320
queryRunner?: QueryRunner,
319321
): Promise<void> {
320-
const _queryRunner: QueryRunner = queryRunner || this.getQueryRunner()
322+
const _queryRunner: QueryRunner = queryRunner ?? this.getQueryRunner()
321323
await Promise.all(
322324
identifiers.map((identifier) => {
323325
const qb = _queryRunner.manager.createQueryBuilder()

‎src/cache/RedisQueryResultCache.ts‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class RedisQueryResultCache implements QueryResultCache {
6767

6868
await this.client.connect()
6969
} else if (this.clientType === "ioredis") {
70-
if (cacheOptions && cacheOptions.port) {
70+
if (cacheOptions?.port) {
7171
if (cacheOptions.options) {
7272
this.client = new this.redis(
7373
cacheOptions.port,
@@ -76,23 +76,15 @@ export class RedisQueryResultCache implements QueryResultCache {
7676
} else {
7777
this.client = new this.redis(cacheOptions.port)
7878
}
79-
} else if (cacheOptions && cacheOptions.options) {
79+
} else if (cacheOptions?.options) {
8080
this.client = new this.redis(cacheOptions.options)
8181
} else {
8282
this.client = new this.redis()
8383
}
8484
} else if (this.clientType === "ioredis/cluster") {
85-
if (
86-
cacheOptions &&
87-
cacheOptions.options &&
88-
Array.isArray(cacheOptions.options)
89-
) {
85+
if (cacheOptions?.options && Array.isArray(cacheOptions.options)) {
9086
this.client = new this.redis.Cluster(cacheOptions.options)
91-
} else if (
92-
cacheOptions &&
93-
cacheOptions.options &&
94-
cacheOptions.options.startupNodes
95-
) {
87+
} else if (cacheOptions?.options?.startupNodes) {
9688
this.client = new this.redis.Cluster(
9789
cacheOptions.options.startupNodes,
9890
cacheOptions.options.options,
@@ -133,7 +125,9 @@ export class RedisQueryResultCache implements QueryResultCache {
133125
options: QueryResultCacheOptions,
134126
queryRunner?: QueryRunner,
135127
): Promise<QueryResultCacheOptions | undefined> {
136-
const key = options.identifier || options.query
128+
const identifier =
129+
options.identifier === "" ? undefined : options.identifier
130+
const key = identifier ?? options.query
137131
if (!key) return undefined
138132

139133
const result = await this.client.get(key)
@@ -161,7 +155,9 @@ export class RedisQueryResultCache implements QueryResultCache {
161155
savedCache: QueryResultCacheOptions,
162156
queryRunner?: QueryRunner,
163157
): Promise<void> {
164-
const key = options.identifier || options.query
158+
const identifier =
159+
options.identifier === "" ? undefined : options.identifier
160+
const key = identifier ?? options.query
165161
if (!key) return
166162

167163
const value = JSON.stringify(options)

‎src/cli-ts-node-esm.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { spawnSync } from "child_process"
33

4-
if ((process.env["NODE_OPTIONS"] || "").includes("--loader ts-node"))
4+
if ((process.env["NODE_OPTIONS"] ?? "").includes("--loader ts-node"))
55
require("./cli")
66
else {
77
const childProcess = spawnSync(process.argv[0], process.argv.slice(1), {
@@ -19,5 +19,5 @@ else {
1919
windowsHide: true,
2020
})
2121

22-
process.exit(childProcess.status || 0)
22+
process.exit(childProcess.status ?? 0)
2323
}

‎src/commands/CacheClearCommand.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class CacheClearCommand implements yargs.CommandModule {
5151
} catch (err) {
5252
PlatformTools.logCmdErr("Error during cache clear.", err)
5353

54-
if (dataSource && dataSource.isInitialized)
54+
if (dataSource?.isInitialized)
5555
await (dataSource as DataSource).destroy()
5656

5757
process.exit(1)

‎src/commands/InitCommand.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class InitCommand implements yargs.CommandModule {
6262

6363
async handler(args: yargs.Arguments) {
6464
try {
65-
const database: string = (args.database as any) || "postgres"
65+
const database: string = (args.database as any) ?? "postgres"
6666
const isExpress = args.express !== undefined ? true : false
6767
const isDocker = args.docker !== undefined ? true : false
6868
const basePath = process.cwd() + (args.name ? "/" + args.name : "")
@@ -581,7 +581,7 @@ AppDataSource.initialize().then(async () => {
581581
): string {
582582
return JSON.stringify(
583583
{
584-
name: projectName || "typeorm-sample",
584+
name: projectName ?? "typeorm-sample",
585585
version: "0.0.1",
586586
description: "Awesome project developed with TypeORM.",
587587
type: projectIsEsm ? "module" : "commonjs",
@@ -741,15 +741,15 @@ Steps to run this project:
741741
),
742742
)
743743

744-
if (!packageJson.devDependencies) packageJson.devDependencies = {}
744+
packageJson.devDependencies ??= {}
745745
packageJson.devDependencies = {
746746
"@types/node": ourPackageJson.devDependencies["@types/node"],
747747
"ts-node": ourPackageJson.devDependencies["ts-node"],
748748
typescript: ourPackageJson.devDependencies.typescript,
749749
...packageJson.devDependencies,
750750
}
751751

752-
if (!packageJson.dependencies) packageJson.dependencies = {}
752+
packageJson.dependencies ??= {}
753753
packageJson.dependencies = {
754754
...packageJson.dependencies,
755755
"reflect-metadata": ourPackageJson.dependencies["reflect-metadata"],
@@ -794,7 +794,7 @@ Steps to run this project:
794794
packageJson.dependencies["body-parser"] = "^1.20.3"
795795
}
796796

797-
if (!packageJson.scripts) packageJson.scripts = {}
797+
packageJson.scripts ??= {}
798798

799799
if (projectIsEsm)
800800
Object.assign(packageJson.scripts, {

‎src/commands/MigrationGenerateCommand.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class MigrationGenerateCommand implements yargs.CommandModule {
219219
* @param parameters
220220
*/
221221
protected static queryParams(parameters: any[] | undefined): string {
222-
if (!parameters || !parameters.length) {
222+
if (!parameters?.length) {
223223
return ""
224224
}
225225

‎src/commands/MigrationRevertCommand.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ export class MigrationRevertCommand implements yargs.CommandModule {
7676
} catch (err) {
7777
PlatformTools.logCmdErr("Error during migration revert:", err)
7878

79-
if (dataSource && dataSource.isInitialized)
80-
await dataSource.destroy()
79+
if (dataSource?.isInitialized) await dataSource.destroy()
8180

8281
process.exit(1)
8382
}

‎src/commands/MigrationRunCommand.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export class MigrationRunCommand implements yargs.CommandModule {
8181
} catch (err) {
8282
PlatformTools.logCmdErr("Error during migration run:", err)
8383

84-
if (dataSource && dataSource.isInitialized)
85-
await dataSource.destroy()
84+
if (dataSource?.isInitialized) await dataSource.destroy()
8685

8786
process.exit(1)
8887
}

‎src/commands/MigrationShowCommand.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export class MigrationShowCommand implements yargs.CommandModule {
4242
} catch (err) {
4343
PlatformTools.logCmdErr("Error during migration show:", err)
4444

45-
if (dataSource && dataSource.isInitialized)
46-
await dataSource.destroy()
45+
if (dataSource?.isInitialized) await dataSource.destroy()
4746

4847
process.exit(1)
4948
}

0 commit comments

Comments
 (0)