Merge pull request #18289 from overleaf/ac-ar-eslint-return-await

Add ESLint rule @typescript-eslint/return-await to backend services

GitOrigin-RevId: 75e3e32597827fcc852e69d479515fc72e8f45e4
This commit is contained in:
Andrew Rumble
2024-05-27 10:22:49 +00:00
committed by Copybot
parent 029cd4abe7
commit 71187a51ba
43 changed files with 1180 additions and 411 deletions
@@ -42,7 +42,7 @@ module.exports = class GcsPersistor extends AbstractPersistor {
}
async sendFile(bucketName, key, fsPath) {
return this.sendStream(bucketName, key, fs.createReadStream(fsPath))
return await this.sendStream(bucketName, key, fs.createReadStream(fsPath))
}
async sendStream(bucketName, key, readStream, opts = {}) {
@@ -17,55 +17,65 @@ const { NotFoundError, WriteError } = require('./Errors')
// }
module.exports = class MigrationPersistor extends AbstractPersistor {
/**
* @param {AbstractPersistor} primaryPersistor
* @param {AbstractPersistor} fallbackPersistor
* @param settings
*/
constructor(primaryPersistor, fallbackPersistor, settings) {
super()
/**
* @type {AbstractPersistor}
*/
this.primaryPersistor = primaryPersistor
/**
* @type {AbstractPersistor}
*/
this.fallbackPersistor = fallbackPersistor
this.settings = settings
}
async sendFile(...args) {
return this.primaryPersistor.sendFile(...args)
return await this.primaryPersistor.sendFile(...args)
}
async sendStream(...args) {
return this.primaryPersistor.sendStream(...args)
return await this.primaryPersistor.sendStream(...args)
}
async getRedirectUrl(...args) {
return this.primaryPersistor.getRedirectUrl(...args)
return await this.primaryPersistor.getRedirectUrl(...args)
}
async getObjectMd5Hash(...args) {
return this._runWithFallback('getObjectMd5Hash', ...args)
return await this._runWithFallback('getObjectMd5Hash', ...args)
}
async checkIfObjectExists(...args) {
return this._runWithFallback('checkIfObjectExists', ...args)
return await this._runWithFallback('checkIfObjectExists', ...args)
}
async getObjectSize(...args) {
return this._runWithFallback('getObjectSize', ...args)
return await this._runWithFallback('getObjectSize', ...args)
}
async directorySize(...args) {
return this._runWithFallback('directorySize', ...args)
return await this._runWithFallback('directorySize', ...args)
}
async deleteObject(...args) {
return this._runOnBoth('deleteObject', ...args)
return await this._runOnBoth('deleteObject', ...args)
}
async deleteDirectory(...args) {
return this._runOnBoth('deleteDirectory', ...args)
return await this._runOnBoth('deleteDirectory', ...args)
}
async getObjectStream(bucket, key, opts = {}) {
const shouldCopy = this.settings.copyOnMiss && !opts.start && !opts.end
try {
// 'return await' so we catch NotFoundError before returning
return await this.primaryPersistor.getObjectStream(bucket, key, opts)
} catch (err) {
if (err instanceof NotFoundError) {
@@ -140,7 +150,7 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
})
}
// copy from sourceKey -> destKey
return this._copyStreamFromFallbackAndVerify(
return await this._copyStreamFromFallbackAndVerify(
copyStream,
fallbackBucket,
bucket,
@@ -217,9 +227,14 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
])
}
/**
* @param {keyof AbstractPersistor} methodName
* @param bucket
* @param key
* @param moreArgs
*/
async _runWithFallback(methodName, bucket, key, ...moreArgs) {
try {
// 'return await' so we catch NotFoundError before returning
return await this.primaryPersistor[methodName](bucket, key, ...moreArgs)
} catch (err) {
if (err instanceof NotFoundError) {
@@ -241,7 +256,7 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
Logger.warn({ err }, 'failed to copy file from fallback')
})
}
return this.fallbackPersistor[methodName](
return await this.fallbackPersistor[methodName](
fallbackBucket,
key,
...moreArgs
@@ -24,7 +24,7 @@ module.exports = class S3Persistor extends AbstractPersistor {
}
async sendFile(bucketName, key, fsPath) {
return this.sendStream(bucketName, key, fs.createReadStream(fsPath))
return await this.sendStream(bucketName, key, fs.createReadStream(fsPath))
}
async sendStream(bucketName, key, readStream, opts = {}) {
@@ -231,7 +231,7 @@ module.exports = class S3Persistor extends AbstractPersistor {
if (this.settings.Metrics) {
this.settings.Metrics.inc('s3.md5Download')
}
return PersistorHelper.calculateStreamMd5(
return await PersistorHelper.calculateStreamMd5(
await this.getObjectStream(bucketName, key)
)
} catch (err) {