fix(api): resolve lint errors
This commit is contained in:
1 parent
96fede9fe5
commit
fd1fa2366c
42 files changed
+307
-199
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { DynamicModule, Module } from '@nestjs/common';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConnectionService } from './connection.service';
|
||||
|
||||
@Module({
|
||||
|
||||
@@ -330,6 +330,9 @@ function legacyAuctionLifecycleId(value: unknown): string {
|
||||
|
||||
function stringifyId(value: unknown): string | undefined {
|
||||
if (value === undefined || value === null) return undefined;
|
||||
// MongoDB ObjectId and migration fixture IDs intentionally rely on their
|
||||
// stable string representation.
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
return typeof value === 'string' ? value : String(value);
|
||||
}
|
||||
|
||||
|
||||
+14
-16
@@ -1,11 +1,4 @@
|
||||
type TournamentCodeState =
|
||||
| 'available'
|
||||
| 'reserved'
|
||||
| 'used'
|
||||
| 'released'
|
||||
| 'expired'
|
||||
| 'voided'
|
||||
| string;
|
||||
type TournamentCodeState = string;
|
||||
|
||||
type AnyDoc = Record<string, unknown> & { _id: unknown };
|
||||
type IndexKey = Record<string, 1 | -1>;
|
||||
@@ -36,7 +29,7 @@ interface MigrationCollection {
|
||||
$unset?: Record<string, ''>;
|
||||
},
|
||||
options?: { ordered?: boolean },
|
||||
): Promise<{ matchedCount?: number; modifiedCount?: number } | unknown>;
|
||||
): Promise<unknown>;
|
||||
indexes?(): Promise<MigrationIndex[]>;
|
||||
dropIndex?(name: string): Promise<unknown>;
|
||||
createIndex?(
|
||||
@@ -516,15 +509,17 @@ function summarizeGroups(
|
||||
function summarizeCode(doc: TournamentCodeDoc): TournamentCodeDuplicateSummary {
|
||||
return {
|
||||
bracketMatchId:
|
||||
doc.bracketMatchId === undefined ? undefined : String(doc.bracketMatchId),
|
||||
code: doc.code === undefined ? undefined : String(doc.code),
|
||||
doc.bracketMatchId === undefined
|
||||
? undefined
|
||||
: stringifyId(doc.bracketMatchId),
|
||||
code: doc.code === undefined ? undefined : stringifyId(doc.code),
|
||||
gameNumber:
|
||||
doc.gameNumber === undefined ? undefined : String(doc.gameNumber),
|
||||
doc.gameNumber === undefined ? undefined : stringifyId(doc.gameNumber),
|
||||
id: stringifyId(doc._id) ?? '',
|
||||
matchId: doc.matchId === undefined ? undefined : stringifyId(doc.matchId),
|
||||
riotMatchId:
|
||||
doc.riotMatchId === undefined ? undefined : String(doc.riotMatchId),
|
||||
state: doc.state === undefined ? undefined : String(doc.state),
|
||||
doc.riotMatchId === undefined ? undefined : stringifyId(doc.riotMatchId),
|
||||
state: doc.state,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -749,16 +744,19 @@ function readModifiedCount(result: unknown): number {
|
||||
}
|
||||
|
||||
function hasField(doc: Record<string, unknown>, key: string): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(doc, key);
|
||||
return Object.hasOwn(doc, key);
|
||||
}
|
||||
|
||||
function stringifyKeyPart(value: unknown): string {
|
||||
if (value === null) return '<null>';
|
||||
if (value === undefined) return '<undefined>';
|
||||
return stringifyId(value) ?? String(value);
|
||||
return stringifyId(value) ?? '<unknown>';
|
||||
}
|
||||
|
||||
function stringifyId(value: unknown): string | undefined {
|
||||
if (value === undefined || value === null) return undefined;
|
||||
// MongoDB ObjectId and migration fixture IDs intentionally rely on their
|
||||
// stable string representation.
|
||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
||||
return typeof value === 'string' ? value : String(value);
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import fs from 'fs/promises';
|
||||
import { connect } from 'nats';
|
||||
import type { NatsConnection } from 'nats';
|
||||
import { SecretModule } from '../secret/secret.module';
|
||||
|
||||
@@ -38,27 +38,24 @@ export function applyMongoosePerformancePlugin(schema: mongoose.Schema): void {
|
||||
const markedSchema = schema as SchemaWithPerformanceMarker;
|
||||
if (markedSchema[PERFORMANCE_PLUGIN_APPLIED]) return;
|
||||
markedSchema[PERFORMANCE_PLUGIN_APPLIED] = true;
|
||||
const hookableSchema = schema as any;
|
||||
|
||||
hookableSchema.pre(QUERY_OPERATION_REGEX, function () {
|
||||
schema.pre(QUERY_OPERATION_REGEX, function () {
|
||||
const query = this as QueryWithPerformanceState;
|
||||
query[QUERY_PERFORMANCE_START] = process.hrtime.bigint();
|
||||
query[QUERY_PERFORMANCE_RECORDED] = false;
|
||||
});
|
||||
|
||||
hookableSchema.post(QUERY_OPERATION_REGEX, function (result: unknown) {
|
||||
recordQueryPerformance(
|
||||
this as unknown as QueryWithPerformanceState,
|
||||
result,
|
||||
);
|
||||
schema.post(QUERY_OPERATION_REGEX, function (result: unknown) {
|
||||
recordQueryPerformance(this as QueryWithPerformanceState, result);
|
||||
});
|
||||
|
||||
hookableSchema.post(
|
||||
schema.post(
|
||||
QUERY_OPERATION_REGEX,
|
||||
{ errorHandler: true },
|
||||
function (
|
||||
error: unknown,
|
||||
error: Error,
|
||||
_result: unknown,
|
||||
next: (error: unknown) => void,
|
||||
next: (error?: mongoose.CallbackError) => void,
|
||||
) {
|
||||
recordQueryPerformance(
|
||||
this as unknown as QueryWithPerformanceState,
|
||||
@@ -69,22 +66,23 @@ export function applyMongoosePerformancePlugin(schema: mongoose.Schema): void {
|
||||
},
|
||||
);
|
||||
|
||||
hookableSchema.pre('aggregate', function () {
|
||||
schema.pre('aggregate', function () {
|
||||
const aggregate = this as AggregateWithPerformanceState;
|
||||
aggregate[QUERY_PERFORMANCE_START] = process.hrtime.bigint();
|
||||
aggregate[QUERY_PERFORMANCE_RECORDED] = false;
|
||||
});
|
||||
|
||||
hookableSchema.post('aggregate', function (result: unknown) {
|
||||
schema.post('aggregate', function (result: unknown) {
|
||||
recordAggregatePerformance(this as AggregateWithPerformanceState, result);
|
||||
});
|
||||
|
||||
hookableSchema.post(
|
||||
schema.post(
|
||||
'aggregate',
|
||||
{ errorHandler: true },
|
||||
function (
|
||||
error: unknown,
|
||||
error: Error,
|
||||
_result: unknown,
|
||||
next: (error: unknown) => void,
|
||||
next: (error?: mongoose.CallbackError) => void,
|
||||
) {
|
||||
recordAggregatePerformance(
|
||||
this as AggregateWithPerformanceState,
|
||||
|
||||
@@ -56,16 +56,11 @@ export class DistributedLockService {
|
||||
const lockOwnershipToken = options.lockOwnershipToken ?? randomUUID();
|
||||
const result = await this.redisService
|
||||
.raw()
|
||||
.sendCommand([
|
||||
'SET',
|
||||
options.lockKey,
|
||||
lockOwnershipToken,
|
||||
'NX',
|
||||
'PX',
|
||||
String(options.lockExpirationDurationMilliseconds),
|
||||
]);
|
||||
.sendCommand<
|
||||
string | null
|
||||
>(['SET', options.lockKey, lockOwnershipToken, 'NX', 'PX', String(options.lockExpirationDurationMilliseconds)]);
|
||||
|
||||
if (String(result) !== 'OK') return null;
|
||||
if (result !== 'OK') return null;
|
||||
return {
|
||||
lockKey: options.lockKey,
|
||||
lockOwnershipToken,
|
||||
@@ -124,7 +119,7 @@ export class DistributedLockService {
|
||||
await this.releaseLockIfOwned(lockOwnership).catch((error: unknown) => {
|
||||
this.logger.warn(
|
||||
`Failed to release distributed lock ${lockOwnership.lockKey}: ${
|
||||
error instanceof Error ? error.message : error
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
);
|
||||
});
|
||||
@@ -143,8 +138,7 @@ export class DistributedLockService {
|
||||
const lockOwnership = await this.acquireLockWithRetry(options);
|
||||
if (!lockOwnership) return null;
|
||||
|
||||
let lockRenewalTimer: NodeJS.Timeout | undefined;
|
||||
lockRenewalTimer = setInterval(() => {
|
||||
const lockRenewalTimer = setInterval(() => {
|
||||
void this.extendLockIfOwned(lockOwnership).then((wasExtended) => {
|
||||
if (wasExtended) return;
|
||||
this.logger.warn(
|
||||
@@ -157,11 +151,11 @@ export class DistributedLockService {
|
||||
try {
|
||||
return await operation(lockOwnership);
|
||||
} finally {
|
||||
if (lockRenewalTimer) clearInterval(lockRenewalTimer);
|
||||
clearInterval(lockRenewalTimer);
|
||||
await this.releaseLockIfOwned(lockOwnership).catch((error: unknown) => {
|
||||
this.logger.warn(
|
||||
`Failed to release distributed lock ${lockOwnership.lockKey}: ${
|
||||
error instanceof Error ? error.message : error
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -54,8 +54,12 @@ async function readFirstSecret(
|
||||
}),
|
||||
);
|
||||
|
||||
client.on('error', (error) => {
|
||||
logger.error(`Redis client error: ${error?.message ?? error}`);
|
||||
client.on('error', (error: unknown) => {
|
||||
logger.error(
|
||||
`Redis client error: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
);
|
||||
});
|
||||
|
||||
await client.connect();
|
||||
|
||||
@@ -35,11 +35,14 @@ interface RawStreamReadResult {
|
||||
|
||||
function normalizeStreamFields(fields: unknown): Record<string, string> {
|
||||
if (Array.isArray(fields)) {
|
||||
const values = fields as unknown[];
|
||||
const normalized: Record<string, string> = {};
|
||||
for (let index = 0; index < fields.length; index += 2) {
|
||||
const key = fields[index];
|
||||
for (let index = 0; index < values.length; index += 2) {
|
||||
const key = values[index];
|
||||
if (key === undefined) continue;
|
||||
normalized[String(key)] = String(fields[index + 1] ?? '');
|
||||
normalized[redisValueToString(key)] = redisValueToString(
|
||||
values[index + 1],
|
||||
);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
@@ -260,10 +263,10 @@ export class RedisService implements OnModuleDestroy {
|
||||
rawMessage: unknown,
|
||||
): StreamEntry | null {
|
||||
if (Array.isArray(rawMessage)) {
|
||||
const [id, fields] = rawMessage;
|
||||
const [id, fields] = rawMessage as unknown[];
|
||||
if (id === undefined) return null;
|
||||
return {
|
||||
id: String(id),
|
||||
id: redisValueToString(id),
|
||||
message: normalizeStreamFields(fields),
|
||||
};
|
||||
}
|
||||
@@ -291,3 +294,17 @@ export class RedisService implements OnModuleDestroy {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function redisValueToString(value: unknown): string {
|
||||
if (typeof value === 'string') return value;
|
||||
if (
|
||||
typeof value === 'number' ||
|
||||
typeof value === 'boolean' ||
|
||||
typeof value === 'bigint'
|
||||
) {
|
||||
return String(value);
|
||||
}
|
||||
if (Buffer.isBuffer(value)) return value.toString('utf8');
|
||||
if (value === undefined || value === null) return '';
|
||||
return JSON.stringify(value) ?? '';
|
||||
}
|
||||
Reference in new issue
Block a user