Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default defineConfig([
// custom rules
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/prefer-optional-chain": "error",

// exceptions from typescript-eslint/recommended
"@typescript-eslint/ban-ts-comment": "warn",
Expand Down
4 changes: 2 additions & 2 deletions src/cache/DbQueryResultCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class DbQueryResultCache implements QueryResultCache {
}
}

if (savedCache && savedCache.identifier) {
if (savedCache?.identifier) {
// if exist then update
const qb = queryRunner.manager
.createQueryBuilder()
Expand All @@ -255,7 +255,7 @@ export class DbQueryResultCache implements QueryResultCache {
condition: insertedValues.identifier,
})
await qb.execute()
} else if (savedCache && savedCache.query) {
} else if (savedCache?.query) {
// if exist then update
const qb = queryRunner.manager
.createQueryBuilder()
Expand Down
16 changes: 4 additions & 12 deletions src/cache/RedisQueryResultCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class RedisQueryResultCache implements QueryResultCache {

await this.client.connect()
} else if (this.clientType === "ioredis") {
if (cacheOptions && cacheOptions.port) {
if (cacheOptions?.port) {
if (cacheOptions.options) {
this.client = new this.redis(
cacheOptions.port,
Expand All @@ -76,23 +76,15 @@ export class RedisQueryResultCache implements QueryResultCache {
} else {
this.client = new this.redis(cacheOptions.port)
}
} else if (cacheOptions && cacheOptions.options) {
} else if (cacheOptions?.options) {
this.client = new this.redis(cacheOptions.options)
} else {
this.client = new this.redis()
}
} else if (this.clientType === "ioredis/cluster") {
if (
cacheOptions &&
cacheOptions.options &&
Array.isArray(cacheOptions.options)
) {
if (cacheOptions?.options && Array.isArray(cacheOptions.options)) {
this.client = new this.redis.Cluster(cacheOptions.options)
} else if (
cacheOptions &&
cacheOptions.options &&
cacheOptions.options.startupNodes
) {
} else if (cacheOptions?.options?.startupNodes) {
this.client = new this.redis.Cluster(
cacheOptions.options.startupNodes,
cacheOptions.options.options,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CacheClearCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CacheClearCommand implements yargs.CommandModule {
} catch (err) {
PlatformTools.logCmdErr("Error during cache clear.", err)

if (dataSource && dataSource.isInitialized)
if (dataSource?.isInitialized)
await (dataSource as DataSource).destroy()

process.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/MigrationGenerateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class MigrationGenerateCommand implements yargs.CommandModule {
* @param parameters
*/
protected static queryParams(parameters: any[] | undefined): string {
if (!parameters || !parameters.length) {
if (!parameters?.length) {
return ""
}

Expand Down
3 changes: 1 addition & 2 deletions src/commands/MigrationRevertCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export class MigrationRevertCommand implements yargs.CommandModule {
} catch (err) {
PlatformTools.logCmdErr("Error during migration revert:", err)

if (dataSource && dataSource.isInitialized)
await dataSource.destroy()
if (dataSource?.isInitialized) await dataSource.destroy()

process.exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/MigrationRunCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ export class MigrationRunCommand implements yargs.CommandModule {
} catch (err) {
PlatformTools.logCmdErr("Error during migration run:", err)

if (dataSource && dataSource.isInitialized)
await dataSource.destroy()
if (dataSource?.isInitialized) await dataSource.destroy()

process.exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/MigrationShowCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export class MigrationShowCommand implements yargs.CommandModule {
} catch (err) {
PlatformTools.logCmdErr("Error during migration show:", err)

if (dataSource && dataSource.isInitialized)
await dataSource.destroy()
if (dataSource?.isInitialized) await dataSource.destroy()

process.exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/QueryCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export class QueryCommand implements yargs.CommandModule {
PlatformTools.logCmdErr("Error during query execution:", err)

if (queryRunner) await (queryRunner as QueryRunner).release()
if (dataSource && dataSource.isInitialized)
await dataSource.destroy()
if (dataSource?.isInitialized) await dataSource.destroy()

process.exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/SchemaDropCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export class SchemaDropCommand implements yargs.CommandModule {
} catch (err) {
PlatformTools.logCmdErr("Error during schema drop:", err)

if (dataSource && dataSource.isInitialized)
await dataSource.destroy()
if (dataSource?.isInitialized) await dataSource.destroy()

process.exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/SchemaSyncCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export class SchemaSyncCommand implements yargs.CommandModule {
} catch (err) {
PlatformTools.logCmdErr("Error during schema synchronization:", err)

if (dataSource && dataSource.isInitialized)
await dataSource.destroy()
if (dataSource?.isInitialized) await dataSource.destroy()

process.exit(1)
}
Expand Down
8 changes: 2 additions & 6 deletions src/commands/VersionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ export class VersionCommand implements yargs.CommandModule {
const localNpmList =
await VersionCommand.executeCommand("npm list --depth=0")
const localMatches = localNpmList.match(/ typeorm@(.*)\n/)
const localNpmVersion = (
localMatches && localMatches[1] ? localMatches[1] : ""
)
const localNpmVersion = (localMatches?.[1] ?? "")
.replace(/"invalid"/gi, "")
.trim()

const globalNpmList = await VersionCommand.executeCommand(
"npm list -g --depth=0",
)
const globalMatches = globalNpmList.match(/ typeorm@(.*)\n/)
const globalNpmVersion = (
globalMatches && globalMatches[1] ? globalMatches[1] : ""
)
const globalNpmVersion = (globalMatches?.[1] ?? "")
.replace(/"invalid"/gi, "")
.trim()

Expand Down
9 changes: 4 additions & 5 deletions src/data-source/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class DataSource {
options?.transaction ||
this.options?.migrationsTransactionMode ||
"all"
migrationExecutor.fake = (options && options.fake) || false
migrationExecutor.fake = options?.fake || false

const successMigrations =
await migrationExecutor.executePendingMigrations()
Expand All @@ -386,9 +386,8 @@ export class DataSource {
if (!this.isInitialized) throw new CannotExecuteNotConnectedError()

const migrationExecutor = new MigrationExecutor(this)
migrationExecutor.transaction =
(options && options.transaction) || "all"
migrationExecutor.fake = (options && options.fake) || false
migrationExecutor.transaction = options?.transaction || "all"
migrationExecutor.fake = options?.fake || false

await migrationExecutor.undoLastMigration()
}
Expand Down Expand Up @@ -506,7 +505,7 @@ export class DataSource {
if (InstanceChecker.isMongoEntityManager(this.manager))
throw new TypeORMError(`Queries aren't supported by MongoDB.`)

if (queryRunner && queryRunner.isReleased)
if (queryRunner?.isReleased)
throw new QueryRunnerProviderAlreadyReleasedError()

const usedQueryRunner = queryRunner || this.createQueryRunner()
Expand Down
14 changes: 7 additions & 7 deletions src/decorator/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ export function Index(
: true,
where: options ? options.where : undefined,
type: options ? options.type : undefined,
unique: options && options.unique ? true : false,
spatial: options && options.spatial ? true : false,
fulltext: options && options.fulltext ? true : false,
nullFiltered: options && options.nullFiltered ? true : false,
unique: options?.unique ? true : false,
spatial: options?.spatial ? true : false,
fulltext: options?.fulltext ? true : false,
nullFiltered: options?.nullFiltered ? true : false,
parser: options ? options.parser : undefined,
sparse: options && options.sparse ? true : false,
background: options && options.background ? true : false,
concurrent: options && options.concurrent ? true : false,
sparse: options?.sparse ? true : false,
background: options?.background ? true : false,
concurrent: options?.concurrent ? true : false,
expireAfterSeconds: options
? options.expireAfterSeconds
: undefined,
Expand Down
13 changes: 6 additions & 7 deletions src/decorator/entity/TableInheritance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ export function TableInheritance(options?: {
return function (target: Function) {
getMetadataArgsStorage().inheritances.push({
target: target,
pattern: options && options.pattern ? options.pattern : "STI",
column:
options && options.column
? typeof options.column === "string"
? { name: options.column }
: options.column
: undefined,
pattern: options?.pattern ? options.pattern : "STI",
column: options?.column
? typeof options.column === "string"
? { name: options.column }
: options.column
: undefined,
} as InheritanceMetadataArgs)
}
}
7 changes: 3 additions & 4 deletions src/decorator/relations/JoinTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@
? [(options as JoinTableOptions).inverseJoinColumn!]
: (options as JoinTableMultipleColumnsOptions)
.inverseJoinColumns) as any,
schema: options && options.schema ? options.schema : undefined,
database:
options && options.database ? options.database : undefined,
synchronize: !(options && options.synchronize === false),
schema: options?.schema ? options.schema : undefined,
database: options?.database ? options.database : undefined,
synchronize: !(options?.synchronize === false),

Check warning on line 58 in src/decorator/relations/JoinTable.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the opposite operator (!==) instead.

See more on https://sonarcloud.io/project/issues?id=typeorm_typeorm&issues=AZ10PSxEIXK3d2b_86ro&open=AZ10PSxEIXK3d2b_86ro&pullRequest=12331
} as JoinTableMetadataArgs)
}
}
2 changes: 1 addition & 1 deletion src/decorator/relations/ManyToOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function ManyToOne<T>(
if (!options) options = {} as RelationOptions

// Now try to determine if it is a lazy relation.
let isLazy = options && options.lazy === true
let isLazy = options?.lazy === true
if (!isLazy && Reflect && (Reflect as any).getMetadata) {
// automatic determination
const reflectedType = (Reflect as any).getMetadata(
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/relations/OneToMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function OneToMany<T>(
if (!options) options = {} as RelationOptions

// Now try to determine if it is a lazy relation.
let isLazy = options && options.lazy === true
let isLazy = options?.lazy === true
if (!isLazy && Reflect && (Reflect as any).getMetadata) {
// automatic determination
const reflectedType = (Reflect as any).getMetadata(
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/relations/OneToOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function OneToOne<T>(
if (!options) options = {} as RelationOptions

// now try to determine it its lazy relation
let isLazy = options && options.lazy === true ? true : false
let isLazy = options?.lazy === true ? true : false
if (!isLazy && Reflect && (Reflect as any).getMetadata) {
// automatic determination
const reflectedType = (Reflect as any).getMetadata(
Expand Down
5 changes: 2 additions & 3 deletions src/driver/DriverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ export class DriverUtils {
buildOptions: { shorten?: boolean; joiner?: string } | undefined,
...alias: string[]
): string {
const joiner =
buildOptions && buildOptions.joiner ? buildOptions.joiner : "_"
const joiner = buildOptions?.joiner ? buildOptions.joiner : "_"

const newAlias = alias.length === 1 ? alias[0] : alias.join(joiner)

Expand All @@ -145,7 +144,7 @@ export class DriverUtils {
maxAliasLength > 0 &&
newAlias.length > maxAliasLength
) {
if (buildOptions && buildOptions.shorten === true) {
if (buildOptions?.shorten === true) {
const shortenedAlias = shorten(newAlias)
if (shortenedAlias.length < maxAliasLength) {
return shortenedAlias
Expand Down
10 changes: 2 additions & 8 deletions src/driver/aurora-mysql/AuroraMysqlDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,7 @@ export class AuroraMysqlDriver implements Driver {
value,
)

if (
!this.options.formatOptions ||
this.options.formatOptions.castParameters !== false
) {
if (this.options.formatOptions?.castParameters !== false) {
return this.client.preparePersistentValue(value, columnMetadata)
}

Expand Down Expand Up @@ -602,10 +599,7 @@ export class AuroraMysqlDriver implements Driver {
)
: value

if (
!this.options.formatOptions ||
this.options.formatOptions.castParameters !== false
) {
if (this.options.formatOptions?.castParameters !== false) {
return this.client.prepareHydratedValue(value, columnMetadata)
}

Expand Down
5 changes: 2 additions & 3 deletions src/driver/aurora-mysql/AuroraMysqlQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ export class AuroraMysqlQueryRunner
*/
protected async loadTables(tableNames?: string[]): Promise<Table[]> {
// if no tables given then no need to proceed
if (tableNames && tableNames.length === 0) {
if (tableNames?.length === 0) {
return []
}

Expand Down Expand Up @@ -2334,8 +2334,7 @@ export class AuroraMysqlQueryRunner
)
const hasIgnoredIndex =
columnUniqueIndices.length > 0 &&
tableMetadata &&
tableMetadata.indices.some((index) => {
tableMetadata?.indices.some((index) => {
return columnUniqueIndices.some((uniqueIndex) => {
return (
index.name === uniqueIndex["INDEX_NAME"] &&
Expand Down
10 changes: 2 additions & 8 deletions src/driver/aurora-postgres/AuroraPostgresDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ export class AuroraPostgresDriver extends PostgresWrapper {
* @param columnMetadata
*/
preparePersistentValue(value: any, columnMetadata: ColumnMetadata): any {
if (
this.options.formatOptions &&
this.options.formatOptions.castParameters === false
) {
if (this.options.formatOptions?.castParameters === false) {
return super.preparePersistentValue(value, columnMetadata)
}

Expand All @@ -140,10 +137,7 @@ export class AuroraPostgresDriver extends PostgresWrapper {
* @param columnMetadata
*/
prepareHydratedValue(value: any, columnMetadata: ColumnMetadata): any {
if (
this.options.formatOptions &&
this.options.formatOptions.castParameters === false
) {
if (this.options.formatOptions?.castParameters === false) {
return super.prepareHydratedValue(value, columnMetadata)
}

Expand Down
4 changes: 2 additions & 2 deletions src/driver/cockroachdb/CockroachQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3193,7 +3193,7 @@ export class CockroachQueryRunner
*/
protected async loadTables(tableNames?: string[]): Promise<Table[]> {
// if no tables given then no need to proceed
if (tableNames && tableNames.length === 0) {
if (tableNames?.length === 0) {
return []
}

Expand Down Expand Up @@ -3636,7 +3636,7 @@ export class CockroachQueryRunner
asExpressionQuery.query,
asExpressionQuery.parameters,
)
if (results[0] && results[0].value) {
if (results[0]?.value) {
tableColumn.asExpression = results[0].value
} else {
tableColumn.asExpression = ""
Expand Down
Loading
Loading