Merge pull request #9020 from overleaf/bg-decaff-guard

decaff cleanup of __guard__ calls

GitOrigin-RevId: 0d61e4d44a2fda19285674040ba92e500deae78d
This commit is contained in:
Brian Gough 2022-07-28 09:23:50 +01:00 committed by Copybot
parent ac9cd2c96b
commit 8960e56e20
10 changed files with 13 additions and 133 deletions

View file

@ -10,7 +10,6 @@
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -85,9 +84,3 @@ module.exports = ForbidSymlinks = function (staticFn, root, options) {
})
}
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -6,7 +6,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -73,12 +72,7 @@ module.exports = HistoryManager = {
// flush changes in the background
flushProjectChangesAsync(project_id) {
if (
!__guard__(
Settings.apis != null ? Settings.apis.project_history : undefined,
x => x.enabled
)
) {
if (!Settings.apis?.project_history?.enabled) {
return
}
return HistoryManager.flushProjectChanges(
@ -93,12 +87,7 @@ module.exports = HistoryManager = {
if (callback == null) {
callback = function () {}
}
if (
!__guard__(
Settings.apis != null ? Settings.apis.project_history : undefined,
x => x.enabled
)
) {
if (!Settings.apis?.project_history?.enabled) {
return callback()
}
if (options.skip_history_flush) {
@ -153,12 +142,7 @@ module.exports = HistoryManager = {
}
// record updates for project history
if (
__guard__(
Settings.apis != null ? Settings.apis.project_history : undefined,
x => x.enabled
)
) {
if (Settings.apis?.project_history?.enabled) {
if (
HistoryManager.shouldFlushHistoryOps(
project_ops_length,
@ -260,9 +244,3 @@ module.exports = HistoryManager = {
)
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -6,7 +6,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -24,22 +23,13 @@ const showUpdateLength = function (update) {
if ((update != null ? update.op : undefined) instanceof Array) {
const copy = _.cloneDeep(update)
copy.op.forEach(function (element, index) {
if (
__guard__(element != null ? element.i : undefined, x => x.length) !=
null
) {
if (element?.i?.length != null) {
copy.op[index].i = element.i.length
}
if (
__guard__(element != null ? element.d : undefined, x1 => x1.length) !=
null
) {
if (element?.d?.length != null) {
copy.op[index].d = element.d.length
}
if (
__guard__(element != null ? element.c : undefined, x2 => x2.length) !=
null
) {
if (element?.c?.length != null) {
return (copy.op[index].c = element.c.length)
}
})
@ -59,9 +49,3 @@ module.exports = {
ranges: showLength,
update: showUpdateLength,
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -7,17 +7,13 @@
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS201: Simplify complex destructure assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let ProjectHistoryRedisManager
const Settings = require('@overleaf/settings')
const projectHistoryKeys = __guard__(
Settings.redis != null ? Settings.redis.project_history : undefined,
x => x.key_schema
)
const projectHistoryKeys = Settings.redis?.project_history?.key_schema
const rclient = require('@overleaf/redis-wrapper').createClient(
Settings.redis.project_history
)
@ -176,9 +172,3 @@ module.exports = ProjectHistoryRedisManager = {
return ProjectHistoryRedisManager.queueOps(project_id, jsonUpdate, callback)
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -9,7 +9,6 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -93,12 +92,7 @@ module.exports = UpdateCompressor = {
},
compressRawUpdates(lastPreviousUpdate, rawUpdates) {
if (
__guard__(
lastPreviousUpdate != null ? lastPreviousUpdate.op : undefined,
x => x.length
) > 1
) {
if (lastPreviousUpdate?.op?.length > 1) {
// if the last previous update was an array op, don't compress onto it.
// The avoids cases where array length changes but version number doesn't
return [lastPreviousUpdate].concat(
@ -331,9 +325,3 @@ module.exports = UpdateCompressor = {
return ops
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -7,7 +7,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -37,12 +36,7 @@ module.exports = UpdateTrimmer = {
return callback(error)
}
logger.debug({ project_id, details }, 'got details')
if (
__guard__(
details != null ? details.features : undefined,
x => x.versioning
)
) {
if (details?.features?.versioning) {
return MongoManager.setProjectMetaData(
project_id,
{ preserveHistory: true },
@ -71,9 +65,3 @@ module.exports = UpdateTrimmer = {
)
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -99,12 +99,7 @@ module.exports = UpdatesManager = {
}
if (rawUpdates[0] != null && rawUpdates[0].v !== lastVersion + 1) {
const ts = __guard__(
lastCompressedUpdate != null
? lastCompressedUpdate.meta
: undefined,
x1 => x1.end_ts
)
const ts = lastCompressedUpdate?.meta?.end_ts
const last_timestamp = ts != null ? new Date(ts) : 'unknown time'
error = new Error(
`Tried to apply raw op at version ${rawUpdates[0].v} to last compressed update with version ${lastVersion} from ${last_timestamp}`

View file

@ -9,7 +9,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -133,10 +132,7 @@ module.exports = ExportsHandler = {
project: {
id: project_id,
rootDocPath: rootDoc[1] != null ? rootDoc[1].fileSystem : undefined,
historyId: __guard__(
project.overleaf != null ? project.overleaf.history : undefined,
x => x.id
),
historyId: project.overleaf?.history?.id,
historyVersion,
v1ProjectId:
project.overleaf != null ? project.overleaf.id : undefined,
@ -287,9 +283,3 @@ module.exports = ExportsHandler = {
)
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}

View file

@ -9,7 +9,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -56,16 +55,7 @@ const ProjectHistoryHandler = {
if (err != null) {
return callback(err)
} // n.b. getDetails returns an error if the project doesn't exist
return callback(
null,
__guard__(
__guard__(
project != null ? project.overleaf : undefined,
x1 => x1.history
),
x => x.id
)
)
return callback(null, project?.overleaf?.history?.id)
}
)
},
@ -195,11 +185,5 @@ const ProjectHistoryHandler = {
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}
ProjectHistoryHandler.promises = promisifyAll(ProjectHistoryHandler)
module.exports = ProjectHistoryHandler

View file

@ -8,7 +8,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@ -41,10 +40,7 @@ module.exports = V1Handler = {
{
email,
isValid,
v1UserId: __guard__(
body != null ? body.user_profile : undefined,
x => x.id
),
v1UserId: body?.user_profile?.id,
},
'[V1Handler] got response from v1 login api'
)
@ -93,9 +89,3 @@ module.exports = V1Handler = {
)
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}