Merge pull request #75 from overleaf/jpa-bulk-dependency-upgrades

[misc] bulk dependency upgrades
This commit is contained in:
Jakob Ackermann 2021-07-13 16:22:47 +02:00 committed by GitHub
commit 207971d470
21 changed files with 1309 additions and 2390 deletions

View file

@ -3,9 +3,9 @@
// https://github.com/sharelatex/sharelatex-dev-environment
{
"extends": [
"eslint:recommended",
"standard",
"prettier",
"prettier/standard"
"prettier"
],
"parserOptions": {
"ecmaVersion": 2018
@ -20,6 +20,19 @@
"mocha": true
},
"rules": {
// TODO(das7pad): remove overrides after fixing all the violations manually (https://github.com/overleaf/issues/issues/3882#issuecomment-878999671)
// START of temporary overrides
"array-callback-return": "off",
"no-dupe-else-if": "off",
"no-var": "off",
"no-empty": "off",
"node/handle-callback-err": "off",
"no-loss-of-precision": "off",
"node/no-callback-literal": "off",
"node/no-path-concat": "off",
"prefer-regex-literals": "off",
// END of temporary overrides
// Swap the no-unused-expressions rule with a more chai-friendly one
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": "error",

View file

@ -20,4 +20,4 @@ updates:
# future if we reorganise teams
labels:
- "dependencies"
- "Team-Magma"
- "type:maintenance"

View file

@ -1 +1 @@
12.21.0
12.22.3

View file

@ -2,6 +2,10 @@
# Instead run bin/update_build_scripts from
# https://github.com/sharelatex/sharelatex-dev-environment
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false
}

View file

@ -2,7 +2,7 @@
# Instead run bin/update_build_scripts from
# https://github.com/sharelatex/sharelatex-dev-environment
FROM node:12.21.0 as base
FROM node:12.22.3 as base
WORKDIR /app

View file

@ -6,7 +6,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const logger = require('logger-sharelatex')
const settings = require('settings-sharelatex')
const settings = require('@overleaf/settings')
const mongodb = require('./app/js/mongodb')
const Server = require('./app/js/server')
@ -16,12 +16,12 @@ if (!module.parent) {
const port =
__guard__(
settings.internal != null ? settings.internal.chat : undefined,
(x) => x.port
x => x.port
) || 3010
const host =
__guard__(
settings.internal != null ? settings.internal.chat : undefined,
(x1) => x1.host
x1 => x1.host
) || 'localhost'
mongodb
.waitForDb()
@ -34,7 +34,7 @@ if (!module.parent) {
return logger.info(`Chat starting up, listening on ${host}:${port}`)
})
})
.catch((err) => {
.catch(err => {
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
process.exit(1)
})

View file

@ -22,7 +22,7 @@ module.exports = MessageFormatter = {
id: message.id,
content: message.content,
timestamp: message.timestamp,
user_id: message.user_id
user_id: message.user_id,
}
if (message.edited_at != null) {
formattedMessage.edited_at = message.edited_at
@ -31,7 +31,7 @@ module.exports = MessageFormatter = {
},
formatMessagesForClientSide(messages) {
return Array.from(messages).map((message) =>
return Array.from(messages).map(message =>
this.formatMessageForClientSide(message)
)
},
@ -76,5 +76,5 @@ module.exports = MessageFormatter = {
}
return threads
}
},
}

View file

@ -53,25 +53,28 @@ module.exports = MessageHttpController = {
getAllThreads(req, res, next) {
const { project_id } = req.params
logger.log({ project_id }, 'getting all threads')
return ThreadManager.findAllThreadRooms(project_id, function (
error,
rooms
) {
if (error != null) {
return next(error)
}
const room_ids = rooms.map((r) => r._id)
return MessageManager.findAllMessagesInRooms(room_ids, function (
error,
messages
) {
return ThreadManager.findAllThreadRooms(
project_id,
function (error, rooms) {
if (error != null) {
return next(error)
}
const threads = MessageFormatter.groupMessagesByThreads(rooms, messages)
return res.json(threads)
})
})
const room_ids = rooms.map(r => r._id)
return MessageManager.findAllMessagesInRooms(
room_ids,
function (error, messages) {
if (error != null) {
return next(error)
}
const threads = MessageFormatter.groupMessagesByThreads(
rooms,
messages
)
return res.json(threads)
}
)
}
)
},
resolveThread(req, res, next) {
@ -105,20 +108,24 @@ module.exports = MessageHttpController = {
deleteThread(req, res, next) {
const { project_id, thread_id } = req.params
logger.log({ project_id, thread_id }, 'deleting thread')
return ThreadManager.deleteThread(project_id, thread_id, function (
error,
room_id
) {
if (error != null) {
return next(error)
}
return MessageManager.deleteAllMessagesInRoom(room_id, function (error) {
return ThreadManager.deleteThread(
project_id,
thread_id,
function (error, room_id) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
})
})
return MessageManager.deleteAllMessagesInRoom(
room_id,
function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
}
)
}
)
}, // No content
editMessage(req, res, next) {
@ -128,48 +135,51 @@ module.exports = MessageHttpController = {
{ project_id, thread_id, message_id, content },
'editing message'
)
return ThreadManager.findOrCreateThread(project_id, thread_id, function (
error,
room
) {
if (error != null) {
return next(error)
}
return MessageManager.updateMessage(
room._id,
message_id,
content,
Date.now(),
function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
return ThreadManager.findOrCreateThread(
project_id,
thread_id,
function (error, room) {
if (error != null) {
return next(error)
}
)
})
return MessageManager.updateMessage(
room._id,
message_id,
content,
Date.now(),
function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
}
)
}
)
},
deleteMessage(req, res, next) {
const { project_id, thread_id, message_id } = req.params
logger.log({ project_id, thread_id, message_id }, 'deleting message')
return ThreadManager.findOrCreateThread(project_id, thread_id, function (
error,
room
) {
if (error != null) {
return next(error)
}
return MessageManager.deleteMessage(room._id, message_id, function (
error,
message
) {
return ThreadManager.findOrCreateThread(
project_id,
thread_id,
function (error, room) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
})
})
return MessageManager.deleteMessage(
room._id,
message_id,
function (error, message) {
if (error != null) {
return next(error)
}
return res.sendStatus(204)
}
)
}
)
},
_sendMessage(client_thread_id, req, res, next) {
@ -259,5 +269,5 @@ module.exports = MessageHttpController = {
)
}
)
}
},
}

View file

@ -26,7 +26,7 @@ module.exports = MessageManager = {
content,
room_id,
user_id,
timestamp
timestamp,
}
newMessageOpts = this._ensureIdsAreObjectIds(newMessageOpts)
db.messages.insertOne(newMessageOpts, function (error, confirmation) {
@ -60,7 +60,7 @@ module.exports = MessageManager = {
}
db.messages
.find({
room_id: { $in: room_ids }
room_id: { $in: room_ids },
})
.toArray(callback)
},
@ -71,7 +71,7 @@ module.exports = MessageManager = {
}
db.messages.deleteMany(
{
room_id
room_id,
},
callback
)
@ -83,15 +83,15 @@ module.exports = MessageManager = {
}
const query = this._ensureIdsAreObjectIds({
_id: message_id,
room_id
room_id,
})
db.messages.updateOne(
query,
{
$set: {
content,
edited_at: timestamp
}
edited_at: timestamp,
},
},
callback
)
@ -103,7 +103,7 @@ module.exports = MessageManager = {
}
const query = this._ensureIdsAreObjectIds({
_id: message_id,
room_id
room_id,
})
db.messages.deleteOne(query, callback)
},
@ -119,15 +119,15 @@ module.exports = MessageManager = {
query._id = ObjectId(query._id)
}
return query
}
},
}
;[
'createMessage',
'getMessages',
'findAllMessagesInRooms',
'updateMessage',
'deleteMessage'
].map((method) =>
'deleteMessage',
].map(method =>
metrics.timeAsyncMethod(
MessageManager,
method,

View file

@ -32,30 +32,33 @@ module.exports = ThreadManager = {
if (thread_id === ThreadManager.GLOBAL_THREAD) {
query = {
project_id,
thread_id: { $exists: false }
thread_id: { $exists: false },
}
update = {
project_id
project_id,
}
} else {
query = {
project_id,
thread_id
thread_id,
}
update = {
project_id,
thread_id
thread_id,
}
}
db.rooms.updateOne(query, { $set: update }, { upsert: true }, function (
error
) {
if (error != null) {
return callback(error)
db.rooms.updateOne(
query,
{ $set: update },
{ upsert: true },
function (error) {
if (error != null) {
return callback(error)
}
db.rooms.findOne(query, callback)
}
db.rooms.findOne(query, callback)
})
)
},
findAllThreadRooms(project_id, callback) {
@ -66,11 +69,11 @@ module.exports = ThreadManager = {
.find(
{
project_id: ObjectId(project_id.toString()),
thread_id: { $exists: true }
thread_id: { $exists: true },
},
{
thread_id: 1,
resolved: 1
resolved: 1,
}
)
.toArray(callback)
@ -83,15 +86,15 @@ module.exports = ThreadManager = {
db.rooms.updateOne(
{
project_id: ObjectId(project_id.toString()),
thread_id: ObjectId(thread_id.toString())
thread_id: ObjectId(thread_id.toString()),
},
{
$set: {
resolved: {
user_id,
ts: new Date()
}
}
ts: new Date(),
},
},
},
callback
)
@ -104,12 +107,12 @@ module.exports = ThreadManager = {
db.rooms.updateOne(
{
project_id: ObjectId(project_id.toString()),
thread_id: ObjectId(thread_id.toString())
thread_id: ObjectId(thread_id.toString()),
},
{
$unset: {
resolved: true
}
resolved: true,
},
},
callback
)
@ -119,33 +122,34 @@ module.exports = ThreadManager = {
if (callback == null) {
callback = function (error, room_id) {}
}
return this.findOrCreateThread(project_id, thread_id, function (
error,
room
) {
if (error != null) {
return callback(error)
}
db.rooms.deleteOne(
{
_id: room._id
},
function (error) {
if (error != null) {
return callback(error)
}
return callback(null, room._id)
return this.findOrCreateThread(
project_id,
thread_id,
function (error, room) {
if (error != null) {
return callback(error)
}
)
})
}
db.rooms.deleteOne(
{
_id: room._id,
},
function (error) {
if (error != null) {
return callback(error)
}
return callback(null, room._id)
}
)
}
)
},
}
;[
'findOrCreateThread',
'findAllThreadRooms',
'resolveThread',
'reopenThread',
'deleteThread'
].map((method) =>
'deleteThread',
].map(method =>
metrics.timeAsyncMethod(ThreadManager, method, 'mongo.ThreadManager', logger)
)

View file

@ -1,4 +1,4 @@
const Settings = require('settings-sharelatex')
const Settings = require('@overleaf/settings')
const { MongoClient, ObjectId } = require('mongodb')
const clientPromise = MongoClient.connect(
@ -25,5 +25,5 @@ async function setupDb() {
module.exports = {
db,
ObjectId,
waitForDb
waitForDb,
}

View file

@ -80,5 +80,5 @@ module.exports = Router = {
)
return app.get('/status', (req, res, next) => res.send('chat is alive'))
}
},
}

View file

@ -37,5 +37,5 @@ Router.route(app)
module.exports = {
server,
app
app,
}

View file

@ -3,6 +3,6 @@ chat
--docker-repos=gcr.io/overleaf-ops
--env-add=
--env-pass-through=
--node-version=12.21.0
--node-version=12.22.3
--public-repo=False
--script-version=3.8.0
--script-version=3.11.0

View file

@ -2,8 +2,8 @@ module.exports = {
internal: {
chat: {
host: process.env.LISTEN_ADDRESS || 'localhost',
port: 3010
}
port: 3010,
},
},
apis: {
@ -12,17 +12,17 @@ module.exports = {
process.env.WEB_PORT || 3000
}`,
user: process.env.WEB_API_USER || 'sharelatex',
pass: process.env.WEB_API_PASSWORD || 'password'
}
pass: process.env.WEB_API_PASSWORD || 'password',
},
},
mongo: {
options: {
useUnifiedTopology:
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true'
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
},
url:
process.env.MONGO_CONNECTION_STRING ||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`
}
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
},
}

View file

@ -6,7 +6,7 @@ version: "2.3"
services:
test_unit:
image: node:12.21.0
image: node:12.22.3
volumes:
- .:/app
working_dir: /app
@ -18,7 +18,7 @@ services:
user: node
test_acceptance:
image: node:12.21.0
image: node:12.22.3
volumes:
- .:/app
working_dir: /app

File diff suppressed because it is too large Load diff

View file

@ -13,41 +13,41 @@
"nodemon": "nodemon --config nodemon.json",
"test:acceptance:_run": "mocha --recursive --reporter spec --timeout 15000 --exit $@ test/acceptance/js",
"test:unit:_run": "mocha --recursive --reporter spec $@ test/unit/js",
"lint": "node_modules/.bin/eslint --max-warnings 0 .",
"format": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --list-different",
"format:fix": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --write"
"lint": "eslint --max-warnings 0 --format unix .",
"format": "prettier --list-different $PWD/'**/*.js'",
"format:fix": "prettier --write $PWD/'**/*.js'",
"lint:fix": "eslint --fix ."
},
"dependencies": {
"@overleaf/metrics": "^3.5.1",
"@overleaf/settings": "^2.1.1",
"async": "3.2.0",
"body-parser": "^1.19.0",
"bunyan": "^1.8.15",
"errorhandler": "^1.5.1",
"express": "4.17.1",
"logger-sharelatex": "^2.2.0",
"mongodb": "^3.6.0",
"request": "^2.88.2",
"settings-sharelatex": "^1.1.0"
"request": "^2.88.2"
},
"devDependencies": {
"acorn": "^7.1.1",
"ajv": "^6.12.0",
"bunyan": "^1.8.12",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-chai-expect": "^2.1.0",
"eslint-plugin-chai-friendly": "^0.5.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-node": "^11.0.0",
"chai-as-promised": "^7.1.1",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-chai-expect": "^2.2.0",
"eslint-plugin-chai-friendly": "^0.6.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.0",
"mocha": "^8.3.2",
"nodemon": "^2.0.2",
"prettier": "^2.0.0",
"prettier-eslint-cli": "^5.0.0",
"prettier": "^2.2.1",
"sandboxed-module": "^2.0.3",
"sinon": "^9.0.0",
"timekeeper": "^2.2.0"

View file

@ -32,20 +32,20 @@ describe('Getting messages', function () {
this.project_id = ObjectId().toString()
return async.series(
[
(cb) =>
cb =>
ChatClient.sendGlobalMessage(
this.project_id,
this.user_id1,
this.content1,
cb
),
(cb) =>
cb =>
ChatClient.sendGlobalMessage(
this.project_id,
this.user_id2,
this.content2,
cb
)
),
],
done
)
@ -74,7 +74,7 @@ describe('Getting messages', function () {
this.thread_id2 = ObjectId().toString()
return async.series(
[
(cb) =>
cb =>
ChatClient.sendMessage(
this.project_id,
this.thread_id1,
@ -82,7 +82,7 @@ describe('Getting messages', function () {
'one',
cb
),
(cb) =>
cb =>
ChatClient.sendMessage(
this.project_id,
this.thread_id2,
@ -90,7 +90,7 @@ describe('Getting messages', function () {
'two',
cb
),
(cb) =>
cb =>
ChatClient.sendMessage(
this.project_id,
this.thread_id1,
@ -98,14 +98,14 @@ describe('Getting messages', function () {
'three',
cb
),
(cb) =>
cb =>
ChatClient.sendMessage(
this.project_id,
this.thread_id2,
this.user_id2,
'four',
cb
)
),
],
done
)

View file

@ -30,7 +30,7 @@ module.exports = {
this.initing = true
this.callbacks.push(callback)
waitForDb().then(() => {
return app.listen(3010, 'localhost', (error) => {
return app.listen(3010, 'localhost', error => {
if (error != null) {
throw error
}
@ -44,5 +44,5 @@ module.exports = {
})()
})
})
}
},
}

View file

@ -10,7 +10,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const request = require('request').defaults({
baseUrl: 'http://localhost:3010'
baseUrl: 'http://localhost:3010',
})
module.exports = {
@ -20,8 +20,8 @@ module.exports = {
url: `/project/${project_id}/messages`,
json: {
user_id,
content
}
content,
},
},
callback
)
@ -31,7 +31,7 @@ module.exports = {
return request.get(
{
url: `/project/${project_id}/messages`,
json: true
json: true,
},
callback
)
@ -43,8 +43,8 @@ module.exports = {
url: `/project/${project_id}/thread/${thread_id}/messages`,
json: {
user_id,
content
}
content,
},
},
callback
)
@ -54,7 +54,7 @@ module.exports = {
return request.get(
{
url: `/project/${project_id}/threads`,
json: true
json: true,
},
callback
)
@ -65,8 +65,8 @@ module.exports = {
{
url: `/project/${project_id}/thread/${thread_id}/resolve`,
json: {
user_id
}
user_id,
},
},
callback
)
@ -75,7 +75,7 @@ module.exports = {
reopenThread(project_id, thread_id, callback) {
return request.post(
{
url: `/project/${project_id}/thread/${thread_id}/reopen`
url: `/project/${project_id}/thread/${thread_id}/reopen`,
},
callback
)
@ -84,7 +84,7 @@ module.exports = {
deleteThread(project_id, thread_id, callback) {
return request.del(
{
url: `/project/${project_id}/thread/${thread_id}`
url: `/project/${project_id}/thread/${thread_id}`,
},
callback
)
@ -95,8 +95,8 @@ module.exports = {
{
url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}/edit`,
json: {
content
}
content,
},
},
callback
)
@ -105,9 +105,9 @@ module.exports = {
deleteMessage(project_id, thread_id, message_id, callback) {
return request.del(
{
url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}`
url: `/project/${project_id}/thread/${thread_id}/messages/${message_id}`,
},
callback
)
}
},
}