diff --git a/services/track-changes/app.js b/services/track-changes/app.js index ed49af171e..8d0890e988 100644 --- a/services/track-changes/app.js +++ b/services/track-changes/app.js @@ -16,9 +16,9 @@ if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) { } // log updates as truncated strings -const truncateFn = updates => +const truncateFn = (updates) => JSON.parse( - JSON.stringify(updates, function(key, value) { + JSON.stringify(updates, function (key, value) { let len if (typeof value === 'string' && (len = value.length) > 80) { return ( @@ -46,7 +46,7 @@ const child_process = require('child_process') const HttpController = require('./app/js/HttpController') const express = require('express') -const bodyParser = require('body-parser'); +const bodyParser = require('body-parser') const app = express() @@ -79,7 +79,7 @@ app.post('/check/dangling', HttpController.checkDanglingUpdates) let packWorker = null // use a single packing worker -app.post('/pack', function(req, res, next) { +app.post('/pack', function (req, res, next) { if (packWorker != null) { return res.send('pack already running') } else { @@ -89,7 +89,7 @@ app.post('/pack', function(req, res, next) { req.query.delay || 1000, req.query.timeout || 30 * 60 * 1000 ]) - packWorker.on('exit', function(code, signal) { + packWorker.on('exit', function (code, signal) { logger.log({ code, signal }, 'history auto pack exited') return (packWorker = null) }) @@ -99,7 +99,7 @@ app.post('/pack', function(req, res, next) { app.get('/status', (req, res, next) => res.send('track-changes is alive')) -app.get('/oops', function(req, res, next) { +app.get('/oops', function (req, res, next) { throw new Error('dummy test error') }) @@ -107,7 +107,7 @@ app.get('/check_lock', HttpController.checkLock) app.get('/health_check', HttpController.healthCheck) -app.use(function(error, req, res, next) { +app.use(function (error, req, res, next) { logger.error({ err: error, req }, 'an internal error occured') return res.send(500) }) @@ -115,17 +115,17 @@ app.use(function(error, req, res, next) { const port = __guard__( Settings.internal != null ? Settings.internal.trackchanges : undefined, - x => x.port + (x) => x.port ) || 3015 const host = __guard__( Settings.internal != null ? Settings.internal.trackchanges : undefined, - x1 => x1.host + (x1) => x1.host ) || 'localhost' if (!module.parent) { // Called directly - app.listen(port, host, function(error) { + app.listen(port, host, function (error) { if (error != null) { return logger.error( { err: error }, diff --git a/services/track-changes/app.js.map b/services/track-changes/app.js.map new file mode 100644 index 0000000000..c408f74302 --- /dev/null +++ b/services/track-changes/app.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "app.js", + "sourceRoot": "", + "sources": [ + "app.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,OAAA,GAAU,OAAA,CAAQ,oBAAR;;EACV,OAAO,CAAC,UAAR,CAAmB,eAAnB;;EACA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,kBAAA,GAAqB,MAAM,CAAC,UAAP,CAAkB,eAAlB,CAAkC,CAAC;;EAExD,IAAG,4DAAH;IACC,MAAM,CAAC,wBAAP,CAAgC,QAAQ,CAAC,MAAM,CAAC,GAAhD,EADD;;;EAIA,UAAA,GAAa,SAAC,OAAD;WACX,IAAI,CAAC,KAAL,CACC,IAAI,CAAC,SAAL,CAAe,OAAf,EAAwB,SAAC,GAAD,EAAM,KAAN;AACvB,UAAA;MAAA,IAAG,OAAO,KAAP,KAAgB,QAAhB,IAA4B,CAAC,GAAA,GAAM,KAAK,CAAC,MAAb,CAAA,GAAuB,EAAtD;AACC,eAAO,KAAK,CAAC,MAAN,CAAa,CAAb,EAAe,EAAf,CAAA,GAAqB,CAAA,wBAAA,GAAyB,GAAzB,GAA6B,gBAA7B,CAArB,GAAoE,KAAK,CAAC,MAAN,CAAa,CAAC,EAAd,EAD5E;OAAA,MAAA;AAGC,eAAO,MAHR;;IADuB,CAAxB,CADD;EADW;;EASb,kBAAkB,CAAC,cAAnB,CAAkC;IACjC,SAAA,EAAW,UADsB;IAEjC,UAAA,EAAY,UAFqB;IAGjC,UAAA,EAAY,UAHqB;IAIjC,UAAA,EAAY,UAJqB;GAAlC;;EAOA,IAAA,GAAO,OAAA,CAAQ,MAAR;;EAEP,OAAO,CAAC,MAAM,CAAC,OAAf,CAAuB,MAAvB;;EAEA,aAAA,GAAgB,OAAA,CAA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Aa,GAAb,EAAkB,IAAlB;IACP,MAAM,CAAC,KAAP,CAAa;MAAA,GAAA,EAAK,KAAL;MAAY,GAAA,EAAK,GAAjB;KAAb,EAAmC,2BAAnC;WACA,GAAG,CAAC,IAAJ,CAAS,GAAT;EAFO,CAAR;;EAIA,IAAA,kFAAsC,CAAE,uBAAjC,IAAyC;;EAChD,IAAA,kFAAsC,CAAE,uBAAjC,IAAyC;;EAEhD,IAAG,CAAC,MAAM,CAAC,MAAX;IACC,GAAG,CAAC,MAAJ,CAAW,IAAX,EAAiB,IAAjB,EAAuB,SAAC,KAAD;MACtB,IAAG,aAAH;eACC,MAAM,CAAC,KAAP,CAAa;UAAA,GAAA,EAAK,KAAL;SAAb,EAAyB,sCAAzB,EADD;OAAA,MAAA;eAGC,MAAM,CAAC,IAAP,CAAY,yCAAA,GAA0C,IAA1C,GAA+C,GAA/C,GAAkD,IAA9D,EAHD;;IADsB,CAAvB,EADD;;;EAOA,MAAM,CAAC,OAAP,GAAiB;AAzGjB" +} \ No newline at end of file diff --git a/services/track-changes/app/js/DiffGenerator.js b/services/track-changes/app/js/DiffGenerator.js index 57e998d318..ebc6a9fcb1 100644 --- a/services/track-changes/app/js/DiffGenerator.js +++ b/services/track-changes/app/js/DiffGenerator.js @@ -13,7 +13,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let DiffGenerator -var ConsistencyError = function(message) { +var ConsistencyError = function (message) { const error = new Error(message) error.name = 'ConsistencyError' error.__proto__ = ConsistencyError.prototype diff --git a/services/track-changes/app/js/DiffGenerator.js.map b/services/track-changes/app/js/DiffGenerator.js.map new file mode 100644 index 0000000000..2394cfe7df --- /dev/null +++ b/services/track-changes/app/js/DiffGenerator.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "DiffGenerator.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/DiffGenerator.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,gBAAA,GAAm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,CAAC,CAAR;YACA,IAAA,EAAM,IADN;YAFF;SAAA,MAIK,IAAG,cAAH;UACJ,OAAA,GAAU,KADN;;QAGL,WAAA,GACC;UAAA,CAAA,EAAG,EAAE,CAAC,CAAN;UAAS,CAAA,EAAG,EAAE,CAAC,CAAC,CAAC,KAAL,CAAW,aAAa,CAAC,oBAAd,CAAmC,IAAnC,CAAX,CAAZ;UAhBG;;AAkBL,aAAO;QACN,OAAA,EAAS,OADH;QAEN,aAAA,EAAe,aAFT;QAGN,WAAA,EAAa,WAHP;;IA7Da,CAxIrB;IA2MA,UAAA,EAAY,SAAC,QAAD,EAAW,IAAX,EAAiB,EAAjB;AACX,UAAA;MAAA,IAAG,kBAAH;QACC,IAAA,GAAO;UAAE,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAC,KAAX,CAAiB,IAAjB,EAAuB,EAAvB,CAAL;UADR;OAAA,MAEK,IAAG,kBAAH;QACJ,IAAA,GAAO;UAAE,CAAA,EAAG,QAAQ,CAAC,CAAC,CAAC,KAAX,CAAiB,IAAjB,EAAuB,EAAvB,CAAL;UADH;;MAEL,IAAG,qBAAH;QACC,IAAI,CAAC,IAAL,GAAY,QAAQ,CAAC,KADtB;;AAEA,aAAO;IAPI,CA3MZ;IAoNA,oBAAA,EAAsB,SAAC,IAAD;aACrB,CAAC,IAAI,CAAC,CAAL,IAAU,IAAI,CAAC,CAAf,IAAoB,IAAI,CAAC,CAAzB,IAA8B,EAA/B,CAAkC,CAAC;IADd,CApNtB;IAuNA,iBAAA,EAAmB,SAAC,IAAD;aAClB,IAAI,CAAC,CAAL,IAAU,IAAI,CAAC,CAAf,IAAoB,IAAI,CAAC,CAAzB,IAA8B;IADZ,CAvNnB;;AAVD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/DiffManager.js b/services/track-changes/app/js/DiffManager.js index 0b8fa39de6..a33ed07c2d 100644 --- a/services/track-changes/app/js/DiffManager.js +++ b/services/track-changes/app/js/DiffManager.js @@ -22,9 +22,9 @@ module.exports = DiffManager = { // Get updates last, since then they must be ahead and it // might be possible to rewind to the same version as the doc. if (callback == null) { - callback = function(error, content, version, updates) {} + callback = function (error, content, version, updates) {} } - return DocumentUpdaterManager.getDocument(project_id, doc_id, function( + return DocumentUpdaterManager.getDocument(project_id, doc_id, function ( error, content, version @@ -40,7 +40,7 @@ module.exports = DiffManager = { project_id, doc_id, { from: fromVersion }, - function(error, updates) { + function (error, updates) { if (error != null) { return callback(error) } @@ -52,13 +52,13 @@ module.exports = DiffManager = { getDiff(project_id, doc_id, fromVersion, toVersion, callback) { if (callback == null) { - callback = function(error, diff) {} + callback = function (error, diff) {} } return DiffManager.getDocumentBeforeVersion( project_id, doc_id, fromVersion, - function(error, startingContent, updates) { + function (error, startingContent, updates) { let diff if (error != null) { if (error.message === 'broken-history') { @@ -94,10 +94,10 @@ module.exports = DiffManager = { // versions. let retry if (_callback == null) { - _callback = function(error, document, rewoundUpdates) {} + _callback = function (error, document, rewoundUpdates) {} } let retries = 3 - const callback = function(error, ...args) { + const callback = function (error, ...args) { if (error != null) { if (error.retry && retries > 0) { logger.warn( @@ -113,7 +113,7 @@ module.exports = DiffManager = { } } - return (retry = function() { + return (retry = function () { retries-- return DiffManager._tryGetDocumentBeforeVersion( project_id, @@ -126,7 +126,7 @@ module.exports = DiffManager = { _tryGetDocumentBeforeVersion(project_id, doc_id, version, callback) { if (callback == null) { - callback = function(error, document, rewoundUpdates) {} + callback = function (error, document, rewoundUpdates) {} } logger.log( { project_id, doc_id, version }, @@ -136,7 +136,7 @@ module.exports = DiffManager = { project_id, doc_id, version, - function(error, content, version, updates) { + function (error, content, version, updates) { let startingContent if (error != null) { return callback(error) diff --git a/services/track-changes/app/js/DiffManager.js.map b/services/track-changes/app/js/DiffManager.js.map new file mode 100644 index 0000000000..9cd8d0895a --- /dev/null +++ b/services/track-changes/app/js/DiffManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "DiffManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coff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B;SAAA,cAAA;UAGM;AACL,iBAAO,QAAA,CAAS,CAAT,EAJR;;eAMA,QAAA,CAAS,IAAT,EAAe,eAAf,EAAgC,UAAhC;MA3B+D,CAAhE;IAF6B,CApD9B;;AAND" +} \ No newline at end of file diff --git a/services/track-changes/app/js/DocumentUpdaterManager.js b/services/track-changes/app/js/DocumentUpdaterManager.js index 5e83cdd9ab..29247b1664 100644 --- a/services/track-changes/app/js/DocumentUpdaterManager.js +++ b/services/track-changes/app/js/DocumentUpdaterManager.js @@ -19,11 +19,11 @@ const Settings = require('settings-sharelatex') module.exports = DocumentUpdaterManager = { getDocument(project_id, doc_id, callback) { if (callback == null) { - callback = function(error, content, version) {} + callback = function (error, content, version) {} } const url = `${Settings.apis.documentupdater.url}/project/${project_id}/doc/${doc_id}` logger.log({ project_id, doc_id }, 'getting doc from document updater') - return request.get(url, function(error, res, body) { + return request.get(url, function (error, res, body) { if (error != null) { return callback(error) } @@ -54,7 +54,7 @@ module.exports = DocumentUpdaterManager = { setDocument(project_id, doc_id, content, user_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } const url = `${Settings.apis.documentupdater.url}/project/${project_id}/doc/${doc_id}` logger.log({ project_id, doc_id }, 'setting doc in document updater') @@ -68,7 +68,7 @@ module.exports = DocumentUpdaterManager = { undoing: true } }, - function(error, res, body) { + function (error, res, body) { if (error != null) { return callback(error) } diff --git a/services/track-changes/app/js/DocumentUpdaterManager.js.map b/services/track-changes/app/js/DocumentUpdaterManager.js.map new file mode 100644 index 0000000000..50a1d7f569 --- /dev/null +++ b/services/track-changes/app/js/DocumentUpdaterManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "DocumentUpdaterManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/DocumentUpdaterManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,OAAA,GAAU,OAAA,CAAQ,SAAR;;EACV,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,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iBACA,QAAA,CAAS,KAAT,EAVD;;MAHgB,CAAjB;IAHY,CAAb;IAkBA,WAAA,EAAa,SAAC,UAAD,EAAa,MAAb,EAAqB,OAArB,EAA8B,OAA9B,EAAuC,QAAvC;AACZ,UAAA;;QADmD,WAAW,SAAC,KAAD,GAAA;;MAC9D,GAAA,GAAS,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,GAA/B,GAAmC,WAAnC,GAA8C,UAA9C,GAAyD,OAAzD,GAAgE;MACxE,MAAM,CAAC,GAAP,CAAW;QAAA,UAAA,EAAW,UAAX;QAAuB,MAAA,EAAQ,MAA/B;OAAX,EAAkD,iCAAlD;aACA,OAAO,CAAC,IAAR,CAAa;QACZ,GAAA,EAAK,GADO;QAEZ,IAAA,EACC;UAAA,KAAA,EAAO,OAAO,CAAC,KAAR,CAAc,IAAd,CAAP;UACA,MAAA,EAAQ,SADR;UAEA,OAAA,EAAS,OAFT;UAGA,OAAA,EAAS,IAHT;SAHW;OAAb,EAOG,SAAC,KAAD,EAAQ,GAAR,EAAa,IAAb;QACF,IAAG,aAAH;AACC,iBAAO,QAAA,CAAS,KAAT,EADR;;QAEA,IAAG,GAAG,CAAC,UAAJ,IAAkB,GAAlB,IAA0B,GAAG,CAAC,UAAJ,GAAiB,GAA9C;iBACC,QAAA,CAAS,IAAT,EADD;SAAA,MAAA;UAGC,KAAA,GAAQ,IAAI,KAAJ,CAAU,kDAAA,GAAmD,GAAG,CAAC,UAAjE;UACR,MAAM,CAAC,KAAP,CAAa;YAAA,GAAA,EAAK,KAAL;YAAY,UAAA,EAAW,UAAvB;YAAmC,MAAA,EAAO,MAA1C;YAAkD,GAAA,EAAK,GAAvD;WAAb,EAAyE,6BAAzE;iBACA,QAAA,CAAS,KAAT,EALD;;MAHE,CAPH;IAHY,CAlBb;;AALD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/HealthChecker.js b/services/track-changes/app/js/HealthChecker.js index 7d02157fe8..a4331b4eac 100644 --- a/services/track-changes/app/js/HealthChecker.js +++ b/services/track-changes/app/js/HealthChecker.js @@ -24,10 +24,10 @@ module.exports = { const url = `http://localhost:${port}/project/${project_id}` logger.log({ project_id }, 'running health check') const jobs = [ - cb => + (cb) => request.get( { url: `http://localhost:${port}/check_lock`, timeout: 3000 }, - function(err, res, body) { + function (err, res, body) { if (err != null) { logger.err( { err, project_id }, @@ -41,8 +41,8 @@ module.exports = { } } ), - cb => - request.post({ url: `${url}/flush`, timeout: 10000 }, function( + (cb) => + request.post({ url: `${url}/flush`, timeout: 10000 }, function ( err, res, body @@ -56,8 +56,8 @@ module.exports = { return cb() } }), - cb => - request.get({ url: `${url}/updates`, timeout: 10000 }, function( + (cb) => + request.get({ url: `${url}/updates`, timeout: 10000 }, function ( err, res, body diff --git a/services/track-changes/app/js/HealthChecker.js.map b/services/track-changes/app/js/HealthChecker.js.map new file mode 100644 index 0000000000..aeb4de5ac2 --- /dev/null +++ b/services/track-changes/app/js/HealthChecker.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "HealthChecker.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/HealthChecker.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,SAAR,CAAkB,CAAC;;EAC9B,OAAA,GAAU,OAAA,CAAQ,SAAR;;EACV,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EACR,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,IAAA,GAAO,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC;;EACtC,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,WAAA,GAAc,OAAA,CAAQ,eAAR;;EAEd,MAAM,CAAC,OAAP,GACC;IAAA,KAAA,EAAQ,SAAC,QAAD;AACP,UAAA;MAAA,UAAA,GAAa,QAAA,CAAS,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,UAA3C;MACb,GAAA,GAAM,mBAAA,GAAoB,IAApB,GAAyB,WAAzB,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AAM,GAAN,EAAW,IAAX;YAClD,IAAG,WAAH;cACC,MAAM,CAAC,GAAP,CAAW;gBAAA,GAAA,EAAI,GAAJ;gBAAS,UAAA,EAAW,UAApB;eAAX,EAA2C,wCAA3C;qBACA,EAAA,CAAG,GAAH,EAFD;aAAA,MAGK,mBAAG,GAAG,CAAE,oBAAL,KAAmB,GAAtB;qBACJ,EAAA,CAAG,4BAAA,GAA6B,GAAG,CAAC,UAApC,EADI;aAAA,MAAA;qBAGJ,EAAA,CAAA,EAHI;;UAJ6C,CAAnD;QADD,CAnBM;;aA6BP,KAAK,CAAC,MAAN,CAAa,IAAb,EAAmB,QAAnB;IAjCO,CAAR;IAmCA,SAAA,EAAW,SAAC,QAAD;aACV,WAAW,CAAC,WAAZ,CAAwB,QAAxB;IADU,CAnCX;;AATD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/HttpController.js b/services/track-changes/app/js/HttpController.js index 662ca49f0d..c167bae1c9 100644 --- a/services/track-changes/app/js/HttpController.js +++ b/services/track-changes/app/js/HttpController.js @@ -24,7 +24,7 @@ const _ = require('underscore') module.exports = HttpController = { flushDoc(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } const { doc_id } = req.params const { project_id } = req.params @@ -32,7 +32,7 @@ module.exports = HttpController = { return UpdatesManager.processUncompressedUpdatesWithLock( project_id, doc_id, - function(error) { + function (error) { if (error != null) { return next(error) } @@ -43,13 +43,13 @@ module.exports = HttpController = { flushProject(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } const { project_id } = req.params logger.log({ project_id }, 'compressing project history') return UpdatesManager.processUncompressedUpdatesForProject( project_id, - function(error) { + function (error) { if (error != null) { return next(error) } @@ -61,11 +61,11 @@ module.exports = HttpController = { flushAll(req, res, next) { // limit on projects to flush or -1 for all (default) if (next == null) { - next = function(error) {} + next = function (error) {} } const limit = req.query.limit != null ? parseInt(req.query.limit, 10) : -1 logger.log({ limit }, 'flushing all projects') - return UpdatesManager.flushAll(limit, function(error, result) { + return UpdatesManager.flushAll(limit, function (error, result) { if (error != null) { return next(error) } @@ -92,10 +92,10 @@ module.exports = HttpController = { checkDanglingUpdates(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } logger.log('checking dangling updates') - return UpdatesManager.getDanglingUpdates(function(error, result) { + return UpdatesManager.getDanglingUpdates(function (error, result) { if (error != null) { return next(error) } @@ -110,39 +110,40 @@ module.exports = HttpController = { checkDoc(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } const { doc_id } = req.params const { project_id } = req.params logger.log({ project_id, doc_id }, 'checking doc history') - return DiffManager.getDocumentBeforeVersion(project_id, doc_id, 1, function( - error, - document, - rewoundUpdates - ) { - if (error != null) { - return next(error) - } - const broken = [] - for (const update of Array.from(rewoundUpdates)) { - for (const op of Array.from(update.op)) { - if (op.broken === true) { - broken.push(op) + return DiffManager.getDocumentBeforeVersion( + project_id, + doc_id, + 1, + function (error, document, rewoundUpdates) { + if (error != null) { + return next(error) + } + const broken = [] + for (const update of Array.from(rewoundUpdates)) { + for (const op of Array.from(update.op)) { + if (op.broken === true) { + broken.push(op) + } } } + if (broken.length > 0) { + return res.send(broken) + } else { + return res.sendStatus(204) + } } - if (broken.length > 0) { - return res.send(broken) - } else { - return res.sendStatus(204) - } - }) + ) }, getDiff(req, res, next) { let from, to if (next == null) { - next = function(error) {} + next = function (error) {} } const { doc_id } = req.params const { project_id } = req.params @@ -159,7 +160,7 @@ module.exports = HttpController = { } logger.log({ project_id, doc_id, from, to }, 'getting diff') - return DiffManager.getDiff(project_id, doc_id, from, to, function( + return DiffManager.getDiff(project_id, doc_id, from, to, function ( error, diff ) { @@ -173,7 +174,7 @@ module.exports = HttpController = { getUpdates(req, res, next) { let before, min_count if (next == null) { - next = function(error) {} + next = function (error) {} } const { project_id } = req.params @@ -187,7 +188,7 @@ module.exports = HttpController = { return UpdatesManager.getSummarizedProjectUpdates( project_id, { before, min_count }, - function(error, updates, nextBeforeTimestamp) { + function (error, updates, nextBeforeTimestamp) { if (error != null) { return next(error) } @@ -201,7 +202,7 @@ module.exports = HttpController = { restore(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } let { doc_id, project_id, version } = req.params const user_id = req.headers['x-user-id'] @@ -211,7 +212,7 @@ module.exports = HttpController = { doc_id, version, user_id, - function(error) { + function (error) { if (error != null) { return next(error) } @@ -222,12 +223,12 @@ module.exports = HttpController = { pushDocHistory(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } const { project_id } = req.params const { doc_id } = req.params logger.log({ project_id, doc_id }, 'pushing all finalised changes to s3') - return PackManager.pushOldPacks(project_id, doc_id, function(error) { + return PackManager.pushOldPacks(project_id, doc_id, function (error) { if (error != null) { return next(error) } @@ -237,12 +238,12 @@ module.exports = HttpController = { pullDocHistory(req, res, next) { if (next == null) { - next = function(error) {} + next = function (error) {} } const { project_id } = req.params const { doc_id } = req.params logger.log({ project_id, doc_id }, 'pulling all packs from s3') - return PackManager.pullOldPacks(project_id, doc_id, function(error) { + return PackManager.pullOldPacks(project_id, doc_id, function (error) { if (error != null) { return next(error) } @@ -251,7 +252,7 @@ module.exports = HttpController = { }, healthCheck(req, res) { - return HealthChecker.check(function(err) { + return HealthChecker.check(function (err) { if (err != null) { logger.err({ err }, 'error performing health check') return res.sendStatus(500) @@ -262,7 +263,7 @@ module.exports = HttpController = { }, checkLock(req, res) { - return HealthChecker.checkLock(function(err) { + return HealthChecker.checkLock(function (err) { if (err != null) { logger.err({ err }, 'error performing lock check') return res.sendStatus(500) diff --git a/services/track-changes/app/js/HttpController.js.map b/services/track-changes/app/js/HttpController.js.map new file mode 100644 index 0000000000..b2d95f4b7b --- /dev/null +++ b/services/track-changes/app/js/HttpController.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "HttpController.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/HttpController.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,cAAA,GAAiB,OAAA,CAAQ,kBAAR;;EACj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} \ No newline at end of file diff --git a/services/track-changes/app/js/LockManager.js b/services/track-changes/app/js/LockManager.js index 729e9bab6b..28701f4ac1 100644 --- a/services/track-changes/app/js/LockManager.js +++ b/services/track-changes/app/js/LockManager.js @@ -40,10 +40,10 @@ module.exports = LockManager = { tryLock(key, callback) { if (callback == null) { - callback = function(err, gotLock) {} + callback = function (err, gotLock) {} } const lockValue = LockManager.randomLock() - return rclient.set(key, lockValue, 'EX', this.LOCK_TTL, 'NX', function( + return rclient.set(key, lockValue, 'EX', this.LOCK_TTL, 'NX', function ( err, gotLock ) { @@ -61,17 +61,17 @@ module.exports = LockManager = { getLock(key, callback) { let attempt if (callback == null) { - callback = function(error) {} + callback = function (error) {} } const startTime = Date.now() - return (attempt = function() { + return (attempt = function () { if (Date.now() - startTime > LockManager.MAX_LOCK_WAIT_TIME) { const e = new Error('Timeout') e.key = key return callback(e) } - return LockManager.tryLock(key, function(error, gotLock, lockValue) { + return LockManager.tryLock(key, function (error, gotLock, lockValue) { if (error != null) { return callback(error) } @@ -86,9 +86,9 @@ module.exports = LockManager = { checkLock(key, callback) { if (callback == null) { - callback = function(err, isFree) {} + callback = function (err, isFree) {} } - return rclient.exists(key, function(err, exists) { + return rclient.exists(key, function (err, exists) { if (err != null) { return callback(err) } @@ -102,7 +102,7 @@ module.exports = LockManager = { }, releaseLock(key, lockValue, callback) { - return rclient.eval(LockManager.unlockScript, 1, key, lockValue, function( + return rclient.eval(LockManager.unlockScript, 1, key, lockValue, function ( err, result ) { @@ -123,14 +123,14 @@ module.exports = LockManager = { runWithLock(key, runner, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } - return LockManager.getLock(key, function(error, lockValue) { + return LockManager.getLock(key, function (error, lockValue) { if (error != null) { return callback(error) } - return runner(error1 => - LockManager.releaseLock(key, lockValue, function(error2) { + return runner((error1) => + LockManager.releaseLock(key, lockValue, function (error2) { error = error1 || error2 if (error != null) { return callback(error) @@ -142,7 +142,7 @@ module.exports = LockManager = { }, healthCheck(callback) { - const action = releaseLock => releaseLock() + const action = (releaseLock) => releaseLock() return LockManager.runWithLock( `HistoryLock:HealthCheck:host=${HOST}:pid=${PID}:random=${RND}`, action, diff --git a/services/track-changes/app/js/LockManager.js.map b/services/track-changes/app/js/LockManager.js.map new file mode 100644 index 0000000000..60b765a17b --- /dev/null +++ b/services/track-changes/app/js/LockManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "LockManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/LockManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,KAAA,GAAQ,OAAA,CAAQ,kBAAR;;EACR,OAAA,GAAU,KAAK,CAAC,YAAN,CAAmB,QAAQ,CAAC,KAAK,CAAC,IAAlC;;EACV,EAAA,GAAK,OAAA,CAAQ,IAAR;;EACL,MAAA,GAAS,OAAA,CAAQ,QAAR;;EACT,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EAET,IAAA,GAAO,EAAE,CAAC,QAAH,CAAA;;EACP,GAAA,GAAM,OAAO,CAAC;;EACd,GAAA,GAAM,MAAM,CAAC,WAAP,CAAmB,CAAnB,CAAqB,CAAC,QAAtB,CAA+B,KAA/B;;EACN,KAAA,GAAQ;;EAER,MAAM,CAAC,OAAP,GAAiB,WAAA,GAChB;IAAA,kBAAA,EAAoB,EAApB;IACA,kBAAA,EAAoB,KADpB;IAEA,QAAA,EAAU,GAFV;IAOA,UAAA,EAAa,SAAA;AACZ,UAAA;MAAA,IAAA,GAAO,IAAI,CAAC,GAAL,CAAA;AACP,aAAO,cAAA,GAAe,IAAf,GAAoB,OAApB,GAA2B,GAA3B,GAA+B,UAA/B,GAAyC,GAAzC,GAA6C,QAA7C,GAAqD,IAArD,GAA0D,SAA1D,GAAkE,CAAC,KAAA,EAAD;IAF7D,CAPb;IAWA,YAAA,EAAc,mGAXd;IAaA,OAAA,EAAU,SAAC,GAAD,EAAM,QA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AAW,CAAC,WAAZ,CAAwB,GAAxB,EAA6B,SAA7B,EAAwC,SAAC,MAAD;YACvC,KAAA,GAAQ,MAAA,IAAU;YAClB,IAA0B,aAA1B;AAAA,qBAAO,QAAA,CAAS,KAAT,EAAP;;mBACA,QAAA,CAAA;UAHuC,CAAxC;QADM,CAAP;MAFwB,CAAzB;IADY,CAvDb;IAgEA,WAAA,EAAa,SAAC,QAAD;AACZ,UAAA;MAAA,MAAA,GAAS,SAAC,WAAD;eACR,WAAA,CAAA;MADQ;aAET,WAAW,CAAC,WAAZ,CAAwB,+BAAA,GAAgC,IAAhC,GAAqC,OAArC,GAA4C,GAA5C,GAAgD,UAAhD,GAA0D,GAAlF,EAAyF,MAAzF,EAAiG,QAAjG;IAHY,CAhEb;IAqEA,KAAA,EAAO,SAAC,QAAD;MACN,OAAO,CAAC,IAAR,CAAA;aACA,OAAO,CAAC,IAAR,CAAa,KAAb,EAAoB,QAApB;IAFM,CArEP;;AAbD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/MongoAWS.js b/services/track-changes/app/js/MongoAWS.js index 613ed930f4..bcf2a49715 100644 --- a/services/track-changes/app/js/MongoAWS.js +++ b/services/track-changes/app/js/MongoAWS.js @@ -26,7 +26,7 @@ const Metrics = require('metrics-sharelatex') const DAYS = 24 * 3600 * 1000 // one day in milliseconds -const createStream = function(streamConstructor, project_id, doc_id, pack_id) { +const createStream = function (streamConstructor, project_id, doc_id, pack_id) { const AWS_CONFIG = { accessKeyId: settings.trackchanges.s3.key, secretAccessKey: settings.trackchanges.s3.secret, @@ -43,11 +43,11 @@ const createStream = function(streamConstructor, project_id, doc_id, pack_id) { module.exports = MongoAWS = { archivePack(project_id, doc_id, pack_id, _callback) { if (_callback == null) { - _callback = function(error) {} + _callback = function (error) {} } - const callback = function(...args) { + const callback = function (...args) { _callback(...Array.from(args || [])) - return (_callback = function() {}) + return (_callback = function () {}) } const query = { @@ -69,7 +69,7 @@ module.exports = MongoAWS = { const upload = createStream(S3S.WriteStream, project_id, doc_id, pack_id) - return db.docHistory.findOne(query, function(err, result) { + return db.docHistory.findOne(query, function (err, result) { if (err != null) { return callback(err) } @@ -85,7 +85,7 @@ module.exports = MongoAWS = { logger.error({ err: error, project_id, doc_id, pack_id }, error.message) return callback(error) } - return zlib.gzip(uncompressedData, function(err, buf) { + return zlib.gzip(uncompressedData, function (err, buf) { logger.log( { project_id, @@ -99,8 +99,8 @@ module.exports = MongoAWS = { if (err != null) { return callback(err) } - upload.on('error', err => callback(err)) - upload.on('finish', function() { + upload.on('error', (err) => callback(err)) + upload.on('finish', function () { Metrics.inc('archive-pack') logger.log({ project_id, doc_id, pack_id }, 'upload to s3 completed') return callback(null) @@ -113,11 +113,11 @@ module.exports = MongoAWS = { readArchivedPack(project_id, doc_id, pack_id, _callback) { if (_callback == null) { - _callback = function(error, result) {} + _callback = function (error, result) {} } - const callback = function(...args) { + const callback = function (...args) { _callback(...Array.from(args || [])) - return (_callback = function() {}) + return (_callback = function () {}) } if (project_id == null) { @@ -135,12 +135,12 @@ module.exports = MongoAWS = { const download = createStream(S3S.ReadStream, project_id, doc_id, pack_id) const inputStream = download - .on('open', obj => 1) - .on('error', err => callback(err)) + .on('open', (obj) => 1) + .on('error', (err) => callback(err)) const gunzip = zlib.createGunzip() gunzip.setEncoding('utf8') - gunzip.on('error', function(err) { + gunzip.on('error', function (err) { logger.log( { project_id, doc_id, pack_id, err }, 'error uncompressing gzip stream' @@ -150,8 +150,8 @@ module.exports = MongoAWS = { const outputStream = inputStream.pipe(gunzip) const parts = [] - outputStream.on('error', err => callback(err)) - outputStream.on('end', function() { + outputStream.on('error', (err) => callback(err)) + outputStream.on('end', function () { let object logger.log({ project_id, doc_id, pack_id }, 'download from s3 completed') try { @@ -169,14 +169,14 @@ module.exports = MongoAWS = { } return callback(null, object) }) - return outputStream.on('data', data => parts.push(data)) + return outputStream.on('data', (data) => parts.push(data)) }, unArchivePack(project_id, doc_id, pack_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } - return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function( + return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function ( err, object ) { diff --git a/services/track-changes/app/js/MongoAWS.js.map b/services/track-changes/app/js/MongoAWS.js.map new file mode 100644 index 0000000000..8594f9a104 --- /dev/null +++ b/services/track-changes/app/js/MongoAWS.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "MongoAWS.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/MongoAWS.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA,sHAAA;IAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,GAAA,GAAM,OAAA,CAAQ,SAAR;;EACN,GAAA,GAAM,OAAA,CAAQ,YAAR;;EACN,MAAiB,OAAA,CAAQ,WAAR,CAAjB,EAAC,WAAD,EAAK;;EACL,UAAA,GAAa,OAAA,CAAQ,YAAR;;EACb,cAAA,GAAiB,OAAA,CAAQ,QAAR;;EACjB,IAAA,GAAO,OAAA,CAAQ,MAAR;;EACP,OAAA,GAAU,OAAA,CAAQ,oBAAR;;EAEV,IAAA,GAAO,EAAA,GAAK,IAAL,GAAY;;EAEnB,YAAA,GAAe,SAAC,iBAAD,EAAoB,UAApB,EAAgC,MAAhC,EAAwC,OAAxC;AACd,QAAA;IAAA,UAAA,GACC;MAAA,WAAA,EAAa,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,GAAtC;MACA,eAAA,EAAiB,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,MAD1C;;AAGD,WAAO,iBAAA,CAAkB,IAAI,GAAG,CAAC,EAAR,CAAW,UAAX,CAAlB,EAA0C;MAChD,QAAA,EAAU,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,WADS;MAEhD,KAAA,EAAO,UAAA,GAAW,WAAX,GAAuB,MAAvB,GAA8B,QAA9B,GAAuC,OAFE;KAA1C;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,QAA7B;MANsD,CAAvD;IADc,CApFf;;AAxBD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/MongoManager.js b/services/track-changes/app/js/MongoManager.js index 947e5b1db1..6a84fe7bc1 100644 --- a/services/track-changes/app/js/MongoManager.js +++ b/services/track-changes/app/js/MongoManager.js @@ -22,13 +22,13 @@ const logger = require('logger-sharelatex') module.exports = MongoManager = { getLastCompressedUpdate(doc_id, callback) { if (callback == null) { - callback = function(error, update) {} + callback = function (error, update) {} } return db.docHistory .find({ doc_id: ObjectId(doc_id.toString()) }, { pack: { $slice: -1 } }) // only return the last entry in a pack .sort({ v: -1 }) .limit(1) - .toArray(function(error, compressedUpdates) { + .toArray(function (error, compressedUpdates) { if (error != null) { return callback(error) } @@ -44,9 +44,9 @@ module.exports = MongoManager = { // to start, we pass it back as callback(null,null,version), just // giving the version so we can check consistency. if (callback == null) { - callback = function(error, update, version) {} + callback = function (error, update, version) {} } - return MongoManager.getLastCompressedUpdate(doc_id, function( + return MongoManager.getLastCompressedUpdate(doc_id, function ( error, update ) { @@ -76,7 +76,7 @@ module.exports = MongoManager = { return callback(null, update, update.v) } } else { - return PackManager.getLastPackFromIndex(doc_id, function(error, pack) { + return PackManager.getLastPackFromIndex(doc_id, function (error, pack) { if (error != null) { return callback(error) } @@ -94,7 +94,7 @@ module.exports = MongoManager = { backportProjectId(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return db.docHistory.update( { @@ -113,13 +113,13 @@ module.exports = MongoManager = { getProjectMetaData(project_id, callback) { if (callback == null) { - callback = function(error, metadata) {} + callback = function (error, metadata) {} } return db.projectHistoryMetaData.find( { project_id: ObjectId(project_id.toString()) }, - function(error, results) { + function (error, results) { if (error != null) { return callback(error) } @@ -130,7 +130,7 @@ module.exports = MongoManager = { setProjectMetaData(project_id, metadata, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return db.projectHistoryMetaData.update( { @@ -149,7 +149,7 @@ module.exports = MongoManager = { upgradeHistory(project_id, callback) { // preserve the project's existing history if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return db.docHistory.update( { @@ -200,11 +200,10 @@ module.exports = MongoManager = { ) } } - ;[ 'getLastCompressedUpdate', 'getProjectMetaData', 'setProjectMetaData' -].map(method => +].map((method) => metrics.timeAsyncMethod(MongoManager, method, 'mongo.MongoManager', logger) ) diff --git a/services/track-changes/app/js/MongoManager.js.map b/services/track-changes/app/js/MongoManager.js.map new file mode 100644 index 0000000000..af11849e38 --- /dev/null +++ b/services/track-changes/app/js/MongoManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "MongoManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/MongoManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,MAAiB,OAAA,CAAQ,WAAR,CAAjB,EAAC,WAAD,EAAK;;EACL,WAAA,GAAc,OAAA,CAAQ,eAAR;;EACd,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EACR,CAAA,GAAI,OAAA,CAAQ,YAAR;;EACJ,OAAA,GAAU,OAAA,CAAQ,oBAAR;;EACV,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EAET,MAAM,CAAC,OAAP,GAAiB,YAAA,GAChB;IAAA,uBAAA,EAAyB,SAAC,MAAD,EAAS,QAAT;;QAAS,WAAW,SAAC,KAAD,EAAQ,MAAR,GAAA;;aAC5C,EAAE,CAAC,UACF,CAAC,IADF,CACO;QAAA,MAAA,EAAQ,QAAA,CAAS,MAAM,CAAC,QAAP,CAAA,CAAT,CAAR;OADP,EAC4C;QAAC,IAAA,EAAM;UAAC,MAAA,EAAO,CAAC,CAAT;SAAP;OAD5C,CAEC,CAAC,IAFF,CAEQ;QAAA,CAAA,EAAG,CAAC,CAAJ;OAFR,CAGC,CAAC,KAHF,CAGQ,CAHR,CAIC,CAAC,OAJF,CAIU,SAAC,KAAD,EAAQ,iBAAR;QACR,IAA0B,aAA1B;AAAA,iBAAO,QAAA,CAAS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,EAAoE,MAApE;EADK,CAJN;AAlGA" +} \ No newline at end of file diff --git a/services/track-changes/app/js/PackManager.js b/services/track-changes/app/js/PackManager.js index 5f5c0444e1..5d753aebb2 100644 --- a/services/track-changes/app/js/PackManager.js +++ b/services/track-changes/app/js/PackManager.js @@ -74,7 +74,7 @@ module.exports = PackManager = { callback ) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } if (newUpdates.length === 0) { return callback() @@ -115,7 +115,7 @@ module.exports = PackManager = { lastUpdate, updatesToFlush, temporary, - function(error) { + function (error) { if (error != null) { return callback(error) } @@ -140,7 +140,7 @@ module.exports = PackManager = { callback ) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } if (newUpdates.length === 0) { return callback() @@ -190,7 +190,7 @@ module.exports = PackManager = { callback ) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } const first = newUpdates[0] const last = newUpdates[newUpdates.length - 1] @@ -218,7 +218,7 @@ module.exports = PackManager = { { project_id, doc_id, newUpdates }, 'inserting updates into new pack' ) - return db.docHistory.save(newPack, function(err, result) { + return db.docHistory.save(newPack, function (err, result) { if (err != null) { return callback(err) } @@ -240,7 +240,7 @@ module.exports = PackManager = { callback ) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } const first = newUpdates[0] const last = newUpdates[newUpdates.length - 1] @@ -283,14 +283,14 @@ module.exports = PackManager = { getOpsByVersionRange(project_id, doc_id, fromVersion, toVersion, callback) { if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } return PackManager.loadPacksByVersionRange( project_id, doc_id, fromVersion, toVersion, - function(error) { + function (error) { const query = { doc_id: ObjectId(doc_id.toString()) } if (toVersion != null) { query.v = { $lte: toVersion } @@ -299,34 +299,36 @@ module.exports = PackManager = { query.v_end = { $gte: fromVersion } } // console.log "query:", query - return db.docHistory.find(query).sort({ v: -1 }, function(err, result) { - if (err != null) { - return callback(err) - } - // console.log "getOpsByVersionRange:", err, result - const updates = [] - const opInRange = function(op, from, to) { - if (fromVersion != null && op.v < fromVersion) { - return false + return db.docHistory + .find(query) + .sort({ v: -1 }, function (err, result) { + if (err != null) { + return callback(err) } - if (toVersion != null && op.v > toVersion) { - return false + // console.log "getOpsByVersionRange:", err, result + const updates = [] + const opInRange = function (op, from, to) { + if (fromVersion != null && op.v < fromVersion) { + return false + } + if (toVersion != null && op.v > toVersion) { + return false + } + return true } - return true - } - for (const docHistory of Array.from(result)) { - // console.log 'adding', docHistory.pack - for (const op of Array.from(docHistory.pack.reverse())) { - if (opInRange(op, fromVersion, toVersion)) { - op.project_id = docHistory.project_id - op.doc_id = docHistory.doc_id - // console.log "added op", op.v, fromVersion, toVersion - updates.push(op) + for (const docHistory of Array.from(result)) { + // console.log 'adding', docHistory.pack + for (const op of Array.from(docHistory.pack.reverse())) { + if (opInRange(op, fromVersion, toVersion)) { + op.project_id = docHistory.project_id + op.doc_id = docHistory.doc_id + // console.log "added op", op.v, fromVersion, toVersion + updates.push(op) + } } } - } - return callback(null, updates) - }) + return callback(null, updates) + }) } ) }, @@ -338,14 +340,14 @@ module.exports = PackManager = { toVersion, callback ) { - return PackManager.getIndex(doc_id, function(err, indexResult) { + return PackManager.getIndex(doc_id, function (err, indexResult) { let pack if (err != null) { return callback(err) } const indexPacks = (indexResult != null ? indexResult.packs : undefined) || [] - const packInRange = function(pack, from, to) { + const packInRange = function (pack, from, to) { if (fromVersion != null && pack.v_end < fromVersion) { return false } @@ -391,7 +393,7 @@ module.exports = PackManager = { } }, { _id: 1 }, - function(err, loadedPacks) { + function (err, loadedPacks) { if (err != null) { return callback(err) } @@ -402,7 +404,7 @@ module.exports = PackManager = { } return result1 })() - const loadedPackIds = Array.from(loadedPacks).map(pack => + const loadedPackIds = Array.from(loadedPacks).map((pack) => pack._id.toString() ) const packIdsToFetch = _.difference(allPackIds, loadedPackIds) @@ -418,7 +420,7 @@ module.exports = PackManager = { 4, (pack_id, cb) => MongoAWS.unArchivePack(project_id, doc_id, pack_id, cb), - function(err) { + function (err) { if (err != null) { return callback(err) } @@ -436,7 +438,7 @@ module.exports = PackManager = { // get all the docHistory Entries return db.docHistory .find({ project_id: ObjectId(project_id) }, { pack: false }) - .sort({ 'meta.end_ts': -1 }, function(err, packs) { + .sort({ 'meta.end_ts': -1 }, function (err, packs) { let pack if (err != null) { return callback(err) @@ -449,7 +451,7 @@ module.exports = PackManager = { } return db.docHistoryIndex.find( { project_id: ObjectId(project_id) }, - function(err, indexes) { + function (err, indexes) { if (err != null) { return callback(err) } @@ -474,7 +476,7 @@ module.exports = PackManager = { }, getPackById(project_id, doc_id, pack_id, callback) { - return db.docHistory.findOne({ _id: pack_id }, function(err, pack) { + return db.docHistory.findOne({ _id: pack_id }, function (err, pack) { if (err != null) { return callback(err) } @@ -500,7 +502,7 @@ module.exports = PackManager = { query: { _id: pack._id }, update: { $set: { expiresAt: new Date(Date.now() + 7 * DAYS) } } }, - err => callback(err, pack) + (err) => callback(err, pack) ) } else { return callback(null, pack) @@ -528,7 +530,7 @@ module.exports = PackManager = { return db.docHistoryIndex.findOne( { _id: ObjectId(doc_id.toString()) }, { packs: { $slice: -1 } }, - function(err, indexPack) { + function (err, indexPack) { if (err != null) { return callback(err) } @@ -541,7 +543,7 @@ module.exports = PackManager = { }, getIndexWithKeys(doc_id, callback) { - return PackManager.getIndex(doc_id, function(err, index) { + return PackManager.getIndex(doc_id, function (err, index) { if (err != null) { return callback(err) } @@ -558,7 +560,7 @@ module.exports = PackManager = { }, initialiseIndex(project_id, doc_id, callback) { - return PackManager.findCompletedPacks(project_id, doc_id, function( + return PackManager.findCompletedPacks(project_id, doc_id, function ( err, packs ) { @@ -580,7 +582,7 @@ module.exports = PackManager = { updateIndex(project_id, doc_id, callback) { // find all packs prior to current pack - return PackManager.findUnindexedPacks(project_id, doc_id, function( + return PackManager.findUnindexedPacks(project_id, doc_id, function ( err, newPacks ) { @@ -594,7 +596,7 @@ module.exports = PackManager = { project_id, doc_id, newPacks, - function(err) { + function (err) { if (err != null) { return callback(err) } @@ -615,7 +617,7 @@ module.exports = PackManager = { } return db.docHistory .find(query, { pack: false }) - .sort({ v: 1 }, function(err, packs) { + .sort({ v: 1 }, function (err, packs) { if (err != null) { return callback(err) } @@ -640,7 +642,7 @@ module.exports = PackManager = { } return db.docHistory .find(query, { pack: false }) - .sort({ v: 1 }, function(err, packs) { + .sort({ v: 1 }, function (err, packs) { if (err != null) { return callback(err) } @@ -655,11 +657,11 @@ module.exports = PackManager = { }, findUnindexedPacks(project_id, doc_id, callback) { - return PackManager.getIndexWithKeys(doc_id, function(err, indexResult) { + return PackManager.getIndexWithKeys(doc_id, function (err, indexResult) { if (err != null) { return callback(err) } - return PackManager.findCompletedPacks(project_id, doc_id, function( + return PackManager.findCompletedPacks(project_id, doc_id, function ( err, historyPacks ) { @@ -713,7 +715,7 @@ module.exports = PackManager = { insertPacksIntoIndexWithLock(project_id, doc_id, newPacks, callback) { return LockManager.runWithLock( keys.historyIndexLock({ doc_id }), - releaseLock => + (releaseLock) => PackManager._insertPacksIntoIndex( project_id, doc_id, @@ -743,14 +745,14 @@ module.exports = PackManager = { // Archiving packs to S3 archivePack(project_id, doc_id, pack_id, callback) { - const clearFlagOnError = function(err, cb) { + const clearFlagOnError = function (err, cb) { if (err != null) { // clear the inS3 flag on error return PackManager.clearPackAsArchiveInProgress( project_id, doc_id, pack_id, - function(err2) { + function (err2) { if (err2 != null) { return cb(err2) } @@ -763,30 +765,30 @@ module.exports = PackManager = { } return async.series( [ - cb => + (cb) => PackManager.checkArchiveNotInProgress( project_id, doc_id, pack_id, cb ), - cb => + (cb) => PackManager.markPackAsArchiveInProgress( project_id, doc_id, pack_id, cb ), - cb => - MongoAWS.archivePack(project_id, doc_id, pack_id, err => + (cb) => + MongoAWS.archivePack(project_id, doc_id, pack_id, (err) => clearFlagOnError(err, cb) ), - cb => - PackManager.checkArchivedPack(project_id, doc_id, pack_id, err => + (cb) => + PackManager.checkArchivedPack(project_id, doc_id, pack_id, (err) => clearFlagOnError(err, cb) ), - cb => PackManager.markPackAsArchived(project_id, doc_id, pack_id, cb), - cb => + (cb) => PackManager.markPackAsArchived(project_id, doc_id, pack_id, cb), + (cb) => PackManager.setTTLOnArchivedPack( project_id, doc_id, @@ -799,14 +801,14 @@ module.exports = PackManager = { }, checkArchivedPack(project_id, doc_id, pack_id, callback) { - return db.docHistory.findOne({ _id: pack_id }, function(err, pack) { + return db.docHistory.findOne({ _id: pack_id }, function (err, pack) { if (err != null) { return callback(err) } if (pack == null) { return callback(new Error('pack not found')) } - return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function( + return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function ( err, result ) { @@ -845,7 +847,7 @@ module.exports = PackManager = { // Extra methods to test archive/unarchive for a doc_id pushOldPacks(project_id, doc_id, callback) { - return PackManager.findPacks(project_id, doc_id, function(err, packs) { + return PackManager.findPacks(project_id, doc_id, function (err, packs) { if (err != null) { return callback(err) } @@ -874,8 +876,8 @@ module.exports = PackManager = { // Processing old packs via worker processOldPack(project_id, doc_id, pack_id, callback) { - const markAsChecked = err => - PackManager.markPackAsChecked(project_id, doc_id, pack_id, function( + const markAsChecked = (err) => + PackManager.markPackAsChecked(project_id, doc_id, pack_id, function ( err2 ) { if (err2 != null) { @@ -884,7 +886,7 @@ module.exports = PackManager = { return callback(err) }) logger.log({ project_id, doc_id }, 'processing old packs') - return db.docHistory.findOne({ _id: pack_id }, function(err, pack) { + return db.docHistory.findOne({ _id: pack_id }, function (err, pack) { if (err != null) { return markAsChecked(err) } @@ -899,42 +901,45 @@ module.exports = PackManager = { doc_id, pack._id, pack, - function(err) { + function (err) { if (err != null) { return markAsChecked(err) } - return PackManager.updateIndexIfNeeded(project_id, doc_id, function( + return PackManager.updateIndexIfNeeded(project_id, doc_id, function ( err ) { if (err != null) { return markAsChecked(err) } - return PackManager.findUnarchivedPacks(project_id, doc_id, function( - err, - unarchivedPacks - ) { - if (err != null) { - return markAsChecked(err) - } - if ( - !(unarchivedPacks != null ? unarchivedPacks.length : undefined) - ) { - logger.log({ project_id, doc_id }, 'no packs need archiving') - return markAsChecked() - } - return async.eachSeries( - unarchivedPacks, - (pack, cb) => - PackManager.archivePack(project_id, doc_id, pack._id, cb), - function(err) { - if (err != null) { - return markAsChecked(err) - } - logger.log({ project_id, doc_id }, 'done processing') + return PackManager.findUnarchivedPacks( + project_id, + doc_id, + function (err, unarchivedPacks) { + if (err != null) { + return markAsChecked(err) + } + if ( + !(unarchivedPacks != null + ? unarchivedPacks.length + : undefined) + ) { + logger.log({ project_id, doc_id }, 'no packs need archiving') return markAsChecked() } - ) - }) + return async.eachSeries( + unarchivedPacks, + (pack, cb) => + PackManager.archivePack(project_id, doc_id, pack._id, cb), + function (err) { + if (err != null) { + return markAsChecked(err) + } + logger.log({ project_id, doc_id }, 'done processing') + return markAsChecked() + } + ) + } + ) }) } ) @@ -975,7 +980,7 @@ module.exports = PackManager = { markPackAsFinalisedWithLock(project_id, doc_id, pack_id, callback) { return LockManager.runWithLock( keys.historyLock({ doc_id }), - releaseLock => + (releaseLock) => PackManager._markPackAsFinalised( project_id, doc_id, @@ -999,7 +1004,7 @@ module.exports = PackManager = { updateIndexIfNeeded(project_id, doc_id, callback) { logger.log({ project_id, doc_id }, 'archiving old packs') - return PackManager.getIndexWithKeys(doc_id, function(err, index) { + return PackManager.getIndexWithKeys(doc_id, function (err, index) { if (err != null) { return callback(err) } @@ -1023,7 +1028,7 @@ module.exports = PackManager = { }, findUnarchivedPacks(project_id, doc_id, callback) { - return PackManager.getIndex(doc_id, function(err, indexResult) { + return PackManager.getIndex(doc_id, function (err, indexResult) { if (err != null) { return callback(err) } @@ -1055,7 +1060,10 @@ module.exports = PackManager = { { project_id, doc_id, pack_id }, 'checking if archive in progress' ) - return PackManager.getPackFromIndex(doc_id, pack_id, function(err, result) { + return PackManager.getPackFromIndex(doc_id, pack_id, function ( + err, + result + ) { if (err != null) { return callback(err) } @@ -1086,7 +1094,7 @@ module.exports = PackManager = { fields: { 'packs.$': 1 }, update: { $set: { 'packs.$.inS3': false } } }, - function(err, result) { + function (err, result) { if (err != null) { return callback(err) } @@ -1131,7 +1139,7 @@ module.exports = PackManager = { fields: { 'packs.$': 1 }, update: { $set: { 'packs.$.inS3': true } } }, - function(err, result) { + function (err, result) { if (err != null) { return callback(err) } @@ -1150,7 +1158,7 @@ module.exports = PackManager = { query: { _id: pack_id }, update: { $set: { expiresAt: new Date(Date.now() + 1 * DAYS) } } }, - function(err) { + function (err) { logger.log({ project_id, doc_id, pack_id }, 'set expiry on pack') return callback() } diff --git a/services/track-changes/app/js/PackManager.js.map b/services/track-changes/app/js/PackManager.js.map new file mode 100644 index 0000000000..bc7445c5e4 --- /dev/null +++ b/services/track-changes/app/js/PackManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "PackManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/PackManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EACR,CAAA,GAAI,OAAA,CAAQ,YAAR;;EACJ,MAAuB,OAAA,CAAQ,WAAR,CAAvB,EAAC,WAAD,EAAK,uBAAL,EAAe;;EACf,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,WAAA,GAAc,OAAA,CAAQ,eAAR;;EACd,QAAA,GAAW,OAAA,CAAQ,YAAR;;EACX,OAAA,GAAU,OAAA,CAAQ,oBAAR;;EACV,eAAA,GAAkB,OAAA,CAAQ,mBAAR;;EAClB,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,IAAA,GAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;;EAoC3B,IAAA,GAAO,EAAA,GAAK,IAAL,GAAY;;EAEnB,MAAM,CAAC,OAAP,GAAiB,WAAA,GAEhB;IAAA,QAAA,EAAW,IAAA,GAAK,IAAhB;IACA,SAAA,EAAW,IADX;IAGA,uBAAA,EAAyB,SAAC,UAAD,EAAa,MAAb,EAAqB,UAArB,EAAiC,UAAjC,EAA6C,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QAAA,MAAb;UAAqB,SAAA,OAArB;SAAX,EAA0C,oBAA1C;eACA,QAAA,CAAA;MAFE,CAHH;IADqB,CA9dtB;;AAjDD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/PackWorker.js b/services/track-changes/app/js/PackWorker.js index f24ddf5fce..e6a02fef3d 100644 --- a/services/track-changes/app/js/PackWorker.js +++ b/services/track-changes/app/js/PackWorker.js @@ -52,8 +52,8 @@ if (!source.match(/^[0-9]+$/)) { } return result1 })() - pending = _.filter(result, row => - __guard__(row != null ? row.doc_id : undefined, x => + pending = _.filter(result, (row) => + __guard__(row != null ? row.doc_id : undefined, (x) => x.match(/^[a-f0-9]{24}$/) ) ) @@ -62,12 +62,12 @@ if (!source.match(/^[0-9]+$/)) { } let shutDownRequested = false -const shutDownTimer = setTimeout(function() { +const shutDownTimer = setTimeout(function () { logger.log('pack timed out, requesting shutdown') // start the shutdown on the next pack shutDownRequested = true // do a hard shutdown after a further 5 minutes - const hardTimeout = setTimeout(function() { + const hardTimeout = setTimeout(function () { logger.error('HARD TIMEOUT in pack archive worker') return process.exit() }, 5 * 60 * 1000) @@ -79,8 +79,8 @@ logger.log( ) // work around for https://github.com/mafintosh/mongojs/issues/224 -db.close = function(callback) { - return this._getServer(function(err, server) { +db.close = function (callback) { + return this._getServer(function (err, server) { if (err != null) { return callback(err) } @@ -90,20 +90,20 @@ db.close = function(callback) { }) } -const finish = function() { +const finish = function () { if (shutDownTimer != null) { logger.log('cancelling timeout') clearTimeout(shutDownTimer) } logger.log('closing db') - return db.close(function() { + return db.close(function () { logger.log('closing LockManager Redis Connection') - return LockManager.close(function() { + return LockManager.close(function () { logger.log( { processedCount: COUNT, allCount: TOTAL }, 'ready to exit from pack archive worker' ) - const hardTimeout = setTimeout(function() { + const hardTimeout = setTimeout(function () { logger.error('hard exit from pack archive worker') return process.exit(1) }, 5 * 1000) @@ -112,12 +112,12 @@ const finish = function() { }) } -process.on('exit', code => logger.log({ code }, 'pack archive worker exited')) +process.on('exit', (code) => logger.log({ code }, 'pack archive worker exited')) -const processUpdates = pending => +const processUpdates = (pending) => async.eachSeries( pending, - function(result, callback) { + function (result, callback) { let _id ;({ _id, project_id, doc_id } = result) COUNT++ @@ -129,7 +129,7 @@ const processUpdates = pending => ) return callback() } - const handler = function(err, result) { + const handler = function (err, result) { if (err != null && err.code === 'InternalError' && err.retryable) { logger.warn( { err, result }, @@ -154,7 +154,7 @@ const processUpdates = pending => return PackManager.processOldPack(project_id, doc_id, _id, handler) } }, - function(err, results) { + function (err, results) { if (err != null && err.message !== 'shutdown') { logger.error({ err }, 'error in pack archive worker processUpdates') } @@ -163,7 +163,7 @@ const processUpdates = pending => ) // find the packs which can be archived -const ObjectIdFromDate = function(date) { +const ObjectIdFromDate = function (date) { const id = Math.floor(date.getTime() / 1000).toString(16) + '0000000000000000' return ObjectId(id) } @@ -191,13 +191,13 @@ if (pending != null) { .sort({ last_checked: 1 }) - .limit(LIMIT, function(err, results) { + .limit(LIMIT, function (err, results) { if (err != null) { logger.log({ err }, 'error checking for updates') finish() return } - pending = _.uniq(results, false, result => result.doc_id.toString()) + pending = _.uniq(results, false, (result) => result.doc_id.toString()) TOTAL = pending.length logger.log(`found ${TOTAL} documents to archive`) return processUpdates(pending) diff --git a/services/track-changes/app/js/PackWorker.js.map b/services/track-changes/app/js/PackWorker.js.map new file mode 100644 index 0000000000..ff2a9b07af --- /dev/null +++ b/services/track-changes/app/js/PackWorker.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "PackWorker.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/PackWorker.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EACR,CAAA,GAAI,OAAA,CAAQ,YAAR;;EACJ,MAAuB,OAAA,CAAQ,WAAR,CAAvB,EAAC,WAAD,EAAK,uBAAL,EAAe;;EACf,EAAA,GAAK,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C,CAMyC;MACxC,YAAA,EAAa,CAD2B;KANzC,CAQE,CAAC,KARH,CAQS,KART,EAQgB,SAAC,GAAD,EAAM,OAAN;MACf,IAAG,WAAH;QACC,MAAM,CAAC,GAAP,CAAW;UAAC,KAAA,GAAD;SAAX,EAAkB,4BAAlB;QACA,MAAA,CAAA;AACA,eAHD;;MAIA,OAAA,GAAU,CAAC,CAAC,IAAF,CAAO,OAAP,EAAgB,KAAhB,EAAuB,SAAC,MAAD;eAAY,MAAM,CAAC,MAAM,CAAC,QAAd,CAAA;MAAZ,CAAvB;MACV,KAAA,GAAQ,OAAO,CAAC;MAChB,MAAM,CAAC,GAAP,CAAW,QAAA,GAAS,KAAT,GAAe,uBAA1B;aACA,cAAA,CAAe,OAAf;IARe,CARhB,EALD;;AArHA" +} \ No newline at end of file diff --git a/services/track-changes/app/js/ProjectIterator.js b/services/track-changes/app/js/ProjectIterator.js index 589c68c241..43ddbc7b2f 100644 --- a/services/track-changes/app/js/ProjectIterator.js +++ b/services/track-changes/app/js/ProjectIterator.js @@ -62,7 +62,7 @@ module.exports = ProjectIterator = ProjectIterator = class ProjectIterator { nextPack.project_id, nextPack.doc_id, nextPack._id, - function(err, pack) { + function (err, pack) { if (err != null) { return callback(err) } diff --git a/services/track-changes/app/js/ProjectIterator.js.map b/services/track-changes/app/js/ProjectIterator.js.map new file mode 100644 index 0000000000..f6aa31a7d1 --- /dev/null +++ b/services/track-changes/app/js/ProjectIterator.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "ProjectIterator.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/ProjectIterator.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,IAAA,GAAO,OAAA,CAAQ,MAAR;;EAEP,MAAM,CAAC,OAAP,GAAiB,eAAA,GAEV;IACQ,yBAAC,KAAD,EAAQ,OAAR,EAAiB,aAAjB;AACZ,UAAA;MADoB,IAAC,CAAA,SAAD;MAAS,IAAC,CAAA,gBAAD;M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AAf,CAAA;AAEA;AAAA,eAAA,qCAAA;;kBAA8B,gBAAJ,IAAe,EAAE,CAAC,IAAI,CAAC,MAAR,GAAiB;;;YAEzD,EAAE,CAAC,MAAH,GAAY,QAAQ,CAAC;YACrB,EAAE,CAAC,UAAH,GAAgB,QAAQ,CAAC;YACzB,KAAK,CAAC,IAAN,CAAW,EAAX;AAJD;AAMA,iBAAO,QAAQ,CAAC,IAAT,CAAc,QAAd;QAVkE,CAAnE,EAFR;;AAeA,aAAM,kBAAA,IAAc,qBAAC,QAAQ,CAAE,IAAI,CAAC,gBAAf,GAAwB,YAAzB,CAApB;QACC,WAAW,CAAC,IAAZ,CAAiB,QAAjB;QACA,KAAK,CAAC,GAAN,CAAA;QACA,QAAA,GAAW,KAAK,CAAC,IAAN,CAAA;MAHZ;MAQA,IAAG,KAAK,CAAC,KAAN,CAAA,CAAA,IAAsB,kBAAzB;QACC,QAAQ,CAAC,KAAT,GAAiB,KADlB;;aAGA,QAAA,CAAS,IAAT,EAAe,WAAf;IAhDK;;8BAkDN,IAAA,GAAM,SAAA;AACL,aAAO,IAAC,CAAA;IADH;;;;;AA5DR" +} \ No newline at end of file diff --git a/services/track-changes/app/js/RedisManager.js b/services/track-changes/app/js/RedisManager.js index a4d8cb1167..5e762bf45a 100644 --- a/services/track-changes/app/js/RedisManager.js +++ b/services/track-changes/app/js/RedisManager.js @@ -22,7 +22,7 @@ const async = require('async') module.exports = RedisManager = { getOldestDocUpdates(doc_id, batchSize, callback) { if (callback == null) { - callback = function(error, jsonUpdates) {} + callback = function (error, jsonUpdates) {} } const key = Keys.uncompressedHistoryOps({ doc_id }) return rclient.lrange(key, 0, batchSize - 1, callback) @@ -31,10 +31,10 @@ module.exports = RedisManager = { expandDocUpdates(jsonUpdates, callback) { let rawUpdates if (callback == null) { - callback = function(error, rawUpdates) {} + callback = function (error, rawUpdates) {} } try { - rawUpdates = Array.from(jsonUpdates || []).map(update => + rawUpdates = Array.from(jsonUpdates || []).map((update) => JSON.parse(update) ) } catch (e) { @@ -45,14 +45,14 @@ module.exports = RedisManager = { deleteAppliedDocUpdates(project_id, doc_id, docUpdates, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } const multi = rclient.multi() // Delete all the updates which have been applied (exact match) for (const update of Array.from(docUpdates || [])) { multi.lrem(Keys.uncompressedHistoryOps({ doc_id }), 1, update) } - return multi.exec(function(error, results) { + return multi.exec(function (error, results) { if (error != null) { return callback(error) } @@ -61,7 +61,7 @@ module.exports = RedisManager = { return rclient.srem( Keys.docsWithHistoryOps({ project_id }), doc_id, - function(error) { + function (error) { if (error != null) { return callback(error) } @@ -73,7 +73,7 @@ module.exports = RedisManager = { getDocIdsWithHistoryOps(project_id, callback) { if (callback == null) { - callback = function(error, doc_ids) {} + callback = function (error, doc_ids) {} } return rclient.smembers(Keys.docsWithHistoryOps({ project_id }), callback) }, @@ -93,8 +93,8 @@ module.exports = RedisManager = { let cursor = 0 // redis iterator const keySet = {} // use hash to avoid duplicate results // scan over all keys looking for pattern - var doIteration = cb => - node.scan(cursor, 'MATCH', pattern, 'COUNT', 1000, function( + var doIteration = (cb) => + node.scan(cursor, 'MATCH', pattern, 'COUNT', 1000, function ( error, reply ) { @@ -132,11 +132,11 @@ module.exports = RedisManager = { getProjectIdsWithHistoryOps(callback) { if (callback == null) { - callback = function(error, project_ids) {} + callback = function (error, project_ids) {} } return RedisManager._getKeys( Keys.docsWithHistoryOps({ project_id: '*' }), - function(error, project_keys) { + function (error, project_keys) { if (error != null) { return callback(error) } @@ -150,11 +150,11 @@ module.exports = RedisManager = { // return all the docids, to find dangling history entries after // everything is flushed. if (callback == null) { - callback = function(error, doc_ids) {} + callback = function (error, doc_ids) {} } return RedisManager._getKeys( Keys.uncompressedHistoryOps({ doc_id: '*' }), - function(error, doc_keys) { + function (error, doc_keys) { if (error != null) { return callback(error) } diff --git a/services/track-changes/app/js/RedisManager.js.map b/services/track-changes/app/js/RedisManager.js.map new file mode 100644 index 0000000000..a0e01b35f6 --- /dev/null +++ b/services/track-changes/app/js/RedisManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "RedisManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/RedisManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,KAAA,GAAQ,OAAA,CAAQ,kBAAR;;EACR,OAAA,GAAU,KAAK,CAAC,YAAN,CAAmB,QAAQ,CAAC,KAAK,CAAC,OAAlC;;EACV,IAAA,GAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;;EAC9B,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EAER,MAAM,CAAC,OAAP,GAAiB,YAAA,GAEhB;IAAA,mBAAA,EAAqB,SAAC,MAAD,EAAS,SAAT,EAAoB,QAApB;AACpB,UAAA;;QADwC,WAAW,SAAC,KAAD,EAAQ,WAAR,GAAA;;MACnD,GAAA,GAAM,IAAI,CAAC,sBAAL,CAA4B;QAAC,QAAA,MAAD;OAA5B;aACN,OAAO,CAAC,MAAR,CAAe,GAAf,EAAoB,CAApB,EAAuB,SAAA,GAAY,CAAnC,EAAsC,QAAtC;IAFoB,CAArB;IAIA,gBAAA,EAAkB,SAAC,WAAD,EAAc,QAAd;AACjB,UAAA;;QAD+B,WAAW,SAAC,KAAD,EAAQ,UAAR,GAAA;;AAC1C;QACC,UAAA;;AAAe;AAAA;eAAA,qCAAA;;0BAAA,IAAI,CAAC,KAAL,CAAW,MAAX;AAAA;;aADhB;OAAA,cAAA;QAEM;AACL,eAAO,QAAA,CAAS,CAAT,EAHR;;aAIA,QAAA,CAAS,IAAT,EAAe,UAAf;IALiB,CAJlB;IAWA,uBAAA,EAAyB,SAAC,UAAD,EAAa,MAAb,EAAqB,UAArB,EAAiC,QAAjC;AACxB,UAAA;;QADyD,WAAW,SAAC,KAAD,GAAA;;MACpE,KAAA,GAAQ,OAAO,CAAC,KAAR,CAAA;AAER;AAAA,WAAA,q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S,KAAT,EAAP;;QACA,OAAA,GAAU,YAAY,CAAC,WAAb,CAAyB,QAAzB;eACV,QAAA,CAAS,KAAT,EAAgB,OAAhB;MAHgE,CAAjE;IAH2B,CAjE5B;;AARD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/RestoreManager.js b/services/track-changes/app/js/RestoreManager.js index cc365f6709..6a1af1af44 100644 --- a/services/track-changes/app/js/RestoreManager.js +++ b/services/track-changes/app/js/RestoreManager.js @@ -19,14 +19,14 @@ const logger = require('logger-sharelatex') module.exports = RestoreManager = { restoreToBeforeVersion(project_id, doc_id, version, user_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } logger.log({ project_id, doc_id, version, user_id }, 'restoring document') return DiffManager.getDocumentBeforeVersion( project_id, doc_id, version, - function(error, content) { + function (error, content) { if (error != null) { return callback(error) } @@ -35,7 +35,7 @@ module.exports = RestoreManager = { doc_id, content, user_id, - function(error) { + function (error) { if (error != null) { return callback(error) } diff --git a/services/track-changes/app/js/RestoreManager.js.map b/services/track-changes/app/js/RestoreManager.js.map new file mode 100644 index 0000000000..b9ab8c044c --- /dev/null +++ b/services/track-changes/app/js/RestoreManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "RestoreManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/RestoreManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,sBAAA,GAAyB,OAAA,CAAQ,0BAAR;;EACzB,WAAA,GAAc,OAAA,CAAQ,eAAR;;EACd,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EAET,MAAM,CAAC,OAAP,GAAiB,cAAA,GAChB;IAAA,sBAAA,EAAwB,SAAC,UAAD,EAAa,MAAb,EAAqB,OAArB,EAA8B,OAA9B,EAAuC,QAAvC;;QAAuC,WAAW,SAAC,KAAD,GAAA;;MACzE,MAAM,CAAC,GAAP,CAAW;QAAA,UAAA,EAAY,UAAZ;QAAwB,MAAA,EAAQ,MAAhC;QAAwC,OAAA,EAAS,OAAjD;QAA0D,OAAA,EAAS,OAAnE;OAAX,EAAuF,oBAAvF;aACA,WAAW,CAAC,wBAAZ,CAAqC,UAArC,EAAiD,MAAjD,EAAyD,OAAzD,EAAkE,SAAC,KAAD,EAAQ,OAAR;QACjE,IAA0B,aAA1B;AAAA,iBAAO,QAAA,CAAS,KAAT,EAAP;;eACA,sBAAsB,CAAC,WAAvB,CAAmC,UAAnC,EAA+C,MAA/C,EAAuD,OAAvD,EAAgE,OAAhE,EAAyE,SAAC,KAAD;UACxE,IAA0B,aAA1B;AAAA,mBAAO,QAAA,CAAS,KAAT,EAAP;;iBACA,QAAA,CAAA;QAFwE,CAAzE;MAFiE,CAAlE;IAFuB,CAAxB;;AALD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/UpdateCompressor.js b/services/track-changes/app/js/UpdateCompressor.js index 570bc97a61..019ad32760 100644 --- a/services/track-changes/app/js/UpdateCompressor.js +++ b/services/track-changes/app/js/UpdateCompressor.js @@ -42,7 +42,7 @@ module.exports = UpdateCompressor = { const splitUpdates = [] for (const update of Array.from(updates)) { // Reject any non-insert or delete ops, i.e. comments - const ops = update.op.filter(o => o.i != null || o.d != null) + const ops = update.op.filter((o) => o.i != null || o.d != null) if (ops.length === 0) { splitUpdates.push({ op: UpdateCompressor.NOOP, @@ -97,7 +97,7 @@ module.exports = UpdateCompressor = { if ( __guard__( lastPreviousUpdate != null ? lastPreviousUpdate.op : undefined, - x => x.length + (x) => x.length ) > 1 ) { // if the last previous update was an array op, don't compress onto it. @@ -183,7 +183,8 @@ module.exports = UpdateCompressor = { if ( firstOp.i != null && secondOp.i != null && - firstOp.p <= secondOp.p && secondOp.p <= firstOp.p + firstOp.i.length && + firstOp.p <= secondOp.p && + secondOp.p <= firstOp.p + firstOp.i.length && firstSize + secondSize < UpdateCompressor.MAX_UPDATE_SIZE ) { return [ @@ -204,7 +205,8 @@ module.exports = UpdateCompressor = { } else if ( firstOp.d != null && secondOp.d != null && - secondOp.p <= firstOp.p && firstOp.p <= secondOp.p + secondOp.d.length && + secondOp.p <= firstOp.p && + firstOp.p <= secondOp.p + secondOp.d.length && firstSize + secondSize < UpdateCompressor.MAX_UPDATE_SIZE ) { return [ @@ -225,7 +227,8 @@ module.exports = UpdateCompressor = { } else if ( firstOp.i != null && secondOp.d != null && - firstOp.p <= secondOp.p && secondOp.p <= firstOp.p + firstOp.i.length + firstOp.p <= secondOp.p && + secondOp.p <= firstOp.p + firstOp.i.length ) { offset = secondOp.p - firstOp.p const insertedText = firstOp.i.slice(offset, offset + secondOp.d.length) @@ -276,7 +279,7 @@ module.exports = UpdateCompressor = { } ] } else { - return diff_ops.map(function(op) { + return diff_ops.map(function (op) { op.p += offset return { meta: { @@ -299,7 +302,7 @@ module.exports = UpdateCompressor = { UNCHANGED: 0, diffAsShareJsOps(before, after, callback) { if (callback == null) { - callback = function(error, ops) {} + callback = function (error, ops) {} } const diffs = dmp.diff_main(before, after) dmp.diff_cleanupSemantic(diffs) diff --git a/services/track-changes/app/js/UpdateCompressor.js.map b/services/track-changes/app/js/UpdateCompressor.js.map new file mode 100644 index 0000000000..6ff4402373 --- /dev/null +++ b/services/track-changes/app/js/UpdateCompressor.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "UpdateCompressor.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/UpdateCompressor.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,SAAA,GAAY,SAAC,EAAD,EAAK,GAAL,EAAU,EAAV;WAAiB,EAAG,cAAH,GAAa,EAAb,GAAkB,EAAG;EAAtC;;EACZ,SAAA,GAAY,SAAC,EAAD,EAAK,GAAL,EAAU,MAAV;WAAqB,EAAG,cAAH,GAAa,EAAG;EAArC;;EAEZ,gBAAA,GAAmB,OAAA,CAAQ,yBAAR,CAAkC,CAAC;;EACtD,GAAA,GAAM,IAAI,gBAAJ,CAAA;;EAEN,MAAM,CAAC,OAAP,GAAiB,gBAAA,GAChB;IAAA,I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AA,GAAQ,GAAG,CAAC,SAAJ,CAAc,MAAd,EAAsB,KAAtB;MACR,GAAG,CAAC,oBAAJ,CAAyB,KAAzB;MAEA,GAAA,GAAM;MACN,QAAA,GAAW;AACX,WAAA,uCAAA;;QACC,IAAA,GAAO,IAAK,CAAA,CAAA;QACZ,OAAA,GAAU,IAAK,CAAA,CAAA;QACf,IAAG,IAAA,KAAQ,IAAC,CAAA,KAAZ;UACC,GAAG,CAAC,IAAJ,CACC;YAAA,CAAA,EAAG,OAAH;YACA,CAAA,EAAG,QADH;WADD;UAGA,QAAA,IAAY,OAAO,CAAC,OAJrB;SAAA,MAKK,IAAG,IAAA,KAAQ,IAAC,CAAA,OAAZ;UACJ,GAAG,CAAC,IAAJ,CACC;YAAA,CAAA,EAAG,OAAH;YACA,CAAA,EAAG,QADH;WADD,EADI;SAAA,MAIA,IAAG,IAAA,KAAQ,IAAC,CAAA,SAAZ;UACJ,QAAA,IAAY,OAAO,CAAC,OADhB;SAAA,MAAA;AAGJ,gBAAM,eAHF;;AAZN;AAgBA,aAAO;IAtBU,CA5LlB;;AAPD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/UpdateTrimmer.js b/services/track-changes/app/js/UpdateTrimmer.js index 8a37e5484f..5fabe1cb9e 100644 --- a/services/track-changes/app/js/UpdateTrimmer.js +++ b/services/track-changes/app/js/UpdateTrimmer.js @@ -20,9 +20,9 @@ const logger = require('logger-sharelatex') module.exports = UpdateTrimmer = { shouldTrimUpdates(project_id, callback) { if (callback == null) { - callback = function(error, shouldTrim) {} + callback = function (error, shouldTrim) {} } - return MongoManager.getProjectMetaData(project_id, function( + return MongoManager.getProjectMetaData(project_id, function ( error, metadata ) { @@ -32,7 +32,7 @@ module.exports = UpdateTrimmer = { if (metadata != null ? metadata.preserveHistory : undefined) { return callback(null, false) } else { - return WebApiManager.getProjectDetails(project_id, function( + return WebApiManager.getProjectDetails(project_id, function ( error, details ) { @@ -43,17 +43,19 @@ module.exports = UpdateTrimmer = { if ( __guard__( details != null ? details.features : undefined, - x => x.versioning + (x) => x.versioning ) ) { return MongoManager.setProjectMetaData( project_id, { preserveHistory: true }, - function(error) { + function (error) { if (error != null) { return callback(error) } - return MongoManager.upgradeHistory(project_id, function(error) { + return MongoManager.upgradeHistory(project_id, function ( + error + ) { if (error != null) { return callback(error) } diff --git a/services/track-changes/app/js/UpdateTrimmer.js.map b/services/track-changes/app/js/UpdateTrimmer.js.map new file mode 100644 index 0000000000..72f24be153 --- /dev/null +++ b/services/track-changes/app/js/UpdateTrimmer.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "UpdateTrimmer.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/UpdateTrimmer.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,YAAA,GAAe,OAAA,CAAQ,gBAAR;;EACf,aAAA,GAAgB,OAAA,CAAQ,iBAAR;;EAChB,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EAET,MAAM,CAAC,OAAP,GAAiB,aAAA,GAChB;IAAA,iBAAA,EAAmB,SAAC,UAAD,EAAa,QAAb;;QAAa,WAAW,SAAC,KAAD,EAAQ,UAAR,GAAA;;aAC1C,YAAY,CAAC,kBAAb,CAAgC,UAAhC,EAA4C,SAAC,KAAD,EAAQ,QAAR;QAC3C,IAA0B,aAA1B;AAAA,iBAAO,QAAA,CAAS,KAAT,EAAP;;QACA,uBAAG,QAAQ,CAAE,wBAAb;AACC,iBAAO,QAAA,CAAS,IAAT,EAAe,KAAf,EADR;SAAA,MAAA;iBAGC,aAAa,CAAC,iBAAd,CAAgC,UAAhC,EAA4C,SAAC,KAAD,EAAQ,OAAR;AAC3C,gBAAA;YAAA,IAA0B,aAA1B;AAAA,qBAAO,QAAA,CAAS,KAAT,EAAP;;YACA,MAAM,CAAC,GAAP,CAAW;cAAA,UAAA,EAAY,UAAZ;cAAwB,OAAA,EAAS,OAAjC;aAAX,EAAqD,aAArD;YACA,4DAAoB,CAAE,4BAAtB;qBACC,YAAY,CAAC,kBAAb,CAAgC,UAAhC,EAA4C;gBAAA,eAAA,EAAiB,IAAjB;eAA5C,EAAmE,SAAC,KAAD;gBAClE,IAA0B,aAA1B;AAAA,yBAAO,QAAA,CAAS,KAAT,EAAP;;uBACA,YAAY,CAAC,cAAb,CAA4B,UAA5B,EAAwC,SAAC,KAAD;kBACvC,IAA0B,aAA1B;AAAA,2BAAO,QAAA,CAAS,KAAT,EAAP;;yBACA,QAAA,CAAS,IAAT,EAAe,KAAf;gBAFuC,CAAxC;cAFkE,CAAnE,EADD;aAAA,MAAA;qBAOC,QAAA,CAAS,IAAT,EAAe,IAAf,EAPD;;UAH2C,CAA5C,EAHD;;MAF2C,CAA5C;IADkB,CAAnB;;AALD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/UpdatesManager.js b/services/track-changes/app/js/UpdatesManager.js index 89da68a631..811e9ba1ca 100644 --- a/services/track-changes/app/js/UpdatesManager.js +++ b/services/track-changes/app/js/UpdatesManager.js @@ -38,7 +38,7 @@ module.exports = UpdatesManager = { ) { let i if (callback == null) { - callback = function(error) {} + callback = function (error) {} } const { length } = rawUpdates if (length === 0) { @@ -50,7 +50,7 @@ module.exports = UpdatesManager = { const op = rawUpdates[i] if (i > 0) { const thisVersion = op != null ? op.v : undefined - const prevVersion = __guard__(rawUpdates[i - 1], x => x.v) + const prevVersion = __guard__(rawUpdates[i - 1], (x) => x.v) if (!(prevVersion < thisVersion)) { logger.error( { @@ -69,7 +69,7 @@ module.exports = UpdatesManager = { // FIXME: we no longer need the lastCompressedUpdate, so change functions not to need it // CORRECTION: we do use it to log the time in case of error - return MongoManager.peekLastCompressedUpdate(doc_id, function( + return MongoManager.peekLastCompressedUpdate(doc_id, function ( error, lastCompressedUpdate, lastVersion @@ -105,7 +105,7 @@ module.exports = UpdatesManager = { lastCompressedUpdate != null ? lastCompressedUpdate.meta : undefined, - x1 => x1.end_ts + (x1) => x1.end_ts ) const last_timestamp = ts != null ? new Date(ts) : 'unknown time' error = new Error( @@ -179,7 +179,7 @@ module.exports = UpdatesManager = { lastCompressedUpdate, compressedUpdates, temporary, - function(error, result) { + function (error, result) { if (error != null) { return callback(error) } @@ -206,9 +206,9 @@ module.exports = UpdatesManager = { // Check whether the updates are temporary (per-project property) _prepareProjectForUpdates(project_id, callback) { if (callback == null) { - callback = function(error, temporary) {} + callback = function (error, temporary) {} } - return UpdateTrimmer.shouldTrimUpdates(project_id, function( + return UpdateTrimmer.shouldTrimUpdates(project_id, function ( error, temporary ) { @@ -222,9 +222,9 @@ module.exports = UpdatesManager = { // Check for project id on document history (per-document property) _prepareDocForUpdates(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } - return MongoManager.backportProjectId(project_id, doc_id, function(error) { + return MongoManager.backportProjectId(project_id, doc_id, function (error) { if (error != null) { return callback(error) } @@ -237,18 +237,18 @@ module.exports = UpdatesManager = { processUncompressedUpdates(project_id, doc_id, temporary, callback) { // get the updates as strings from redis (so we can delete them after they are applied) if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return RedisManager.getOldestDocUpdates( doc_id, UpdatesManager.REDIS_READ_BATCH_SIZE, - function(error, docUpdates) { + function (error, docUpdates) { if (error != null) { return callback(error) } const { length } = docUpdates // parse the redis strings into ShareJs updates - return RedisManager.expandDocUpdates(docUpdates, function( + return RedisManager.expandDocUpdates(docUpdates, function ( error, rawUpdates ) { @@ -268,7 +268,7 @@ module.exports = UpdatesManager = { doc_id, rawUpdates, temporary, - function(error) { + function (error) { if (error != null) { return callback(error) } @@ -281,7 +281,7 @@ module.exports = UpdatesManager = { project_id, doc_id, docUpdates, - function(error) { + function (error) { if (error != null) { return callback(error) } @@ -320,9 +320,9 @@ module.exports = UpdatesManager = { // Process updates for a doc when we flush it individually processUncompressedUpdatesWithLock(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } - return UpdatesManager._prepareProjectForUpdates(project_id, function( + return UpdatesManager._prepareProjectForUpdates(project_id, function ( error, temporary ) { @@ -346,9 +346,9 @@ module.exports = UpdatesManager = { callback ) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } - return UpdatesManager._prepareDocForUpdates(project_id, doc_id, function( + return UpdatesManager._prepareDocForUpdates(project_id, doc_id, function ( error ) { if (error != null) { @@ -356,7 +356,7 @@ module.exports = UpdatesManager = { } return LockManager.runWithLock( keys.historyLock({ doc_id }), - releaseLock => + (releaseLock) => UpdatesManager.processUncompressedUpdates( project_id, doc_id, @@ -371,23 +371,23 @@ module.exports = UpdatesManager = { // Process all updates for a project, only check project-level information once processUncompressedUpdatesForProject(project_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } - return RedisManager.getDocIdsWithHistoryOps(project_id, function( + return RedisManager.getDocIdsWithHistoryOps(project_id, function ( error, doc_ids ) { if (error != null) { return callback(error) } - return UpdatesManager._prepareProjectForUpdates(project_id, function( + return UpdatesManager._prepareProjectForUpdates(project_id, function ( error, temporary ) { const jobs = [] for (const doc_id of Array.from(doc_ids)) { - ;(doc_id => - jobs.push(cb => + ;((doc_id) => + jobs.push((cb) => UpdatesManager._processUncompressedUpdatesForDocWithLock( project_id, doc_id, @@ -404,9 +404,9 @@ module.exports = UpdatesManager = { // flush all outstanding changes flushAll(limit, callback) { if (callback == null) { - callback = function(error, result) {} + callback = function (error, result) {} } - return RedisManager.getProjectIdsWithHistoryOps(function( + return RedisManager.getProjectIdsWithHistoryOps(function ( error, project_ids ) { @@ -426,15 +426,15 @@ module.exports = UpdatesManager = { const selectedProjects = limit < 0 ? project_ids : project_ids.slice(0, limit) for (project_id of Array.from(selectedProjects)) { - ;(project_id => - jobs.push(cb => + ;((project_id) => + jobs.push((cb) => UpdatesManager.processUncompressedUpdatesForProject( project_id, - err => cb(null, { failed: err != null, project_id }) + (err) => cb(null, { failed: err != null, project_id }) ) ))(project_id) } - return async.series(jobs, function(error, result) { + return async.series(jobs, function (error, result) { let x if (error != null) { return callback(error) @@ -468,16 +468,16 @@ module.exports = UpdatesManager = { getDanglingUpdates(callback) { if (callback == null) { - callback = function(error, doc_ids) {} + callback = function (error, doc_ids) {} } - return RedisManager.getAllDocIdsWithHistoryOps(function( + return RedisManager.getAllDocIdsWithHistoryOps(function ( error, all_doc_ids ) { if (error != null) { return callback(error) } - return RedisManager.getProjectIdsWithHistoryOps(function( + return RedisManager.getProjectIdsWithHistoryOps(function ( error, all_project_ids ) { @@ -485,14 +485,14 @@ module.exports = UpdatesManager = { return callback(error) } // function to get doc_ids for each project - const task = cb => + const task = (cb) => async.concatSeries( all_project_ids, RedisManager.getDocIdsWithHistoryOps, cb ) // find the dangling doc ids - return task(function(error, project_doc_ids) { + return task(function (error, project_doc_ids) { const dangling_doc_ids = _.difference(all_doc_ids, project_doc_ids) logger.log( { all_doc_ids, all_project_ids, project_doc_ids, dangling_doc_ids }, @@ -509,12 +509,12 @@ module.exports = UpdatesManager = { options = {} } if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } return UpdatesManager.processUncompressedUpdatesWithLock( project_id, doc_id, - function(error) { + function (error) { if (error != null) { return callback(error) } @@ -524,7 +524,7 @@ module.exports = UpdatesManager = { doc_id, options.from, options.to, - function(error, updates) { + function (error, updates) { if (error != null) { return callback(error) } @@ -540,16 +540,16 @@ module.exports = UpdatesManager = { options = {} } if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } - return UpdatesManager.getDocUpdates(project_id, doc_id, options, function( + return UpdatesManager.getDocUpdates(project_id, doc_id, options, function ( error, updates ) { if (error != null) { return callback(error) } - return UpdatesManager.fillUserInfo(updates, function(error, updates) { + return UpdatesManager.fillUserInfo(updates, function (error, updates) { if (error != null) { return callback(error) } @@ -563,7 +563,7 @@ module.exports = UpdatesManager = { options = {} } if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } if (!options.min_count) { options.min_count = 25 @@ -573,11 +573,11 @@ module.exports = UpdatesManager = { let nextBeforeTimestamp = null return UpdatesManager.processUncompressedUpdatesForProject( project_id, - function(error) { + function (error) { if (error != null) { return callback(error) } - return PackManager.makeProjectIterator(project_id, before, function( + return PackManager.makeProjectIterator(project_id, before, function ( err, iterator ) { @@ -590,8 +590,8 @@ module.exports = UpdatesManager = { // console.log "checking iterator.done", iterator.done() summarizedUpdates.length < options.min_count && !iterator.done(), - cb => - iterator.next(function(err, partialUpdates) { + (cb) => + iterator.next(function (err, partialUpdates) { if (err != null) { return callback(err) } @@ -612,19 +612,19 @@ module.exports = UpdatesManager = { () => // finally done all updates // console.log 'summarized Updates', summarizedUpdates - UpdatesManager.fillSummarizedUserInfo(summarizedUpdates, function( - err, - results - ) { - if (err != null) { - return callback(err) + UpdatesManager.fillSummarizedUserInfo( + summarizedUpdates, + function (err, results) { + if (err != null) { + return callback(err) + } + return callback( + null, + results, + !iterator.done() ? nextBeforeTimestamp : undefined + ) } - return callback( - null, - results, - !iterator.done() ? nextBeforeTimestamp : undefined - ) - }) + ) ) }) } @@ -633,14 +633,14 @@ module.exports = UpdatesManager = { fetchUserInfo(users, callback) { if (callback == null) { - callback = function(error, fetchedUserInfo) {} + callback = function (error, fetchedUserInfo) {} } const jobs = [] const fetchedUserInfo = {} for (const user_id in users) { - ;(user_id => - jobs.push(callback => - WebApiManager.getUserInfo(user_id, function(error, userInfo) { + ;((user_id) => + jobs.push((callback) => + WebApiManager.getUserInfo(user_id, function (error, userInfo) { if (error != null) { return callback(error) } @@ -650,7 +650,7 @@ module.exports = UpdatesManager = { ))(user_id) } - return async.series(jobs, function(err) { + return async.series(jobs, function (err) { if (err != null) { return callback(err) } @@ -661,7 +661,7 @@ module.exports = UpdatesManager = { fillUserInfo(updates, callback) { let update, user_id if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } const users = {} for (update of Array.from(updates)) { @@ -671,7 +671,7 @@ module.exports = UpdatesManager = { } } - return UpdatesManager.fetchUserInfo(users, function( + return UpdatesManager.fetchUserInfo(users, function ( error, fetchedUserInfo ) { @@ -692,7 +692,7 @@ module.exports = UpdatesManager = { fillSummarizedUserInfo(updates, callback) { let update, user_id, user_ids if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } const users = {} for (update of Array.from(updates)) { @@ -704,7 +704,7 @@ module.exports = UpdatesManager = { } } - return UpdatesManager.fetchUserInfo(users, function( + return UpdatesManager.fetchUserInfo(users, function ( error, fetchedUserInfo ) { diff --git a/services/track-changes/app/js/UpdatesManager.js.map b/services/track-changes/app/js/UpdatesManager.js.map new file mode 100644 index 0000000000..32c9cdd909 --- /dev/null +++ b/services/track-changes/app/js/UpdatesManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "UpdatesManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/UpdatesManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,YAAA,GAAe,OAAA,CAAQ,gBAAR;;EACf,WAAA,GAAc,OAAA,CAAQ,eAAR;;EACd,YAAA,GAAe,OAAA,CAAQ,gBAAR;;EACf,gBAAA,GAAmB,OAAA,CAAQ,oBAAR;;EACnB,WAAA,GAAc,OAAA,CAAQ,eAAR;;EACd,aAAA,GAAgB,OAAA,CAAQ,iBAAR;;EAChB,aAAA,GAAgB,OAAA,CAAQ,iBAAR;;EAChB,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EACR,CAAA,GAAI,OAAA,CAAQ,YAAR;;EACJ,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,IAAA,GAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;;EAE3B,MAAM,CAAC,OAAP,GAAiB,cAAA,GAChB;IAAA,yBAAA,EAA2B,SAAC,UAAD,EAAa,MAAb,EAAqB,UAArB,EAAiC,SAAjC,EAA4C,QAA5C;AAC1B,UAAA;;QADsE,WAAW,SAAC,KAAD,GAAA;;MACjF,MAAA,GAAS,UAAU,CAAC;MACpB,IAAG,MAAA,KAAU,CAAb;AACC,eAAO,QAAA,CAAA,EADR;;AA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B,EAAuC,MAAM,CAAC,IAAI,CAAC,QAAnD;UAC/B,cAAc,CAAC,IAAI,CAAC,MAApB,GAA+B,IAAI,CAAC,GAAL,CAAS,cAAc,CAAC,IAAI,CAAC,MAA7B,EAAqC,MAAM,CAAC,IAAI,CAAC,MAAjD,EAhBhC;SAAA,MAAA;UAkBC,SAAA,GACC;YAAA,IAAA,EACC;cAAA,QAAA,EAAU,EAAV;cACA,QAAA,EAAU,MAAM,CAAC,IAAI,CAAC,QADtB;cAEA,MAAA,EAAQ,MAAM,CAAC,IAAI,CAAC,MAFpB;aADD;YAIA,IAAA,EAAM,EAJN;;UAMD,SAAS,CAAC,IAAK,CAAA,MAAM,CAAC,MAAM,CAAC,QAAd,CAAA,CAAA,CAAf,GACC;YAAA,KAAA,EAAO,MAAM,CAAC,CAAd;YACA,GAAA,EAAK,MAAM,CAAC,CADZ;;UAED,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAxB,CAA6B,MAAM,CAAC,IAAI,CAAC,OAAzC;UACA,iBAAiB,CAAC,IAAlB,CAAuB,SAAvB,EA7BD;;AAxBD;AAuDA,aAAO;IA1DW,CA/QnB;;AAdD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/WebApiManager.js b/services/track-changes/app/js/WebApiManager.js index 937b767ab2..2ab3bdfda1 100644 --- a/services/track-changes/app/js/WebApiManager.js +++ b/services/track-changes/app/js/WebApiManager.js @@ -26,7 +26,7 @@ const MAX_HTTP_REQUEST_LENGTH = 15000 // 15 seconds module.exports = WebApiManager = { sendRequest(url, callback) { if (callback == null) { - callback = function(error, body) {} + callback = function (error, body) {} } return request.get( { @@ -39,7 +39,7 @@ module.exports = WebApiManager = { sendImmediately: true } }, - function(error, res, body) { + function (error, res, body) { if (error != null) { return callback(error) } @@ -61,11 +61,11 @@ module.exports = WebApiManager = { getUserInfo(user_id, callback) { if (callback == null) { - callback = function(error, userInfo) {} + callback = function (error, userInfo) {} } const url = `/user/${user_id}/personal_info` logger.log({ user_id }, 'getting user info from web') - return WebApiManager.sendRequest(url, function(error, body) { + return WebApiManager.sendRequest(url, function (error, body) { let user if (error != null) { logger.error({ err: error, user_id, url }, 'error accessing web') @@ -93,11 +93,11 @@ module.exports = WebApiManager = { getProjectDetails(project_id, callback) { if (callback == null) { - callback = function(error, details) {} + callback = function (error, details) {} } const url = `/project/${project_id}/details` logger.log({ project_id }, 'getting project details from web') - return WebApiManager.sendRequest(url, function(error, body) { + return WebApiManager.sendRequest(url, function (error, body) { let project if (error != null) { logger.error({ err: error, project_id, url }, 'error accessing web') diff --git a/services/track-changes/app/js/WebApiManager.js.map b/services/track-changes/app/js/WebApiManager.js.map new file mode 100644 index 0000000000..1ef0953f13 --- /dev/null +++ b/services/track-changes/app/js/WebApiManager.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "WebApiManager.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/WebApiManager.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,OAAA,GAAU,OAAA,CAAQ,cAAR;;EACV,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EAGX,uBAAA,GAA0B;;EAO1B,MAAM,CAAC,OAAP,GAAiB,aAAA,GAChB;IAAA,WAAA,EAAa,SAAC,GAAD,EAAM,QAAN;;QAAM,WAAW,SAAC,KAAD,EAAQ,IAAR,GAAA;;aAC7B,OAAO,CAAC,GAAR,CAAY;QACX,GAAA,EAAK,EAAA,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAArB,GAA2B,GADrB;QAEX,OAAA,EAAS,uBAFE;QAGX,WAAA,EAAa,CAHF;QAIX,IAAA,EACC;UAAA,IAAA,EAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAxB;UACA,IAAA,EAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IADxB;UAEA,eAAA,EAAiB,IAFjB;SALU;OAAZ,EAQG,SAAC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,EAFR;;AAGA;UACC,IAAA,GAAO,IAAI,CAAC,KAAL,CAAW,IAAX,EADR;SAAA,cAAA;UAEM;AACL,iBAAO,QAAA,CAAS,KAAT,EAHR;;eAIA,QAAA,CAAS,IAAT,EAAe;UACd,EAAA,EAAI,IAAI,CAAC,EADK;UAEd,KAAA,EAAO,IAAI,CAAC,KAFE;UAGd,UAAA,EAAY,IAAI,CAAC,UAHH;UAId,SAAA,EAAW,IAAI,CAAC,SAJF;SAAf;MAZ8B,CAA/B;IAHY,CArBb;IA2CA,iBAAA,EAAmB,SAAC,UAAD,EAAa,QAAb;AAClB,UAAA;;QAD+B,WAAW,SAAC,KAAD,EAAQ,OAAR,GAAA;;MAC1C,GAAA,GAAM,WAAA,GAAY,UAAZ,GAAuB;MAC7B,MAAM,CAAC,GAAP,CAAW;QAAA,UAAA,EAAY,UAAZ;OAAX,EAAmC,kCAAnC;aACA,aAAa,CAAC,WAAd,CAA0B,GAA1B,EAA+B,SAAC,KAAD,EAAQ,IAAR;AAC9B,YAAA;QAAA,IAAG,aAAH;UACC,MAAM,CAAC,KAAP,CAAa;YAAA,GAAA,EAAK,KAAL;YAAY,UAAA,EAAY,UAAxB;YAAoC,GAAA,EAAK,GAAzC;WAAb,EAA2D,qBAA3D;AACA,iBAAO,QAAA,CAAS,KAAT,EAFR;;AAIA;UACC,OAAA,GAAU,IAAI,CAAC,KAAL,CAAW,IAAX,EADX;SAAA,cAAA;UAEM;AACL,iBAAO,QAAA,CAAS,KAAT,EAHR;;eAIA,QAAA,CAAS,IAAT,EAAe,OAAf;MAT8B,CAA/B;IAHkB,CA3CnB;;AAbD" +} \ No newline at end of file diff --git a/services/track-changes/app/js/mongojs.js.map b/services/track-changes/app/js/mongojs.js.map new file mode 100644 index 0000000000..9c2dbd94d8 --- /dev/null +++ b/services/track-changes/app/js/mongojs.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "mongojs.js", + "sourceRoot": "../..", + "sources": [ + "app/coffee/mongojs.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,OAAA,GAAU,OAAA,CAAQ,SAAR;;EACV,IAAA,GAAO,OAAA,CAAQ,MAAR;;EACP,EAAA,GAAK,OAAA,CAAQ,QAAQ,CAAC,KAAK,CAAC,GAAvB,EAA4B,CAAC,YAAD,EAAe,wBAAf,EAAyC,iBAAzC,CAA5B;;EACL,MAAM,CAAC,OAAP,GACC;IAAA,EAAA,EAAI,EAAJ;IACA,QAAA,EAAU,OAAO,CAAC,QADlB;IAEA,IAAA,EAAM,IAAI,IAAI,CAAC,QAAT,CAAA,CAFN;;AALD" +} \ No newline at end of file diff --git a/services/track-changes/app/lib/diff_match_patch.js b/services/track-changes/app/lib/diff_match_patch.js index 112130e097..c4864d7bde 100644 --- a/services/track-changes/app/lib/diff_match_patch.js +++ b/services/track-changes/app/lib/diff_match_patch.js @@ -28,48 +28,44 @@ * @constructor */ function diff_match_patch() { - // Defaults. // Redefine these in your program to override the defaults. // Number of seconds to map a diff before giving up (0 for infinity). - this.Diff_Timeout = 1.0; + this.Diff_Timeout = 1.0 // Cost of an empty edit operation in terms of edit characters. - this.Diff_EditCost = 4; + this.Diff_EditCost = 4 // At what point is no match declared (0.0 = perfection, 1.0 = very loose). - this.Match_Threshold = 0.5; + this.Match_Threshold = 0.5 // How far to search for a match (0 = exact location, 1000+ = broad match). // A match this many characters away from the expected location will add // 1.0 to the score (0.0 is a perfect match). - this.Match_Distance = 1000; + this.Match_Distance = 1000 // When deleting a large block of text (over ~64 characters), how close do // the contents have to be to match the expected contents. (0.0 = perfection, // 1.0 = very loose). Note that Match_Threshold controls how closely the // end points of a delete need to match. - this.Patch_DeleteThreshold = 0.5; + this.Patch_DeleteThreshold = 0.5 // Chunk size for context length. - this.Patch_Margin = 4; + this.Patch_Margin = 4 // The number of bits in an int. - this.Match_MaxBits = 32; + this.Match_MaxBits = 32 } - // DIFF FUNCTIONS - /** * The data structure representing a diff is an array of tuples: * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] * which means: delete 'Hello', add 'Goodbye' and keep ' world.' */ -var DIFF_DELETE = -1; -var DIFF_INSERT = 1; -var DIFF_EQUAL = 0; +var DIFF_DELETE = -1 +var DIFF_INSERT = 1 +var DIFF_EQUAL = 0 /** @typedef {{0: number, 1: string}} */ -diff_match_patch.Diff; - +diff_match_patch.Diff /** * Find the differences between two texts. Simplifies the problem by stripping @@ -84,62 +80,65 @@ diff_match_patch.Diff; * instead. * @return {!Array.} Array of diff tuples. */ -diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, - opt_deadline) { +diff_match_patch.prototype.diff_main = function ( + text1, + text2, + opt_checklines, + opt_deadline +) { // Set a deadline by which time the diff must be complete. - if (typeof opt_deadline == 'undefined') { + if (typeof opt_deadline === 'undefined') { if (this.Diff_Timeout <= 0) { - opt_deadline = Number.MAX_VALUE; + opt_deadline = Number.MAX_VALUE } else { - opt_deadline = (new Date).getTime() + this.Diff_Timeout * 1000; + opt_deadline = new Date().getTime() + this.Diff_Timeout * 1000 } } - var deadline = opt_deadline; + var deadline = opt_deadline // Check for null inputs. if (text1 == null || text2 == null) { - throw new Error('Null input. (diff_main)'); + throw new Error('Null input. (diff_main)') } // Check for equality (speedup). if (text1 == text2) { if (text1) { - return [[DIFF_EQUAL, text1]]; + return [[DIFF_EQUAL, text1]] } - return []; + return [] } - if (typeof opt_checklines == 'undefined') { - opt_checklines = true; + if (typeof opt_checklines === 'undefined') { + opt_checklines = true } - var checklines = opt_checklines; + var checklines = opt_checklines // Trim off common prefix (speedup). - var commonlength = this.diff_commonPrefix(text1, text2); - var commonprefix = text1.substring(0, commonlength); - text1 = text1.substring(commonlength); - text2 = text2.substring(commonlength); + var commonlength = this.diff_commonPrefix(text1, text2) + var commonprefix = text1.substring(0, commonlength) + text1 = text1.substring(commonlength) + text2 = text2.substring(commonlength) // Trim off common suffix (speedup). - commonlength = this.diff_commonSuffix(text1, text2); - var commonsuffix = text1.substring(text1.length - commonlength); - text1 = text1.substring(0, text1.length - commonlength); - text2 = text2.substring(0, text2.length - commonlength); + commonlength = this.diff_commonSuffix(text1, text2) + var commonsuffix = text1.substring(text1.length - commonlength) + text1 = text1.substring(0, text1.length - commonlength) + text2 = text2.substring(0, text2.length - commonlength) // Compute the diff on the middle block. - var diffs = this.diff_compute_(text1, text2, checklines, deadline); + var diffs = this.diff_compute_(text1, text2, checklines, deadline) // Restore the prefix and suffix. if (commonprefix) { - diffs.unshift([DIFF_EQUAL, commonprefix]); + diffs.unshift([DIFF_EQUAL, commonprefix]) } if (commonsuffix) { - diffs.push([DIFF_EQUAL, commonsuffix]); + diffs.push([DIFF_EQUAL, commonsuffix]) } - this.diff_cleanupMerge(diffs); - return diffs; -}; - + this.diff_cleanupMerge(diffs) + return diffs +} /** * Find the differences between two texts. Assumes that the texts do not @@ -153,64 +152,72 @@ diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, - deadline) { - var diffs; +diff_match_patch.prototype.diff_compute_ = function ( + text1, + text2, + checklines, + deadline +) { + var diffs if (!text1) { // Just add some text (speedup). - return [[DIFF_INSERT, text2]]; + return [[DIFF_INSERT, text2]] } if (!text2) { // Just delete some text (speedup). - return [[DIFF_DELETE, text1]]; + return [[DIFF_DELETE, text1]] } - var longtext = text1.length > text2.length ? text1 : text2; - var shorttext = text1.length > text2.length ? text2 : text1; - var i = longtext.indexOf(shorttext); + var longtext = text1.length > text2.length ? text1 : text2 + var shorttext = text1.length > text2.length ? text2 : text1 + var i = longtext.indexOf(shorttext) if (i != -1) { // Shorter text is inside the longer text (speedup). - diffs = [[DIFF_INSERT, longtext.substring(0, i)], - [DIFF_EQUAL, shorttext], - [DIFF_INSERT, longtext.substring(i + shorttext.length)]]; + diffs = [ + [DIFF_INSERT, longtext.substring(0, i)], + [DIFF_EQUAL, shorttext], + [DIFF_INSERT, longtext.substring(i + shorttext.length)] + ] // Swap insertions for deletions if diff is reversed. if (text1.length > text2.length) { - diffs[0][0] = diffs[2][0] = DIFF_DELETE; + diffs[0][0] = diffs[2][0] = DIFF_DELETE } - return diffs; + return diffs } if (shorttext.length == 1) { // Single character string. // After the previous speedup, the character can't be an equality. - return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; + return [ + [DIFF_DELETE, text1], + [DIFF_INSERT, text2] + ] } // Check to see if the problem can be split in two. - var hm = this.diff_halfMatch_(text1, text2); + var hm = this.diff_halfMatch_(text1, text2) if (hm) { // A half-match was found, sort out the return data. - var text1_a = hm[0]; - var text1_b = hm[1]; - var text2_a = hm[2]; - var text2_b = hm[3]; - var mid_common = hm[4]; + var text1_a = hm[0] + var text1_b = hm[1] + var text2_a = hm[2] + var text2_b = hm[3] + var mid_common = hm[4] // Send both pairs off for separate processing. - var diffs_a = this.diff_main(text1_a, text2_a, checklines, deadline); - var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline); + var diffs_a = this.diff_main(text1_a, text2_a, checklines, deadline) + var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline) // Merge the results. - return diffs_a.concat([[DIFF_EQUAL, mid_common]], diffs_b); + return diffs_a.concat([[DIFF_EQUAL, mid_common]], diffs_b) } if (checklines && text1.length > 100 && text2.length > 100) { - return this.diff_lineMode_(text1, text2, deadline); + return this.diff_lineMode_(text1, text2, deadline) } - return this.diff_bisect_(text1, text2, deadline); -}; - + return this.diff_bisect_(text1, text2, deadline) +} /** * Do a quick line-level diff on both strings, then rediff the parts for @@ -222,64 +229,65 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { +diff_match_patch.prototype.diff_lineMode_ = function (text1, text2, deadline) { // Scan the text on a line-by-line basis first. - var a = this.diff_linesToChars_(text1, text2); - text1 = a.chars1; - text2 = a.chars2; - var linearray = a.lineArray; + var a = this.diff_linesToChars_(text1, text2) + text1 = a.chars1 + text2 = a.chars2 + var linearray = a.lineArray - var diffs = this.diff_main(text1, text2, false, deadline); + var diffs = this.diff_main(text1, text2, false, deadline) // Convert the diff back to original text. - this.diff_charsToLines_(diffs, linearray); + this.diff_charsToLines_(diffs, linearray) // Eliminate freak matches (e.g. blank lines) - this.diff_cleanupSemantic(diffs); + this.diff_cleanupSemantic(diffs) // Rediff any replacement blocks, this time character-by-character. // Add a dummy entry at the end. - diffs.push([DIFF_EQUAL, '']); - var pointer = 0; - var count_delete = 0; - var count_insert = 0; - var text_delete = ''; - var text_insert = ''; + diffs.push([DIFF_EQUAL, '']) + var pointer = 0 + var count_delete = 0 + var count_insert = 0 + var text_delete = '' + var text_insert = '' while (pointer < diffs.length) { switch (diffs[pointer][0]) { case DIFF_INSERT: - count_insert++; - text_insert += diffs[pointer][1]; - break; + count_insert++ + text_insert += diffs[pointer][1] + break case DIFF_DELETE: - count_delete++; - text_delete += diffs[pointer][1]; - break; + count_delete++ + text_delete += diffs[pointer][1] + break case DIFF_EQUAL: // Upon reaching an equality, check for prior redundancies. if (count_delete >= 1 && count_insert >= 1) { // Delete the offending records and add the merged ones. - diffs.splice(pointer - count_delete - count_insert, - count_delete + count_insert); - pointer = pointer - count_delete - count_insert; - var a = this.diff_main(text_delete, text_insert, false, deadline); + diffs.splice( + pointer - count_delete - count_insert, + count_delete + count_insert + ) + pointer = pointer - count_delete - count_insert + var a = this.diff_main(text_delete, text_insert, false, deadline) for (var j = a.length - 1; j >= 0; j--) { - diffs.splice(pointer, 0, a[j]); + diffs.splice(pointer, 0, a[j]) } - pointer = pointer + a.length; + pointer = pointer + a.length } - count_insert = 0; - count_delete = 0; - text_delete = ''; - text_insert = ''; - break; + count_insert = 0 + count_delete = 0 + text_delete = '' + text_insert = '' + break } - pointer++; + pointer++ } - diffs.pop(); // Remove the dummy entry at the end. - - return diffs; -}; + diffs.pop() // Remove the dummy entry at the end. + return diffs +} /** * Find the 'middle snake' of a diff, split the problem in two @@ -291,69 +299,72 @@ diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { +diff_match_patch.prototype.diff_bisect_ = function (text1, text2, deadline) { // Cache the text lengths to prevent multiple calls. - var text1_length = text1.length; - var text2_length = text2.length; - var max_d = Math.ceil((text1_length + text2_length) / 2); - var v_offset = max_d; - var v_length = 2 * max_d; - var v1 = new Array(v_length); - var v2 = new Array(v_length); + var text1_length = text1.length + var text2_length = text2.length + var max_d = Math.ceil((text1_length + text2_length) / 2) + var v_offset = max_d + var v_length = 2 * max_d + var v1 = new Array(v_length) + var v2 = new Array(v_length) // Setting all elements to -1 is faster in Chrome & Firefox than mixing // integers and undefined. for (var x = 0; x < v_length; x++) { - v1[x] = -1; - v2[x] = -1; + v1[x] = -1 + v2[x] = -1 } - v1[v_offset + 1] = 0; - v2[v_offset + 1] = 0; - var delta = text1_length - text2_length; + v1[v_offset + 1] = 0 + v2[v_offset + 1] = 0 + var delta = text1_length - text2_length // If the total number of characters is odd, then the front path will collide // with the reverse path. - var front = (delta % 2 != 0); + var front = delta % 2 != 0 // Offsets for start and end of k loop. // Prevents mapping of space beyond the grid. - var k1start = 0; - var k1end = 0; - var k2start = 0; - var k2end = 0; + var k1start = 0 + var k1end = 0 + var k2start = 0 + var k2end = 0 for (var d = 0; d < max_d; d++) { // Bail out if deadline is reached. - if ((new Date()).getTime() > deadline) { - break; + if (new Date().getTime() > deadline) { + break } // Walk the front path one step. for (var k1 = -d + k1start; k1 <= d - k1end; k1 += 2) { - var k1_offset = v_offset + k1; - var x1; + var k1_offset = v_offset + k1 + var x1 if (k1 == -d || (k1 != d && v1[k1_offset - 1] < v1[k1_offset + 1])) { - x1 = v1[k1_offset + 1]; + x1 = v1[k1_offset + 1] } else { - x1 = v1[k1_offset - 1] + 1; + x1 = v1[k1_offset - 1] + 1 } - var y1 = x1 - k1; - while (x1 < text1_length && y1 < text2_length && - text1.charAt(x1) == text2.charAt(y1)) { - x1++; - y1++; + var y1 = x1 - k1 + while ( + x1 < text1_length && + y1 < text2_length && + text1.charAt(x1) == text2.charAt(y1) + ) { + x1++ + y1++ } - v1[k1_offset] = x1; + v1[k1_offset] = x1 if (x1 > text1_length) { // Ran off the right of the graph. - k1end += 2; + k1end += 2 } else if (y1 > text2_length) { // Ran off the bottom of the graph. - k1start += 2; + k1start += 2 } else if (front) { - var k2_offset = v_offset + delta - k1; + var k2_offset = v_offset + delta - k1 if (k2_offset >= 0 && k2_offset < v_length && v2[k2_offset] != -1) { // Mirror x2 onto top-left coordinate system. - var x2 = text1_length - v2[k2_offset]; + var x2 = text1_length - v2[k2_offset] if (x1 >= x2) { // Overlap detected. - return this.diff_bisectSplit_(text1, text2, x1, y1, deadline); + return this.diff_bisectSplit_(text1, text2, x1, y1, deadline) } } } @@ -361,37 +372,40 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { // Walk the reverse path one step. for (var k2 = -d + k2start; k2 <= d - k2end; k2 += 2) { - var k2_offset = v_offset + k2; - var x2; + var k2_offset = v_offset + k2 + var x2 if (k2 == -d || (k2 != d && v2[k2_offset - 1] < v2[k2_offset + 1])) { - x2 = v2[k2_offset + 1]; + x2 = v2[k2_offset + 1] } else { - x2 = v2[k2_offset - 1] + 1; + x2 = v2[k2_offset - 1] + 1 } - var y2 = x2 - k2; - while (x2 < text1_length && y2 < text2_length && - text1.charAt(text1_length - x2 - 1) == - text2.charAt(text2_length - y2 - 1)) { - x2++; - y2++; + var y2 = x2 - k2 + while ( + x2 < text1_length && + y2 < text2_length && + text1.charAt(text1_length - x2 - 1) == + text2.charAt(text2_length - y2 - 1) + ) { + x2++ + y2++ } - v2[k2_offset] = x2; + v2[k2_offset] = x2 if (x2 > text1_length) { // Ran off the left of the graph. - k2end += 2; + k2end += 2 } else if (y2 > text2_length) { // Ran off the top of the graph. - k2start += 2; + k2start += 2 } else if (!front) { - var k1_offset = v_offset + delta - k2; + var k1_offset = v_offset + delta - k2 if (k1_offset >= 0 && k1_offset < v_length && v1[k1_offset] != -1) { - var x1 = v1[k1_offset]; - var y1 = v_offset + x1 - k1_offset; + var x1 = v1[k1_offset] + var y1 = v_offset + x1 - k1_offset // Mirror x2 onto top-left coordinate system. - x2 = text1_length - x2; + x2 = text1_length - x2 if (x1 >= x2) { // Overlap detected. - return this.diff_bisectSplit_(text1, text2, x1, y1, deadline); + return this.diff_bisectSplit_(text1, text2, x1, y1, deadline) } } } @@ -399,9 +413,11 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { } // Diff took too long and hit the deadline or // number of diffs equals number of characters, no commonality at all. - return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; -}; - + return [ + [DIFF_DELETE, text1], + [DIFF_INSERT, text2] + ] +} /** * Given the location of the 'middle snake', split the diff in two parts @@ -414,20 +430,24 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y, - deadline) { - var text1a = text1.substring(0, x); - var text2a = text2.substring(0, y); - var text1b = text1.substring(x); - var text2b = text2.substring(y); +diff_match_patch.prototype.diff_bisectSplit_ = function ( + text1, + text2, + x, + y, + deadline +) { + var text1a = text1.substring(0, x) + var text2a = text2.substring(0, y) + var text1b = text1.substring(x) + var text2b = text2.substring(y) // Compute both diffs serially. - var diffs = this.diff_main(text1a, text2a, false, deadline); - var diffsb = this.diff_main(text1b, text2b, false, deadline); - - return diffs.concat(diffsb); -}; + var diffs = this.diff_main(text1a, text2a, false, deadline) + var diffsb = this.diff_main(text1b, text2b, false, deadline) + return diffs.concat(diffsb) +} /** * Split two texts into an array of strings. Reduce the texts to a string of @@ -440,13 +460,13 @@ diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y, * The zeroth element of the array of unique strings is intentionally blank. * @private */ -diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { - var lineArray = []; // e.g. lineArray[4] == 'Hello\n' - var lineHash = {}; // e.g. lineHash['Hello\n'] == 4 +diff_match_patch.prototype.diff_linesToChars_ = function (text1, text2) { + var lineArray = [] // e.g. lineArray[4] == 'Hello\n' + var lineHash = {} // e.g. lineHash['Hello\n'] == 4 // '\x00' is a valid character, but various debuggers don't like it. // So we'll insert a junk entry to avoid generating a null character. - lineArray[0] = ''; + lineArray[0] = '' /** * Split a text into an array of strings. Reduce the texts to a string of @@ -457,39 +477,41 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { * @private */ function diff_linesToCharsMunge_(text) { - var chars = ''; + var chars = '' // Walk the text, pulling out a substring for each line. // text.split('\n') would would temporarily double our memory footprint. // Modifying text would create many large strings to garbage collect. - var lineStart = 0; - var lineEnd = -1; + var lineStart = 0 + var lineEnd = -1 // Keeping our own length variable is faster than looking it up. - var lineArrayLength = lineArray.length; + var lineArrayLength = lineArray.length while (lineEnd < text.length - 1) { - lineEnd = text.indexOf('\n', lineStart); + lineEnd = text.indexOf('\n', lineStart) if (lineEnd == -1) { - lineEnd = text.length - 1; + lineEnd = text.length - 1 } - var line = text.substring(lineStart, lineEnd + 1); - lineStart = lineEnd + 1; + var line = text.substring(lineStart, lineEnd + 1) + lineStart = lineEnd + 1 - if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : - (lineHash[line] !== undefined)) { - chars += String.fromCharCode(lineHash[line]); + if ( + lineHash.hasOwnProperty + ? lineHash.hasOwnProperty(line) + : lineHash[line] !== undefined + ) { + chars += String.fromCharCode(lineHash[line]) } else { - chars += String.fromCharCode(lineArrayLength); - lineHash[line] = lineArrayLength; - lineArray[lineArrayLength++] = line; + chars += String.fromCharCode(lineArrayLength) + lineHash[line] = lineArrayLength + lineArray[lineArrayLength++] = line } } - return chars; + return chars } - var chars1 = diff_linesToCharsMunge_(text1); - var chars2 = diff_linesToCharsMunge_(text2); - return {chars1: chars1, chars2: chars2, lineArray: lineArray}; -}; - + var chars1 = diff_linesToCharsMunge_(text1) + var chars2 = diff_linesToCharsMunge_(text2) + return { chars1: chars1, chars2: chars2, lineArray: lineArray } +} /** * Rehydrate the text in a diff from a string of line hashes to real lines of @@ -498,17 +520,16 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { * @param {!Array.} lineArray Array of unique strings. * @private */ -diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) { +diff_match_patch.prototype.diff_charsToLines_ = function (diffs, lineArray) { for (var x = 0; x < diffs.length; x++) { - var chars = diffs[x][1]; - var text = []; + var chars = diffs[x][1] + var text = [] for (var y = 0; y < chars.length; y++) { - text[y] = lineArray[chars.charCodeAt(y)]; + text[y] = lineArray[chars.charCodeAt(y)] } - diffs[x][1] = text.join(''); + diffs[x][1] = text.join('') } -}; - +} /** * Determine the common prefix of two strings. @@ -517,30 +538,31 @@ diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) { * @return {number} The number of characters common to the start of each * string. */ -diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) { +diff_match_patch.prototype.diff_commonPrefix = function (text1, text2) { // Quick check for common null cases. if (!text1 || !text2 || text1.charAt(0) != text2.charAt(0)) { - return 0; + return 0 } // Binary search. // Performance analysis: http://neil.fraser.name/news/2007/10/09/ - var pointermin = 0; - var pointermax = Math.min(text1.length, text2.length); - var pointermid = pointermax; - var pointerstart = 0; + var pointermin = 0 + var pointermax = Math.min(text1.length, text2.length) + var pointermid = pointermax + var pointerstart = 0 while (pointermin < pointermid) { - if (text1.substring(pointerstart, pointermid) == - text2.substring(pointerstart, pointermid)) { - pointermin = pointermid; - pointerstart = pointermin; + if ( + text1.substring(pointerstart, pointermid) == + text2.substring(pointerstart, pointermid) + ) { + pointermin = pointermid + pointerstart = pointermin } else { - pointermax = pointermid; + pointermax = pointermid } - pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin); + pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin) } - return pointermid; -}; - + return pointermid +} /** * Determine the common suffix of two strings. @@ -548,31 +570,35 @@ diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) { * @param {string} text2 Second string. * @return {number} The number of characters common to the end of each string. */ -diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) { +diff_match_patch.prototype.diff_commonSuffix = function (text1, text2) { // Quick check for common null cases. - if (!text1 || !text2 || - text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) { - return 0; + if ( + !text1 || + !text2 || + text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1) + ) { + return 0 } // Binary search. // Performance analysis: http://neil.fraser.name/news/2007/10/09/ - var pointermin = 0; - var pointermax = Math.min(text1.length, text2.length); - var pointermid = pointermax; - var pointerend = 0; + var pointermin = 0 + var pointermax = Math.min(text1.length, text2.length) + var pointermid = pointermax + var pointerend = 0 while (pointermin < pointermid) { - if (text1.substring(text1.length - pointermid, text1.length - pointerend) == - text2.substring(text2.length - pointermid, text2.length - pointerend)) { - pointermin = pointermid; - pointerend = pointermin; + if ( + text1.substring(text1.length - pointermid, text1.length - pointerend) == + text2.substring(text2.length - pointermid, text2.length - pointerend) + ) { + pointermin = pointermid + pointerend = pointermin } else { - pointermax = pointermid; + pointermax = pointermid } - pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin); + pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin) } - return pointermid; -}; - + return pointermid +} /** * Determine if the suffix of one string is the prefix of another. @@ -582,46 +608,47 @@ diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) { * string and the start of the second string. * @private */ -diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) { +diff_match_patch.prototype.diff_commonOverlap_ = function (text1, text2) { // Cache the text lengths to prevent multiple calls. - var text1_length = text1.length; - var text2_length = text2.length; + var text1_length = text1.length + var text2_length = text2.length // Eliminate the null case. if (text1_length == 0 || text2_length == 0) { - return 0; + return 0 } // Truncate the longer string. if (text1_length > text2_length) { - text1 = text1.substring(text1_length - text2_length); + text1 = text1.substring(text1_length - text2_length) } else if (text1_length < text2_length) { - text2 = text2.substring(0, text1_length); + text2 = text2.substring(0, text1_length) } - var text_length = Math.min(text1_length, text2_length); + var text_length = Math.min(text1_length, text2_length) // Quick check for the worst case. if (text1 == text2) { - return text_length; + return text_length } // Start by looking for a single character match // and increase length until no match is found. // Performance analysis: http://neil.fraser.name/news/2010/11/04/ - var best = 0; - var length = 1; + var best = 0 + var length = 1 while (true) { - var pattern = text1.substring(text_length - length); - var found = text2.indexOf(pattern); + var pattern = text1.substring(text_length - length) + var found = text2.indexOf(pattern) if (found == -1) { - return best; + return best } - length += found; - if (found == 0 || text1.substring(text_length - length) == - text2.substring(0, length)) { - best = length; - length++; + length += found + if ( + found == 0 || + text1.substring(text_length - length) == text2.substring(0, length) + ) { + best = length + length++ } } -}; - +} /** * Do the two texts share a substring which is at least half the length of the @@ -634,17 +661,17 @@ diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) { * text2 and the common middle. Or null if there was no match. * @private */ -diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { +diff_match_patch.prototype.diff_halfMatch_ = function (text1, text2) { if (this.Diff_Timeout <= 0) { // Don't risk returning a non-optimal diff if we have unlimited time. - return null; + return null } - var longtext = text1.length > text2.length ? text1 : text2; - var shorttext = text1.length > text2.length ? text2 : text1; + var longtext = text1.length > text2.length ? text1 : text2 + var shorttext = text1.length > text2.length ? text2 : text1 if (longtext.length < 4 || shorttext.length * 2 < longtext.length) { - return null; // Pointless. + return null // Pointless. } - var dmp = this; // 'this' becomes 'window' in a closure. + var dmp = this // 'this' becomes 'window' in a closure. /** * Does a substring of shorttext exist within longtext such that the substring @@ -660,132 +687,153 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { */ function diff_halfMatchI_(longtext, shorttext, i) { // Start with a 1/4 length substring at position i as a seed. - var seed = longtext.substring(i, i + Math.floor(longtext.length / 4)); - var j = -1; - var best_common = ''; - var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b; + var seed = longtext.substring(i, i + Math.floor(longtext.length / 4)) + var j = -1 + var best_common = '' + var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b while ((j = shorttext.indexOf(seed, j + 1)) != -1) { - var prefixLength = dmp.diff_commonPrefix(longtext.substring(i), - shorttext.substring(j)); - var suffixLength = dmp.diff_commonSuffix(longtext.substring(0, i), - shorttext.substring(0, j)); + var prefixLength = dmp.diff_commonPrefix( + longtext.substring(i), + shorttext.substring(j) + ) + var suffixLength = dmp.diff_commonSuffix( + longtext.substring(0, i), + shorttext.substring(0, j) + ) if (best_common.length < suffixLength + prefixLength) { - best_common = shorttext.substring(j - suffixLength, j) + - shorttext.substring(j, j + prefixLength); - best_longtext_a = longtext.substring(0, i - suffixLength); - best_longtext_b = longtext.substring(i + prefixLength); - best_shorttext_a = shorttext.substring(0, j - suffixLength); - best_shorttext_b = shorttext.substring(j + prefixLength); + best_common = + shorttext.substring(j - suffixLength, j) + + shorttext.substring(j, j + prefixLength) + best_longtext_a = longtext.substring(0, i - suffixLength) + best_longtext_b = longtext.substring(i + prefixLength) + best_shorttext_a = shorttext.substring(0, j - suffixLength) + best_shorttext_b = shorttext.substring(j + prefixLength) } } if (best_common.length * 2 >= longtext.length) { - return [best_longtext_a, best_longtext_b, - best_shorttext_a, best_shorttext_b, best_common]; + return [ + best_longtext_a, + best_longtext_b, + best_shorttext_a, + best_shorttext_b, + best_common + ] } else { - return null; + return null } } // First check if the second quarter is the seed for a half-match. - var hm1 = diff_halfMatchI_(longtext, shorttext, - Math.ceil(longtext.length / 4)); + var hm1 = diff_halfMatchI_( + longtext, + shorttext, + Math.ceil(longtext.length / 4) + ) // Check again based on the third quarter. - var hm2 = diff_halfMatchI_(longtext, shorttext, - Math.ceil(longtext.length / 2)); - var hm; + var hm2 = diff_halfMatchI_( + longtext, + shorttext, + Math.ceil(longtext.length / 2) + ) + var hm if (!hm1 && !hm2) { - return null; + return null } else if (!hm2) { - hm = hm1; + hm = hm1 } else if (!hm1) { - hm = hm2; + hm = hm2 } else { // Both matched. Select the longest. - hm = hm1[4].length > hm2[4].length ? hm1 : hm2; + hm = hm1[4].length > hm2[4].length ? hm1 : hm2 } // A half-match was found, sort out the return data. - var text1_a, text1_b, text2_a, text2_b; + var text1_a, text1_b, text2_a, text2_b if (text1.length > text2.length) { - text1_a = hm[0]; - text1_b = hm[1]; - text2_a = hm[2]; - text2_b = hm[3]; + text1_a = hm[0] + text1_b = hm[1] + text2_a = hm[2] + text2_b = hm[3] } else { - text2_a = hm[0]; - text2_b = hm[1]; - text1_a = hm[2]; - text1_b = hm[3]; + text2_a = hm[0] + text2_b = hm[1] + text1_a = hm[2] + text1_b = hm[3] } - var mid_common = hm[4]; - return [text1_a, text1_b, text2_a, text2_b, mid_common]; -}; - + var mid_common = hm[4] + return [text1_a, text1_b, text2_a, text2_b, mid_common] +} /** * Reduce the number of edits by eliminating semantically trivial equalities. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { - var changes = false; - var equalities = []; // Stack of indices where equalities are found. - var equalitiesLength = 0; // Keeping our own length var is faster in JS. +diff_match_patch.prototype.diff_cleanupSemantic = function (diffs) { + var changes = false + var equalities = [] // Stack of indices where equalities are found. + var equalitiesLength = 0 // Keeping our own length var is faster in JS. /** @type {?string} */ - var lastequality = null; + var lastequality = null // Always equal to diffs[equalities[equalitiesLength - 1]][1] - var pointer = 0; // Index of current position. + var pointer = 0 // Index of current position. // Number of characters that changed prior to the equality. - var length_insertions1 = 0; - var length_deletions1 = 0; + var length_insertions1 = 0 + var length_deletions1 = 0 // Number of characters that changed after the equality. - var length_insertions2 = 0; - var length_deletions2 = 0; + var length_insertions2 = 0 + var length_deletions2 = 0 while (pointer < diffs.length) { - if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found. - equalities[equalitiesLength++] = pointer; - length_insertions1 = length_insertions2; - length_deletions1 = length_deletions2; - length_insertions2 = 0; - length_deletions2 = 0; - lastequality = diffs[pointer][1]; - } else { // An insertion or deletion. + if (diffs[pointer][0] == DIFF_EQUAL) { + // Equality found. + equalities[equalitiesLength++] = pointer + length_insertions1 = length_insertions2 + length_deletions1 = length_deletions2 + length_insertions2 = 0 + length_deletions2 = 0 + lastequality = diffs[pointer][1] + } else { + // An insertion or deletion. if (diffs[pointer][0] == DIFF_INSERT) { - length_insertions2 += diffs[pointer][1].length; + length_insertions2 += diffs[pointer][1].length } else { - length_deletions2 += diffs[pointer][1].length; + length_deletions2 += diffs[pointer][1].length } // Eliminate an equality that is smaller or equal to the edits on both // sides of it. - if (lastequality && (lastequality.length <= - Math.max(length_insertions1, length_deletions1)) && - (lastequality.length <= Math.max(length_insertions2, - length_deletions2))) { + if ( + lastequality && + lastequality.length <= + Math.max(length_insertions1, length_deletions1) && + lastequality.length <= Math.max(length_insertions2, length_deletions2) + ) { // Duplicate record. - diffs.splice(equalities[equalitiesLength - 1], 0, - [DIFF_DELETE, lastequality]); + diffs.splice(equalities[equalitiesLength - 1], 0, [ + DIFF_DELETE, + lastequality + ]) // Change second copy to insert. - diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; + diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT // Throw away the equality we just deleted. - equalitiesLength--; + equalitiesLength-- // Throw away the previous equality (it needs to be reevaluated). - equalitiesLength--; - pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1; - length_insertions1 = 0; // Reset the counters. - length_deletions1 = 0; - length_insertions2 = 0; - length_deletions2 = 0; - lastequality = null; - changes = true; + equalitiesLength-- + pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1 + length_insertions1 = 0 // Reset the counters. + length_deletions1 = 0 + length_insertions2 = 0 + length_deletions2 = 0 + lastequality = null + changes = true } } - pointer++; + pointer++ } // Normalize the diff. if (changes) { - this.diff_cleanupMerge(diffs); + this.diff_cleanupMerge(diffs) } - this.diff_cleanupSemanticLossless(diffs); + this.diff_cleanupSemanticLossless(diffs) // Find any overlaps between deletions and insertions. // e.g: abcxxxxxxdef @@ -793,47 +841,59 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { // e.g: xxxabcdefxxx // -> defxxxabc // Only extract an overlap if it is as big as the edit ahead or behind it. - pointer = 1; + pointer = 1 while (pointer < diffs.length) { - if (diffs[pointer - 1][0] == DIFF_DELETE && - diffs[pointer][0] == DIFF_INSERT) { - var deletion = diffs[pointer - 1][1]; - var insertion = diffs[pointer][1]; - var overlap_length1 = this.diff_commonOverlap_(deletion, insertion); - var overlap_length2 = this.diff_commonOverlap_(insertion, deletion); + if ( + diffs[pointer - 1][0] == DIFF_DELETE && + diffs[pointer][0] == DIFF_INSERT + ) { + var deletion = diffs[pointer - 1][1] + var insertion = diffs[pointer][1] + var overlap_length1 = this.diff_commonOverlap_(deletion, insertion) + var overlap_length2 = this.diff_commonOverlap_(insertion, deletion) if (overlap_length1 >= overlap_length2) { - if (overlap_length1 >= deletion.length / 2 || - overlap_length1 >= insertion.length / 2) { + if ( + overlap_length1 >= deletion.length / 2 || + overlap_length1 >= insertion.length / 2 + ) { // Overlap found. Insert an equality and trim the surrounding edits. - diffs.splice(pointer, 0, - [DIFF_EQUAL, insertion.substring(0, overlap_length1)]); - diffs[pointer - 1][1] = - deletion.substring(0, deletion.length - overlap_length1); - diffs[pointer + 1][1] = insertion.substring(overlap_length1); - pointer++; + diffs.splice(pointer, 0, [ + DIFF_EQUAL, + insertion.substring(0, overlap_length1) + ]) + diffs[pointer - 1][1] = deletion.substring( + 0, + deletion.length - overlap_length1 + ) + diffs[pointer + 1][1] = insertion.substring(overlap_length1) + pointer++ } } else { - if (overlap_length2 >= deletion.length / 2 || - overlap_length2 >= insertion.length / 2) { + if ( + overlap_length2 >= deletion.length / 2 || + overlap_length2 >= insertion.length / 2 + ) { // Reverse overlap found. // Insert an equality and swap and trim the surrounding edits. - diffs.splice(pointer, 0, - [DIFF_EQUAL, deletion.substring(0, overlap_length2)]); - diffs[pointer - 1][0] = DIFF_INSERT; - diffs[pointer - 1][1] = - insertion.substring(0, insertion.length - overlap_length2); - diffs[pointer + 1][0] = DIFF_DELETE; - diffs[pointer + 1][1] = - deletion.substring(overlap_length2); - pointer++; + diffs.splice(pointer, 0, [ + DIFF_EQUAL, + deletion.substring(0, overlap_length2) + ]) + diffs[pointer - 1][0] = DIFF_INSERT + diffs[pointer - 1][1] = insertion.substring( + 0, + insertion.length - overlap_length2 + ) + diffs[pointer + 1][0] = DIFF_DELETE + diffs[pointer + 1][1] = deletion.substring(overlap_length2) + pointer++ } } - pointer++; + pointer++ } - pointer++; + pointer++ } -}; - +} /** * Look for single edits surrounded on both sides by equalities @@ -841,7 +901,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { * e.g: The cat came. -> The cat came. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { +diff_match_patch.prototype.diff_cleanupSemanticLossless = function (diffs) { /** * Given two strings, compute a score representing whether the internal * boundary falls on logical boundaries. @@ -855,7 +915,7 @@ diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { function diff_cleanupSemanticScore_(one, two) { if (!one || !two) { // Edges are the best. - return 6; + return 6 } // Each port of this function behaves slightly differently due to @@ -863,150 +923,158 @@ diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { // 'whitespace'. Since this function's purpose is largely cosmetic, // the choice has been made to use each language's native features // rather than force total conformity. - var char1 = one.charAt(one.length - 1); - var char2 = two.charAt(0); - var nonAlphaNumeric1 = char1.match(diff_match_patch.nonAlphaNumericRegex_); - var nonAlphaNumeric2 = char2.match(diff_match_patch.nonAlphaNumericRegex_); - var whitespace1 = nonAlphaNumeric1 && - char1.match(diff_match_patch.whitespaceRegex_); - var whitespace2 = nonAlphaNumeric2 && - char2.match(diff_match_patch.whitespaceRegex_); - var lineBreak1 = whitespace1 && - char1.match(diff_match_patch.linebreakRegex_); - var lineBreak2 = whitespace2 && - char2.match(diff_match_patch.linebreakRegex_); - var blankLine1 = lineBreak1 && - one.match(diff_match_patch.blanklineEndRegex_); - var blankLine2 = lineBreak2 && - two.match(diff_match_patch.blanklineStartRegex_); + var char1 = one.charAt(one.length - 1) + var char2 = two.charAt(0) + var nonAlphaNumeric1 = char1.match(diff_match_patch.nonAlphaNumericRegex_) + var nonAlphaNumeric2 = char2.match(diff_match_patch.nonAlphaNumericRegex_) + var whitespace1 = + nonAlphaNumeric1 && char1.match(diff_match_patch.whitespaceRegex_) + var whitespace2 = + nonAlphaNumeric2 && char2.match(diff_match_patch.whitespaceRegex_) + var lineBreak1 = + whitespace1 && char1.match(diff_match_patch.linebreakRegex_) + var lineBreak2 = + whitespace2 && char2.match(diff_match_patch.linebreakRegex_) + var blankLine1 = + lineBreak1 && one.match(diff_match_patch.blanklineEndRegex_) + var blankLine2 = + lineBreak2 && two.match(diff_match_patch.blanklineStartRegex_) if (blankLine1 || blankLine2) { // Five points for blank lines. - return 5; + return 5 } else if (lineBreak1 || lineBreak2) { // Four points for line breaks. - return 4; + return 4 } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) { // Three points for end of sentences. - return 3; + return 3 } else if (whitespace1 || whitespace2) { // Two points for whitespace. - return 2; + return 2 } else if (nonAlphaNumeric1 || nonAlphaNumeric2) { // One point for non-alphanumeric. - return 1; + return 1 } - return 0; + return 0 } - var pointer = 1; + var pointer = 1 // Intentionally ignore the first and last element (don't need checking). while (pointer < diffs.length - 1) { - if (diffs[pointer - 1][0] == DIFF_EQUAL && - diffs[pointer + 1][0] == DIFF_EQUAL) { + if ( + diffs[pointer - 1][0] == DIFF_EQUAL && + diffs[pointer + 1][0] == DIFF_EQUAL + ) { // This is a single edit surrounded by equalities. - var equality1 = diffs[pointer - 1][1]; - var edit = diffs[pointer][1]; - var equality2 = diffs[pointer + 1][1]; + var equality1 = diffs[pointer - 1][1] + var edit = diffs[pointer][1] + var equality2 = diffs[pointer + 1][1] // First, shift the edit as far left as possible. - var commonOffset = this.diff_commonSuffix(equality1, edit); + var commonOffset = this.diff_commonSuffix(equality1, edit) if (commonOffset) { - var commonString = edit.substring(edit.length - commonOffset); - equality1 = equality1.substring(0, equality1.length - commonOffset); - edit = commonString + edit.substring(0, edit.length - commonOffset); - equality2 = commonString + equality2; + var commonString = edit.substring(edit.length - commonOffset) + equality1 = equality1.substring(0, equality1.length - commonOffset) + edit = commonString + edit.substring(0, edit.length - commonOffset) + equality2 = commonString + equality2 } // Second, step character by character right, looking for the best fit. - var bestEquality1 = equality1; - var bestEdit = edit; - var bestEquality2 = equality2; - var bestScore = diff_cleanupSemanticScore_(equality1, edit) + - diff_cleanupSemanticScore_(edit, equality2); + var bestEquality1 = equality1 + var bestEdit = edit + var bestEquality2 = equality2 + var bestScore = + diff_cleanupSemanticScore_(equality1, edit) + + diff_cleanupSemanticScore_(edit, equality2) while (edit.charAt(0) === equality2.charAt(0)) { - equality1 += edit.charAt(0); - edit = edit.substring(1) + equality2.charAt(0); - equality2 = equality2.substring(1); - var score = diff_cleanupSemanticScore_(equality1, edit) + - diff_cleanupSemanticScore_(edit, equality2); + equality1 += edit.charAt(0) + edit = edit.substring(1) + equality2.charAt(0) + equality2 = equality2.substring(1) + var score = + diff_cleanupSemanticScore_(equality1, edit) + + diff_cleanupSemanticScore_(edit, equality2) // The >= encourages trailing rather than leading whitespace on edits. if (score >= bestScore) { - bestScore = score; - bestEquality1 = equality1; - bestEdit = edit; - bestEquality2 = equality2; + bestScore = score + bestEquality1 = equality1 + bestEdit = edit + bestEquality2 = equality2 } } if (diffs[pointer - 1][1] != bestEquality1) { // We have an improvement, save it back to the diff. if (bestEquality1) { - diffs[pointer - 1][1] = bestEquality1; + diffs[pointer - 1][1] = bestEquality1 } else { - diffs.splice(pointer - 1, 1); - pointer--; + diffs.splice(pointer - 1, 1) + pointer-- } - diffs[pointer][1] = bestEdit; + diffs[pointer][1] = bestEdit if (bestEquality2) { - diffs[pointer + 1][1] = bestEquality2; + diffs[pointer + 1][1] = bestEquality2 } else { - diffs.splice(pointer + 1, 1); - pointer--; + diffs.splice(pointer + 1, 1) + pointer-- } } } - pointer++; + pointer++ } -}; +} // Define some regex patterns for matching boundaries. -diff_match_patch.nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/; -diff_match_patch.whitespaceRegex_ = /\s/; -diff_match_patch.linebreakRegex_ = /[\r\n]/; -diff_match_patch.blanklineEndRegex_ = /\n\r?\n$/; -diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/; +diff_match_patch.nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/ +diff_match_patch.whitespaceRegex_ = /\s/ +diff_match_patch.linebreakRegex_ = /[\r\n]/ +diff_match_patch.blanklineEndRegex_ = /\n\r?\n$/ +diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/ /** * Reduce the number of edits by eliminating operationally trivial equalities. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { - var changes = false; - var equalities = []; // Stack of indices where equalities are found. - var equalitiesLength = 0; // Keeping our own length var is faster in JS. +diff_match_patch.prototype.diff_cleanupEfficiency = function (diffs) { + var changes = false + var equalities = [] // Stack of indices where equalities are found. + var equalitiesLength = 0 // Keeping our own length var is faster in JS. /** @type {?string} */ - var lastequality = null; + var lastequality = null // Always equal to diffs[equalities[equalitiesLength - 1]][1] - var pointer = 0; // Index of current position. + var pointer = 0 // Index of current position. // Is there an insertion operation before the last equality. - var pre_ins = false; + var pre_ins = false // Is there a deletion operation before the last equality. - var pre_del = false; + var pre_del = false // Is there an insertion operation after the last equality. - var post_ins = false; + var post_ins = false // Is there a deletion operation after the last equality. - var post_del = false; + var post_del = false while (pointer < diffs.length) { - if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found. - if (diffs[pointer][1].length < this.Diff_EditCost && - (post_ins || post_del)) { + if (diffs[pointer][0] == DIFF_EQUAL) { + // Equality found. + if ( + diffs[pointer][1].length < this.Diff_EditCost && + (post_ins || post_del) + ) { // Candidate found. - equalities[equalitiesLength++] = pointer; - pre_ins = post_ins; - pre_del = post_del; - lastequality = diffs[pointer][1]; + equalities[equalitiesLength++] = pointer + pre_ins = post_ins + pre_del = post_del + lastequality = diffs[pointer][1] } else { // Not a candidate, and can never become one. - equalitiesLength = 0; - lastequality = null; + equalitiesLength = 0 + lastequality = null } - post_ins = post_del = false; - } else { // An insertion or deletion. + post_ins = post_del = false + } else { + // An insertion or deletion. if (diffs[pointer][0] == DIFF_DELETE) { - post_del = true; + post_del = true } else { - post_ins = true; + post_ins = true } /* * Five types to be split: @@ -1016,164 +1084,198 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { * AXCD * ABXC */ - if (lastequality && ((pre_ins && pre_del && post_ins && post_del) || - ((lastequality.length < this.Diff_EditCost / 2) && - (pre_ins + pre_del + post_ins + post_del) == 3))) { + if ( + lastequality && + ((pre_ins && pre_del && post_ins && post_del) || + (lastequality.length < this.Diff_EditCost / 2 && + pre_ins + pre_del + post_ins + post_del == 3)) + ) { // Duplicate record. - diffs.splice(equalities[equalitiesLength - 1], 0, - [DIFF_DELETE, lastequality]); + diffs.splice(equalities[equalitiesLength - 1], 0, [ + DIFF_DELETE, + lastequality + ]) // Change second copy to insert. - diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; - equalitiesLength--; // Throw away the equality we just deleted; - lastequality = null; + diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT + equalitiesLength-- // Throw away the equality we just deleted; + lastequality = null if (pre_ins && pre_del) { // No changes made which could affect previous entry, keep going. - post_ins = post_del = true; - equalitiesLength = 0; + post_ins = post_del = true + equalitiesLength = 0 } else { - equalitiesLength--; // Throw away the previous equality. - pointer = equalitiesLength > 0 ? - equalities[equalitiesLength - 1] : -1; - post_ins = post_del = false; + equalitiesLength-- // Throw away the previous equality. + pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1 + post_ins = post_del = false } - changes = true; + changes = true } } - pointer++; + pointer++ } if (changes) { - this.diff_cleanupMerge(diffs); + this.diff_cleanupMerge(diffs) } -}; - +} /** * Reorder and merge like edit sections. Merge equalities. * Any edit section can move as long as it doesn't cross an equality. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { - diffs.push([DIFF_EQUAL, '']); // Add a dummy entry at the end. - var pointer = 0; - var count_delete = 0; - var count_insert = 0; - var text_delete = ''; - var text_insert = ''; - var commonlength; +diff_match_patch.prototype.diff_cleanupMerge = function (diffs) { + diffs.push([DIFF_EQUAL, '']) // Add a dummy entry at the end. + var pointer = 0 + var count_delete = 0 + var count_insert = 0 + var text_delete = '' + var text_insert = '' + var commonlength while (pointer < diffs.length) { switch (diffs[pointer][0]) { case DIFF_INSERT: - count_insert++; - text_insert += diffs[pointer][1]; - pointer++; - break; + count_insert++ + text_insert += diffs[pointer][1] + pointer++ + break case DIFF_DELETE: - count_delete++; - text_delete += diffs[pointer][1]; - pointer++; - break; + count_delete++ + text_delete += diffs[pointer][1] + pointer++ + break case DIFF_EQUAL: // Upon reaching an equality, check for prior redundancies. if (count_delete + count_insert > 1) { if (count_delete !== 0 && count_insert !== 0) { // Factor out any common prefixies. - commonlength = this.diff_commonPrefix(text_insert, text_delete); + commonlength = this.diff_commonPrefix(text_insert, text_delete) if (commonlength !== 0) { - if ((pointer - count_delete - count_insert) > 0 && - diffs[pointer - count_delete - count_insert - 1][0] == - DIFF_EQUAL) { - diffs[pointer - count_delete - count_insert - 1][1] += - text_insert.substring(0, commonlength); + if ( + pointer - count_delete - count_insert > 0 && + diffs[pointer - count_delete - count_insert - 1][0] == + DIFF_EQUAL + ) { + diffs[ + pointer - count_delete - count_insert - 1 + ][1] += text_insert.substring(0, commonlength) } else { - diffs.splice(0, 0, [DIFF_EQUAL, - text_insert.substring(0, commonlength)]); - pointer++; + diffs.splice(0, 0, [ + DIFF_EQUAL, + text_insert.substring(0, commonlength) + ]) + pointer++ } - text_insert = text_insert.substring(commonlength); - text_delete = text_delete.substring(commonlength); + text_insert = text_insert.substring(commonlength) + text_delete = text_delete.substring(commonlength) } // Factor out any common suffixies. - commonlength = this.diff_commonSuffix(text_insert, text_delete); + commonlength = this.diff_commonSuffix(text_insert, text_delete) if (commonlength !== 0) { - diffs[pointer][1] = text_insert.substring(text_insert.length - - commonlength) + diffs[pointer][1]; - text_insert = text_insert.substring(0, text_insert.length - - commonlength); - text_delete = text_delete.substring(0, text_delete.length - - commonlength); + diffs[pointer][1] = + text_insert.substring(text_insert.length - commonlength) + + diffs[pointer][1] + text_insert = text_insert.substring( + 0, + text_insert.length - commonlength + ) + text_delete = text_delete.substring( + 0, + text_delete.length - commonlength + ) } } // Delete the offending records and add the merged ones. if (count_delete === 0) { - diffs.splice(pointer - count_insert, - count_delete + count_insert, [DIFF_INSERT, text_insert]); + diffs.splice(pointer - count_insert, count_delete + count_insert, [ + DIFF_INSERT, + text_insert + ]) } else if (count_insert === 0) { - diffs.splice(pointer - count_delete, - count_delete + count_insert, [DIFF_DELETE, text_delete]); + diffs.splice(pointer - count_delete, count_delete + count_insert, [ + DIFF_DELETE, + text_delete + ]) } else { - diffs.splice(pointer - count_delete - count_insert, - count_delete + count_insert, [DIFF_DELETE, text_delete], - [DIFF_INSERT, text_insert]); + diffs.splice( + pointer - count_delete - count_insert, + count_delete + count_insert, + [DIFF_DELETE, text_delete], + [DIFF_INSERT, text_insert] + ) } - pointer = pointer - count_delete - count_insert + - (count_delete ? 1 : 0) + (count_insert ? 1 : 0) + 1; + pointer = + pointer - + count_delete - + count_insert + + (count_delete ? 1 : 0) + + (count_insert ? 1 : 0) + + 1 } else if (pointer !== 0 && diffs[pointer - 1][0] == DIFF_EQUAL) { // Merge this equality with the previous one. - diffs[pointer - 1][1] += diffs[pointer][1]; - diffs.splice(pointer, 1); + diffs[pointer - 1][1] += diffs[pointer][1] + diffs.splice(pointer, 1) } else { - pointer++; + pointer++ } - count_insert = 0; - count_delete = 0; - text_delete = ''; - text_insert = ''; - break; + count_insert = 0 + count_delete = 0 + text_delete = '' + text_insert = '' + break } } if (diffs[diffs.length - 1][1] === '') { - diffs.pop(); // Remove the dummy entry at the end. + diffs.pop() // Remove the dummy entry at the end. } // Second pass: look for single edits surrounded on both sides by equalities // which can be shifted sideways to eliminate an equality. // e.g: ABAC -> ABAC - var changes = false; - pointer = 1; + var changes = false + pointer = 1 // Intentionally ignore the first and last element (don't need checking). while (pointer < diffs.length - 1) { - if (diffs[pointer - 1][0] == DIFF_EQUAL && - diffs[pointer + 1][0] == DIFF_EQUAL) { + if ( + diffs[pointer - 1][0] == DIFF_EQUAL && + diffs[pointer + 1][0] == DIFF_EQUAL + ) { // This is a single edit surrounded by equalities. - if (diffs[pointer][1].substring(diffs[pointer][1].length - - diffs[pointer - 1][1].length) == diffs[pointer - 1][1]) { + if ( + diffs[pointer][1].substring( + diffs[pointer][1].length - diffs[pointer - 1][1].length + ) == diffs[pointer - 1][1] + ) { // Shift the edit over the previous equality. - diffs[pointer][1] = diffs[pointer - 1][1] + - diffs[pointer][1].substring(0, diffs[pointer][1].length - - diffs[pointer - 1][1].length); - diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1]; - diffs.splice(pointer - 1, 1); - changes = true; - } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) == - diffs[pointer + 1][1]) { - // Shift the edit over the next equality. - diffs[pointer - 1][1] += diffs[pointer + 1][1]; diffs[pointer][1] = - diffs[pointer][1].substring(diffs[pointer + 1][1].length) + - diffs[pointer + 1][1]; - diffs.splice(pointer + 1, 1); - changes = true; + diffs[pointer - 1][1] + + diffs[pointer][1].substring( + 0, + diffs[pointer][1].length - diffs[pointer - 1][1].length + ) + diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1] + diffs.splice(pointer - 1, 1) + changes = true + } else if ( + diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) == + diffs[pointer + 1][1] + ) { + // Shift the edit over the next equality. + diffs[pointer - 1][1] += diffs[pointer + 1][1] + diffs[pointer][1] = + diffs[pointer][1].substring(diffs[pointer + 1][1].length) + + diffs[pointer + 1][1] + diffs.splice(pointer + 1, 1) + changes = true } } - pointer++; + pointer++ } // If shifts were made, the diff needs reordering and another shift sweep. if (changes) { - this.diff_cleanupMerge(diffs); + this.diff_cleanupMerge(diffs) } -}; - +} /** * loc is a location in text1, compute and return the equivalent location in @@ -1183,97 +1285,99 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { * @param {number} loc Location within text1. * @return {number} Location within text2. */ -diff_match_patch.prototype.diff_xIndex = function(diffs, loc) { - var chars1 = 0; - var chars2 = 0; - var last_chars1 = 0; - var last_chars2 = 0; - var x; +diff_match_patch.prototype.diff_xIndex = function (diffs, loc) { + var chars1 = 0 + var chars2 = 0 + var last_chars1 = 0 + var last_chars2 = 0 + var x for (x = 0; x < diffs.length; x++) { - if (diffs[x][0] !== DIFF_INSERT) { // Equality or deletion. - chars1 += diffs[x][1].length; + if (diffs[x][0] !== DIFF_INSERT) { + // Equality or deletion. + chars1 += diffs[x][1].length } - if (diffs[x][0] !== DIFF_DELETE) { // Equality or insertion. - chars2 += diffs[x][1].length; + if (diffs[x][0] !== DIFF_DELETE) { + // Equality or insertion. + chars2 += diffs[x][1].length } - if (chars1 > loc) { // Overshot the location. - break; + if (chars1 > loc) { + // Overshot the location. + break } - last_chars1 = chars1; - last_chars2 = chars2; + last_chars1 = chars1 + last_chars2 = chars2 } // Was the location was deleted? if (diffs.length != x && diffs[x][0] === DIFF_DELETE) { - return last_chars2; + return last_chars2 } // Add the remaining character length. - return last_chars2 + (loc - last_chars1); -}; - + return last_chars2 + (loc - last_chars1) +} /** * Convert a diff array into a pretty HTML report. * @param {!Array.} diffs Array of diff tuples. * @return {string} HTML representation. */ -diff_match_patch.prototype.diff_prettyHtml = function(diffs) { - var html = []; - var pattern_amp = /&/g; - var pattern_lt = //g; - var pattern_para = /\n/g; +diff_match_patch.prototype.diff_prettyHtml = function (diffs) { + var html = [] + var pattern_amp = /&/g + var pattern_lt = //g + var pattern_para = /\n/g for (var x = 0; x < diffs.length; x++) { - var op = diffs[x][0]; // Operation (insert, delete, equal) - var data = diffs[x][1]; // Text of change. - var text = data.replace(pattern_amp, '&').replace(pattern_lt, '<') - .replace(pattern_gt, '>').replace(pattern_para, '¶
'); + var op = diffs[x][0] // Operation (insert, delete, equal) + var data = diffs[x][1] // Text of change. + var text = data + .replace(pattern_amp, '&') + .replace(pattern_lt, '<') + .replace(pattern_gt, '>') + .replace(pattern_para, '¶
') switch (op) { case DIFF_INSERT: - html[x] = '' + text + ''; - break; + html[x] = '' + text + '' + break case DIFF_DELETE: - html[x] = '' + text + ''; - break; + html[x] = '' + text + '' + break case DIFF_EQUAL: - html[x] = '' + text + ''; - break; + html[x] = '' + text + '' + break } } - return html.join(''); -}; - + return html.join('') +} /** * Compute and return the source text (all equalities and deletions). * @param {!Array.} diffs Array of diff tuples. * @return {string} Source text. */ -diff_match_patch.prototype.diff_text1 = function(diffs) { - var text = []; +diff_match_patch.prototype.diff_text1 = function (diffs) { + var text = [] for (var x = 0; x < diffs.length; x++) { if (diffs[x][0] !== DIFF_INSERT) { - text[x] = diffs[x][1]; + text[x] = diffs[x][1] } } - return text.join(''); -}; - + return text.join('') +} /** * Compute and return the destination text (all equalities and insertions). * @param {!Array.} diffs Array of diff tuples. * @return {string} Destination text. */ -diff_match_patch.prototype.diff_text2 = function(diffs) { - var text = []; +diff_match_patch.prototype.diff_text2 = function (diffs) { + var text = [] for (var x = 0; x < diffs.length; x++) { if (diffs[x][0] !== DIFF_DELETE) { - text[x] = diffs[x][1]; + text[x] = diffs[x][1] } } - return text.join(''); -}; - + return text.join('') +} /** * Compute the Levenshtein distance; the number of inserted, deleted or @@ -1281,32 +1385,31 @@ diff_match_patch.prototype.diff_text2 = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {number} Number of changes. */ -diff_match_patch.prototype.diff_levenshtein = function(diffs) { - var levenshtein = 0; - var insertions = 0; - var deletions = 0; +diff_match_patch.prototype.diff_levenshtein = function (diffs) { + var levenshtein = 0 + var insertions = 0 + var deletions = 0 for (var x = 0; x < diffs.length; x++) { - var op = diffs[x][0]; - var data = diffs[x][1]; + var op = diffs[x][0] + var data = diffs[x][1] switch (op) { case DIFF_INSERT: - insertions += data.length; - break; + insertions += data.length + break case DIFF_DELETE: - deletions += data.length; - break; + deletions += data.length + break case DIFF_EQUAL: // A deletion and an insertion is one substitution. - levenshtein += Math.max(insertions, deletions); - insertions = 0; - deletions = 0; - break; + levenshtein += Math.max(insertions, deletions) + insertions = 0 + deletions = 0 + break } } - levenshtein += Math.max(insertions, deletions); - return levenshtein; -}; - + levenshtein += Math.max(insertions, deletions) + return levenshtein +} /** * Crush the diff into an encoded string which describes the operations @@ -1316,24 +1419,23 @@ diff_match_patch.prototype.diff_levenshtein = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {string} Delta text. */ -diff_match_patch.prototype.diff_toDelta = function(diffs) { - var text = []; +diff_match_patch.prototype.diff_toDelta = function (diffs) { + var text = [] for (var x = 0; x < diffs.length; x++) { switch (diffs[x][0]) { case DIFF_INSERT: - text[x] = '+' + encodeURI(diffs[x][1]); - break; + text[x] = '+' + encodeURI(diffs[x][1]) + break case DIFF_DELETE: - text[x] = '-' + diffs[x][1].length; - break; + text[x] = '-' + diffs[x][1].length + break case DIFF_EQUAL: - text[x] = '=' + diffs[x][1].length; - break; + text[x] = '=' + diffs[x][1].length + break } } - return text.join('\t').replace(/%20/g, ' '); -}; - + return text.join('\t').replace(/%20/g, ' ') +} /** * Given the original text1, and an encoded string which describes the @@ -1343,58 +1445,62 @@ diff_match_patch.prototype.diff_toDelta = function(diffs) { * @return {!Array.} Array of diff tuples. * @throws {!Error} If invalid input. */ -diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { - var diffs = []; - var diffsLength = 0; // Keeping our own length var is faster in JS. - var pointer = 0; // Cursor in text1 - var tokens = delta.split(/\t/g); +diff_match_patch.prototype.diff_fromDelta = function (text1, delta) { + var diffs = [] + var diffsLength = 0 // Keeping our own length var is faster in JS. + var pointer = 0 // Cursor in text1 + var tokens = delta.split(/\t/g) for (var x = 0; x < tokens.length; x++) { // Each token begins with a one character parameter which specifies the // operation of this token (delete, insert, equality). - var param = tokens[x].substring(1); + var param = tokens[x].substring(1) switch (tokens[x].charAt(0)) { case '+': try { - diffs[diffsLength++] = [DIFF_INSERT, decodeURI(param)]; + diffs[diffsLength++] = [DIFF_INSERT, decodeURI(param)] } catch (ex) { // Malformed URI sequence. - throw new Error('Illegal escape in diff_fromDelta: ' + param); + throw new Error('Illegal escape in diff_fromDelta: ' + param) } - break; + break case '-': - // Fall through. + // Fall through. case '=': - var n = parseInt(param, 10); + var n = parseInt(param, 10) if (isNaN(n) || n < 0) { - throw new Error('Invalid number in diff_fromDelta: ' + param); + throw new Error('Invalid number in diff_fromDelta: ' + param) } - var text = text1.substring(pointer, pointer += n); + var text = text1.substring(pointer, (pointer += n)) if (tokens[x].charAt(0) == '=') { - diffs[diffsLength++] = [DIFF_EQUAL, text]; + diffs[diffsLength++] = [DIFF_EQUAL, text] } else { - diffs[diffsLength++] = [DIFF_DELETE, text]; + diffs[diffsLength++] = [DIFF_DELETE, text] } - break; + break default: // Blank tokens are ok (from a trailing \t). // Anything else is an error. if (tokens[x]) { - throw new Error('Invalid diff operation in diff_fromDelta: ' + - tokens[x]); + throw new Error( + 'Invalid diff operation in diff_fromDelta: ' + tokens[x] + ) } } } if (pointer != text1.length) { - throw new Error('Delta length (' + pointer + - ') does not equal source text length (' + text1.length + ').'); + throw new Error( + 'Delta length (' + + pointer + + ') does not equal source text length (' + + text1.length + + ').' + ) } - return diffs; -}; - + return diffs +} // MATCH FUNCTIONS - /** * Locate the best instance of 'pattern' in 'text' near 'loc'. * @param {string} text The text to search. @@ -1402,28 +1508,27 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { * @param {number} loc The location to search around. * @return {number} Best match index or -1. */ -diff_match_patch.prototype.match_main = function(text, pattern, loc) { +diff_match_patch.prototype.match_main = function (text, pattern, loc) { // Check for null inputs. if (text == null || pattern == null || loc == null) { - throw new Error('Null input. (match_main)'); + throw new Error('Null input. (match_main)') } - loc = Math.max(0, Math.min(loc, text.length)); + loc = Math.max(0, Math.min(loc, text.length)) if (text == pattern) { // Shortcut (potentially not guaranteed by the algorithm) - return 0; + return 0 } else if (!text.length) { // Nothing to match. - return -1; + return -1 } else if (text.substring(loc, loc + pattern.length) == pattern) { // Perfect match at the perfect spot! (Includes case of null pattern) - return loc; + return loc } else { // Do a fuzzy compare. - return this.match_bitap_(text, pattern, loc); + return this.match_bitap_(text, pattern, loc) } -}; - +} /** * Locate the best instance of 'pattern' in 'text' near 'loc' using the @@ -1434,15 +1539,15 @@ diff_match_patch.prototype.match_main = function(text, pattern, loc) { * @return {number} Best match index or -1. * @private */ -diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { +diff_match_patch.prototype.match_bitap_ = function (text, pattern, loc) { if (pattern.length > this.Match_MaxBits) { - throw new Error('Pattern too long for this browser.'); + throw new Error('Pattern too long for this browser.') } // Initialise the alphabet. - var s = this.match_alphabet_(pattern); + var s = this.match_alphabet_(pattern) - var dmp = this; // 'this' becomes 'window' in a closure. + var dmp = this // 'this' becomes 'window' in a closure. /** * Compute and return the score for a match with e errors and x location. @@ -1453,95 +1558,99 @@ diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { * @private */ function match_bitapScore_(e, x) { - var accuracy = e / pattern.length; - var proximity = Math.abs(loc - x); + var accuracy = e / pattern.length + var proximity = Math.abs(loc - x) if (!dmp.Match_Distance) { // Dodge divide by zero error. - return proximity ? 1.0 : accuracy; + return proximity ? 1.0 : accuracy } - return accuracy + (proximity / dmp.Match_Distance); + return accuracy + proximity / dmp.Match_Distance } // Highest score beyond which we give up. - var score_threshold = this.Match_Threshold; + var score_threshold = this.Match_Threshold // Is there a nearby exact match? (speedup) - var best_loc = text.indexOf(pattern, loc); + var best_loc = text.indexOf(pattern, loc) if (best_loc != -1) { - score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold); + score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold) // What about in the other direction? (speedup) - best_loc = text.lastIndexOf(pattern, loc + pattern.length); + best_loc = text.lastIndexOf(pattern, loc + pattern.length) if (best_loc != -1) { - score_threshold = - Math.min(match_bitapScore_(0, best_loc), score_threshold); + score_threshold = Math.min( + match_bitapScore_(0, best_loc), + score_threshold + ) } } // Initialise the bit arrays. - var matchmask = 1 << (pattern.length - 1); - best_loc = -1; + var matchmask = 1 << (pattern.length - 1) + best_loc = -1 - var bin_min, bin_mid; - var bin_max = pattern.length + text.length; - var last_rd; + var bin_min, bin_mid + var bin_max = pattern.length + text.length + var last_rd for (var d = 0; d < pattern.length; d++) { // Scan for the best match; each iteration allows for one more error. // Run a binary search to determine how far from 'loc' we can stray at this // error level. - bin_min = 0; - bin_mid = bin_max; + bin_min = 0 + bin_mid = bin_max while (bin_min < bin_mid) { if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) { - bin_min = bin_mid; + bin_min = bin_mid } else { - bin_max = bin_mid; + bin_max = bin_mid } - bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min); + bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min) } // Use the result from this iteration as the maximum for the next. - bin_max = bin_mid; - var start = Math.max(1, loc - bin_mid + 1); - var finish = Math.min(loc + bin_mid, text.length) + pattern.length; + bin_max = bin_mid + var start = Math.max(1, loc - bin_mid + 1) + var finish = Math.min(loc + bin_mid, text.length) + pattern.length - var rd = Array(finish + 2); - rd[finish + 1] = (1 << d) - 1; + var rd = Array(finish + 2) + rd[finish + 1] = (1 << d) - 1 for (var j = finish; j >= start; j--) { // The alphabet (s) is a sparse hash, so the following line generates // warnings. - var charMatch = s[text.charAt(j - 1)]; - if (d === 0) { // First pass: exact match. - rd[j] = ((rd[j + 1] << 1) | 1) & charMatch; - } else { // Subsequent passes: fuzzy match. - rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) | - (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | - last_rd[j + 1]; + var charMatch = s[text.charAt(j - 1)] + if (d === 0) { + // First pass: exact match. + rd[j] = ((rd[j + 1] << 1) | 1) & charMatch + } else { + // Subsequent passes: fuzzy match. + rd[j] = + (((rd[j + 1] << 1) | 1) & charMatch) | + (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | + last_rd[j + 1] } if (rd[j] & matchmask) { - var score = match_bitapScore_(d, j - 1); + var score = match_bitapScore_(d, j - 1) // This match will almost certainly be better than any existing match. // But check anyway. if (score <= score_threshold) { // Told you so. - score_threshold = score; - best_loc = j - 1; + score_threshold = score + best_loc = j - 1 if (best_loc > loc) { // When passing loc, don't exceed our current distance from loc. - start = Math.max(1, 2 * loc - best_loc); + start = Math.max(1, 2 * loc - best_loc) } else { // Already passed loc, downhill from here on in. - break; + break } } } } // No hope for a (better) match at greater error levels. if (match_bitapScore_(d + 1, loc) > score_threshold) { - break; + break } - last_rd = rd; + last_rd = rd } - return best_loc; -}; - + return best_loc +} /** * Initialise the alphabet for the Bitap algorithm. @@ -1549,21 +1658,19 @@ diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { * @return {!Object} Hash of character locations. * @private */ -diff_match_patch.prototype.match_alphabet_ = function(pattern) { - var s = {}; +diff_match_patch.prototype.match_alphabet_ = function (pattern) { + var s = {} for (var i = 0; i < pattern.length; i++) { - s[pattern.charAt(i)] = 0; + s[pattern.charAt(i)] = 0 } for (var i = 0; i < pattern.length; i++) { - s[pattern.charAt(i)] |= 1 << (pattern.length - i - 1); + s[pattern.charAt(i)] |= 1 << (pattern.length - i - 1) } - return s; -}; - + return s +} // PATCH FUNCTIONS - /** * Increase the context until it is unique, * but don't let the pattern expand beyond Match_MaxBits. @@ -1571,45 +1678,49 @@ diff_match_patch.prototype.match_alphabet_ = function(pattern) { * @param {string} text Source text. * @private */ -diff_match_patch.prototype.patch_addContext_ = function(patch, text) { +diff_match_patch.prototype.patch_addContext_ = function (patch, text) { if (text.length == 0) { - return; + return } - var pattern = text.substring(patch.start2, patch.start2 + patch.length1); - var padding = 0; + var pattern = text.substring(patch.start2, patch.start2 + patch.length1) + var padding = 0 // Look for the first and last matches of pattern in text. If two different // matches are found, increase the pattern length. - while (text.indexOf(pattern) != text.lastIndexOf(pattern) && - pattern.length < this.Match_MaxBits - this.Patch_Margin - - this.Patch_Margin) { - padding += this.Patch_Margin; - pattern = text.substring(patch.start2 - padding, - patch.start2 + patch.length1 + padding); + while ( + text.indexOf(pattern) != text.lastIndexOf(pattern) && + pattern.length < this.Match_MaxBits - this.Patch_Margin - this.Patch_Margin + ) { + padding += this.Patch_Margin + pattern = text.substring( + patch.start2 - padding, + patch.start2 + patch.length1 + padding + ) } // Add one chunk for good luck. - padding += this.Patch_Margin; + padding += this.Patch_Margin // Add the prefix. - var prefix = text.substring(patch.start2 - padding, patch.start2); + var prefix = text.substring(patch.start2 - padding, patch.start2) if (prefix) { - patch.diffs.unshift([DIFF_EQUAL, prefix]); + patch.diffs.unshift([DIFF_EQUAL, prefix]) } // Add the suffix. - var suffix = text.substring(patch.start2 + patch.length1, - patch.start2 + patch.length1 + padding); + var suffix = text.substring( + patch.start2 + patch.length1, + patch.start2 + patch.length1 + padding + ) if (suffix) { - patch.diffs.push([DIFF_EQUAL, suffix]); + patch.diffs.push([DIFF_EQUAL, suffix]) } // Roll back the start points. - patch.start1 -= prefix.length; - patch.start2 -= prefix.length; + patch.start1 -= prefix.length + patch.start2 -= prefix.length // Extend the lengths. - patch.length1 += prefix.length + suffix.length; - patch.length2 += prefix.length + suffix.length; -}; - + patch.length1 += prefix.length + suffix.length + patch.length2 += prefix.length + suffix.length +} /** * Compute a list of patches to turn text1 into text2. @@ -1633,143 +1744,161 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { * for text1 to text2 (method 4) or undefined (methods 1,2,3). * @return {!Array.} Array of Patch objects. */ -diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { - var text1, diffs; - if (typeof a == 'string' && typeof opt_b == 'string' && - typeof opt_c == 'undefined') { +diff_match_patch.prototype.patch_make = function (a, opt_b, opt_c) { + var text1, diffs + if ( + typeof a === 'string' && + typeof opt_b === 'string' && + typeof opt_c === 'undefined' + ) { // Method 1: text1, text2 // Compute diffs from text1 and text2. - text1 = /** @type {string} */(a); - diffs = this.diff_main(text1, /** @type {string} */(opt_b), true); + text1 = /** @type {string} */ (a) + diffs = this.diff_main(text1, /** @type {string} */ (opt_b), true) if (diffs.length > 2) { - this.diff_cleanupSemantic(diffs); - this.diff_cleanupEfficiency(diffs); + this.diff_cleanupSemantic(diffs) + this.diff_cleanupEfficiency(diffs) } - } else if (a && typeof a == 'object' && typeof opt_b == 'undefined' && - typeof opt_c == 'undefined') { + } else if ( + a && + typeof a === 'object' && + typeof opt_b === 'undefined' && + typeof opt_c === 'undefined' + ) { // Method 2: diffs // Compute text1 from diffs. - diffs = /** @type {!Array.} */(a); - text1 = this.diff_text1(diffs); - } else if (typeof a == 'string' && opt_b && typeof opt_b == 'object' && - typeof opt_c == 'undefined') { + diffs = /** @type {!Array.} */ (a) + text1 = this.diff_text1(diffs) + } else if ( + typeof a === 'string' && + opt_b && + typeof opt_b === 'object' && + typeof opt_c === 'undefined' + ) { // Method 3: text1, diffs - text1 = /** @type {string} */(a); - diffs = /** @type {!Array.} */(opt_b); - } else if (typeof a == 'string' && typeof opt_b == 'string' && - opt_c && typeof opt_c == 'object') { + text1 = /** @type {string} */ (a) + diffs = /** @type {!Array.} */ (opt_b) + } else if ( + typeof a === 'string' && + typeof opt_b === 'string' && + opt_c && + typeof opt_c === 'object' + ) { // Method 4: text1, text2, diffs // text2 is not used. - text1 = /** @type {string} */(a); - diffs = /** @type {!Array.} */(opt_c); + text1 = /** @type {string} */ (a) + diffs = /** @type {!Array.} */ (opt_c) } else { - throw new Error('Unknown call format to patch_make.'); + throw new Error('Unknown call format to patch_make.') } if (diffs.length === 0) { - return []; // Get rid of the null case. + return [] // Get rid of the null case. } - var patches = []; - var patch = new diff_match_patch.patch_obj(); - var patchDiffLength = 0; // Keeping our own length var is faster in JS. - var char_count1 = 0; // Number of characters into the text1 string. - var char_count2 = 0; // Number of characters into the text2 string. + var patches = [] + var patch = new diff_match_patch.patch_obj() + var patchDiffLength = 0 // Keeping our own length var is faster in JS. + var char_count1 = 0 // Number of characters into the text1 string. + var char_count2 = 0 // Number of characters into the text2 string. // Start with text1 (prepatch_text) and apply the diffs until we arrive at // text2 (postpatch_text). We recreate the patches one by one to determine // context info. - var prepatch_text = text1; - var postpatch_text = text1; + var prepatch_text = text1 + var postpatch_text = text1 for (var x = 0; x < diffs.length; x++) { - var diff_type = diffs[x][0]; - var diff_text = diffs[x][1]; + var diff_type = diffs[x][0] + var diff_text = diffs[x][1] if (!patchDiffLength && diff_type !== DIFF_EQUAL) { // A new patch starts here. - patch.start1 = char_count1; - patch.start2 = char_count2; + patch.start1 = char_count1 + patch.start2 = char_count2 } switch (diff_type) { case DIFF_INSERT: - patch.diffs[patchDiffLength++] = diffs[x]; - patch.length2 += diff_text.length; - postpatch_text = postpatch_text.substring(0, char_count2) + diff_text + - postpatch_text.substring(char_count2); - break; + patch.diffs[patchDiffLength++] = diffs[x] + patch.length2 += diff_text.length + postpatch_text = + postpatch_text.substring(0, char_count2) + + diff_text + + postpatch_text.substring(char_count2) + break case DIFF_DELETE: - patch.length1 += diff_text.length; - patch.diffs[patchDiffLength++] = diffs[x]; - postpatch_text = postpatch_text.substring(0, char_count2) + - postpatch_text.substring(char_count2 + - diff_text.length); - break; + patch.length1 += diff_text.length + patch.diffs[patchDiffLength++] = diffs[x] + postpatch_text = + postpatch_text.substring(0, char_count2) + + postpatch_text.substring(char_count2 + diff_text.length) + break case DIFF_EQUAL: - if (diff_text.length <= 2 * this.Patch_Margin && - patchDiffLength && diffs.length != x + 1) { + if ( + diff_text.length <= 2 * this.Patch_Margin && + patchDiffLength && + diffs.length != x + 1 + ) { // Small equality inside a patch. - patch.diffs[patchDiffLength++] = diffs[x]; - patch.length1 += diff_text.length; - patch.length2 += diff_text.length; + patch.diffs[patchDiffLength++] = diffs[x] + patch.length1 += diff_text.length + patch.length2 += diff_text.length } else if (diff_text.length >= 2 * this.Patch_Margin) { // Time for a new patch. if (patchDiffLength) { - this.patch_addContext_(patch, prepatch_text); - patches.push(patch); - patch = new diff_match_patch.patch_obj(); - patchDiffLength = 0; + this.patch_addContext_(patch, prepatch_text) + patches.push(patch) + patch = new diff_match_patch.patch_obj() + patchDiffLength = 0 // Unlike Unidiff, our patch lists have a rolling context. // http://code.google.com/p/google-diff-match-patch/wiki/Unidiff // Update prepatch text & pos to reflect the application of the // just completed patch. - prepatch_text = postpatch_text; - char_count1 = char_count2; + prepatch_text = postpatch_text + char_count1 = char_count2 } } - break; + break } // Update the current character count. if (diff_type !== DIFF_INSERT) { - char_count1 += diff_text.length; + char_count1 += diff_text.length } if (diff_type !== DIFF_DELETE) { - char_count2 += diff_text.length; + char_count2 += diff_text.length } } // Pick up the leftover patch if not empty. if (patchDiffLength) { - this.patch_addContext_(patch, prepatch_text); - patches.push(patch); + this.patch_addContext_(patch, prepatch_text) + patches.push(patch) } - return patches; -}; - + return patches +} /** * Given an array of patches, return another array that is identical. * @param {!Array.} patches Array of Patch objects. * @return {!Array.} Array of Patch objects. */ -diff_match_patch.prototype.patch_deepCopy = function(patches) { +diff_match_patch.prototype.patch_deepCopy = function (patches) { // Making deep copies is hard in JavaScript. - var patchesCopy = []; + var patchesCopy = [] for (var x = 0; x < patches.length; x++) { - var patch = patches[x]; - var patchCopy = new diff_match_patch.patch_obj(); - patchCopy.diffs = []; + var patch = patches[x] + var patchCopy = new diff_match_patch.patch_obj() + patchCopy.diffs = [] for (var y = 0; y < patch.diffs.length; y++) { - patchCopy.diffs[y] = patch.diffs[y].slice(); + patchCopy.diffs[y] = patch.diffs[y].slice() } - patchCopy.start1 = patch.start1; - patchCopy.start2 = patch.start2; - patchCopy.length1 = patch.length1; - patchCopy.length2 = patch.length2; - patchesCopy[x] = patchCopy; + patchCopy.start1 = patch.start1 + patchCopy.start2 = patch.start2 + patchCopy.length1 = patch.length1 + patchCopy.length2 = patch.length2 + patchesCopy[x] = patchCopy } - return patchesCopy; -}; - + return patchesCopy +} /** * Merge a set of patches onto the text. Return a patched text, as well @@ -1779,94 +1908,108 @@ diff_match_patch.prototype.patch_deepCopy = function(patches) { * @return {!Array.>} Two element Array, containing the * new text and an array of boolean values. */ -diff_match_patch.prototype.patch_apply = function(patches, text) { +diff_match_patch.prototype.patch_apply = function (patches, text) { if (patches.length == 0) { - return [text, []]; + return [text, []] } // Deep copy the patches so that no changes are made to originals. - patches = this.patch_deepCopy(patches); + patches = this.patch_deepCopy(patches) - var nullPadding = this.patch_addPadding(patches); - text = nullPadding + text + nullPadding; + var nullPadding = this.patch_addPadding(patches) + text = nullPadding + text + nullPadding - this.patch_splitMax(patches); + this.patch_splitMax(patches) // delta keeps track of the offset between the expected and actual location // of the previous patch. If there are patches expected at positions 10 and // 20, but the first patch was found at 12, delta is 2 and the second patch // has an effective expected position of 22. - var delta = 0; - var results = []; + var delta = 0 + var results = [] for (var x = 0; x < patches.length; x++) { - var expected_loc = patches[x].start2 + delta; - var text1 = this.diff_text1(patches[x].diffs); - var start_loc; - var end_loc = -1; + var expected_loc = patches[x].start2 + delta + var text1 = this.diff_text1(patches[x].diffs) + var start_loc + var end_loc = -1 if (text1.length > this.Match_MaxBits) { // patch_splitMax will only provide an oversized pattern in the case of // a monster delete. - start_loc = this.match_main(text, text1.substring(0, this.Match_MaxBits), - expected_loc); + start_loc = this.match_main( + text, + text1.substring(0, this.Match_MaxBits), + expected_loc + ) if (start_loc != -1) { - end_loc = this.match_main(text, - text1.substring(text1.length - this.Match_MaxBits), - expected_loc + text1.length - this.Match_MaxBits); + end_loc = this.match_main( + text, + text1.substring(text1.length - this.Match_MaxBits), + expected_loc + text1.length - this.Match_MaxBits + ) if (end_loc == -1 || start_loc >= end_loc) { // Can't find valid trailing context. Drop this patch. - start_loc = -1; + start_loc = -1 } } } else { - start_loc = this.match_main(text, text1, expected_loc); + start_loc = this.match_main(text, text1, expected_loc) } if (start_loc == -1) { // No match found. :( - results[x] = false; + results[x] = false // Subtract the delta for this failed patch from subsequent patches. - delta -= patches[x].length2 - patches[x].length1; + delta -= patches[x].length2 - patches[x].length1 } else { // Found a match. :) - results[x] = true; - delta = start_loc - expected_loc; - var text2; + results[x] = true + delta = start_loc - expected_loc + var text2 if (end_loc == -1) { - text2 = text.substring(start_loc, start_loc + text1.length); + text2 = text.substring(start_loc, start_loc + text1.length) } else { - text2 = text.substring(start_loc, end_loc + this.Match_MaxBits); + text2 = text.substring(start_loc, end_loc + this.Match_MaxBits) } if (text1 == text2) { // Perfect match, just shove the replacement text in. - text = text.substring(0, start_loc) + - this.diff_text2(patches[x].diffs) + - text.substring(start_loc + text1.length); + text = + text.substring(0, start_loc) + + this.diff_text2(patches[x].diffs) + + text.substring(start_loc + text1.length) } else { // Imperfect match. Run a diff to get a framework of equivalent // indices. - var diffs = this.diff_main(text1, text2, false); - if (text1.length > this.Match_MaxBits && - this.diff_levenshtein(diffs) / text1.length > - this.Patch_DeleteThreshold) { + var diffs = this.diff_main(text1, text2, false) + if ( + text1.length > this.Match_MaxBits && + this.diff_levenshtein(diffs) / text1.length > + this.Patch_DeleteThreshold + ) { // The end points match, but the content is unacceptably bad. - results[x] = false; + results[x] = false } else { - this.diff_cleanupSemanticLossless(diffs); - var index1 = 0; - var index2; + this.diff_cleanupSemanticLossless(diffs) + var index1 = 0 + var index2 for (var y = 0; y < patches[x].diffs.length; y++) { - var mod = patches[x].diffs[y]; + var mod = patches[x].diffs[y] if (mod[0] !== DIFF_EQUAL) { - index2 = this.diff_xIndex(diffs, index1); + index2 = this.diff_xIndex(diffs, index1) } - if (mod[0] === DIFF_INSERT) { // Insertion - text = text.substring(0, start_loc + index2) + mod[1] + - text.substring(start_loc + index2); - } else if (mod[0] === DIFF_DELETE) { // Deletion - text = text.substring(0, start_loc + index2) + - text.substring(start_loc + this.diff_xIndex(diffs, - index1 + mod[1].length)); + if (mod[0] === DIFF_INSERT) { + // Insertion + text = + text.substring(0, start_loc + index2) + + mod[1] + + text.substring(start_loc + index2) + } else if (mod[0] === DIFF_DELETE) { + // Deletion + text = + text.substring(0, start_loc + index2) + + text.substring( + start_loc + this.diff_xIndex(diffs, index1 + mod[1].length) + ) } if (mod[0] !== DIFF_DELETE) { - index1 += mod[1].length; + index1 += mod[1].length } } } @@ -1874,10 +2017,9 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { } } // Strip the padding off. - text = text.substring(nullPadding.length, text.length - nullPadding.length); - return [text, results]; -}; - + text = text.substring(nullPadding.length, text.length - nullPadding.length) + return [text, results] +} /** * Add some padding on text start and end so that edges can match something. @@ -1885,58 +2027,57 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { * @param {!Array.} patches Array of Patch objects. * @return {string} The padding string added to each side. */ -diff_match_patch.prototype.patch_addPadding = function(patches) { - var paddingLength = this.Patch_Margin; - var nullPadding = ''; +diff_match_patch.prototype.patch_addPadding = function (patches) { + var paddingLength = this.Patch_Margin + var nullPadding = '' for (var x = 1; x <= paddingLength; x++) { - nullPadding += String.fromCharCode(x); + nullPadding += String.fromCharCode(x) } // Bump all the patches forward. for (var x = 0; x < patches.length; x++) { - patches[x].start1 += paddingLength; - patches[x].start2 += paddingLength; + patches[x].start1 += paddingLength + patches[x].start2 += paddingLength } // Add some padding on start of first diff. - var patch = patches[0]; - var diffs = patch.diffs; + var patch = patches[0] + var diffs = patch.diffs if (diffs.length == 0 || diffs[0][0] != DIFF_EQUAL) { // Add nullPadding equality. - diffs.unshift([DIFF_EQUAL, nullPadding]); - patch.start1 -= paddingLength; // Should be 0. - patch.start2 -= paddingLength; // Should be 0. - patch.length1 += paddingLength; - patch.length2 += paddingLength; + diffs.unshift([DIFF_EQUAL, nullPadding]) + patch.start1 -= paddingLength // Should be 0. + patch.start2 -= paddingLength // Should be 0. + patch.length1 += paddingLength + patch.length2 += paddingLength } else if (paddingLength > diffs[0][1].length) { // Grow first equality. - var extraLength = paddingLength - diffs[0][1].length; - diffs[0][1] = nullPadding.substring(diffs[0][1].length) + diffs[0][1]; - patch.start1 -= extraLength; - patch.start2 -= extraLength; - patch.length1 += extraLength; - patch.length2 += extraLength; + var extraLength = paddingLength - diffs[0][1].length + diffs[0][1] = nullPadding.substring(diffs[0][1].length) + diffs[0][1] + patch.start1 -= extraLength + patch.start2 -= extraLength + patch.length1 += extraLength + patch.length2 += extraLength } // Add some padding on end of last diff. - patch = patches[patches.length - 1]; - diffs = patch.diffs; + patch = patches[patches.length - 1] + diffs = patch.diffs if (diffs.length == 0 || diffs[diffs.length - 1][0] != DIFF_EQUAL) { // Add nullPadding equality. - diffs.push([DIFF_EQUAL, nullPadding]); - patch.length1 += paddingLength; - patch.length2 += paddingLength; + diffs.push([DIFF_EQUAL, nullPadding]) + patch.length1 += paddingLength + patch.length2 += paddingLength } else if (paddingLength > diffs[diffs.length - 1][1].length) { // Grow last equality. - var extraLength = paddingLength - diffs[diffs.length - 1][1].length; - diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength); - patch.length1 += extraLength; - patch.length2 += extraLength; + var extraLength = paddingLength - diffs[diffs.length - 1][1].length + diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength) + patch.length1 += extraLength + patch.length2 += extraLength } - return nullPadding; -}; - + return nullPadding +} /** * Look through the patches and break up any which are longer than the maximum @@ -1944,106 +2085,115 @@ diff_match_patch.prototype.patch_addPadding = function(patches) { * Intended to be called only from within patch_apply. * @param {!Array.} patches Array of Patch objects. */ -diff_match_patch.prototype.patch_splitMax = function(patches) { - var patch_size = this.Match_MaxBits; +diff_match_patch.prototype.patch_splitMax = function (patches) { + var patch_size = this.Match_MaxBits for (var x = 0; x < patches.length; x++) { if (patches[x].length1 <= patch_size) { - continue; + continue } - var bigpatch = patches[x]; + var bigpatch = patches[x] // Remove the big old patch. - patches.splice(x--, 1); - var start1 = bigpatch.start1; - var start2 = bigpatch.start2; - var precontext = ''; + patches.splice(x--, 1) + var start1 = bigpatch.start1 + var start2 = bigpatch.start2 + var precontext = '' while (bigpatch.diffs.length !== 0) { // Create one of several smaller patches. - var patch = new diff_match_patch.patch_obj(); - var empty = true; - patch.start1 = start1 - precontext.length; - patch.start2 = start2 - precontext.length; + var patch = new diff_match_patch.patch_obj() + var empty = true + patch.start1 = start1 - precontext.length + patch.start2 = start2 - precontext.length if (precontext !== '') { - patch.length1 = patch.length2 = precontext.length; - patch.diffs.push([DIFF_EQUAL, precontext]); + patch.length1 = patch.length2 = precontext.length + patch.diffs.push([DIFF_EQUAL, precontext]) } - while (bigpatch.diffs.length !== 0 && - patch.length1 < patch_size - this.Patch_Margin) { - var diff_type = bigpatch.diffs[0][0]; - var diff_text = bigpatch.diffs[0][1]; + while ( + bigpatch.diffs.length !== 0 && + patch.length1 < patch_size - this.Patch_Margin + ) { + var diff_type = bigpatch.diffs[0][0] + var diff_text = bigpatch.diffs[0][1] if (diff_type === DIFF_INSERT) { // Insertions are harmless. - patch.length2 += diff_text.length; - start2 += diff_text.length; - patch.diffs.push(bigpatch.diffs.shift()); - empty = false; - } else if (diff_type === DIFF_DELETE && patch.diffs.length == 1 && - patch.diffs[0][0] == DIFF_EQUAL && - diff_text.length > 2 * patch_size) { + patch.length2 += diff_text.length + start2 += diff_text.length + patch.diffs.push(bigpatch.diffs.shift()) + empty = false + } else if ( + diff_type === DIFF_DELETE && + patch.diffs.length == 1 && + patch.diffs[0][0] == DIFF_EQUAL && + diff_text.length > 2 * patch_size + ) { // This is a large deletion. Let it pass in one chunk. - patch.length1 += diff_text.length; - start1 += diff_text.length; - empty = false; - patch.diffs.push([diff_type, diff_text]); - bigpatch.diffs.shift(); + patch.length1 += diff_text.length + start1 += diff_text.length + empty = false + patch.diffs.push([diff_type, diff_text]) + bigpatch.diffs.shift() } else { // Deletion or equality. Only take as much as we can stomach. - diff_text = diff_text.substring(0, - patch_size - patch.length1 - this.Patch_Margin); - patch.length1 += diff_text.length; - start1 += diff_text.length; + diff_text = diff_text.substring( + 0, + patch_size - patch.length1 - this.Patch_Margin + ) + patch.length1 += diff_text.length + start1 += diff_text.length if (diff_type === DIFF_EQUAL) { - patch.length2 += diff_text.length; - start2 += diff_text.length; + patch.length2 += diff_text.length + start2 += diff_text.length } else { - empty = false; + empty = false } - patch.diffs.push([diff_type, diff_text]); + patch.diffs.push([diff_type, diff_text]) if (diff_text == bigpatch.diffs[0][1]) { - bigpatch.diffs.shift(); + bigpatch.diffs.shift() } else { - bigpatch.diffs[0][1] = - bigpatch.diffs[0][1].substring(diff_text.length); + bigpatch.diffs[0][1] = bigpatch.diffs[0][1].substring( + diff_text.length + ) } } } // Compute the head context for the next patch. - precontext = this.diff_text2(patch.diffs); - precontext = - precontext.substring(precontext.length - this.Patch_Margin); + precontext = this.diff_text2(patch.diffs) + precontext = precontext.substring(precontext.length - this.Patch_Margin) // Append the end context for this patch. - var postcontext = this.diff_text1(bigpatch.diffs) - .substring(0, this.Patch_Margin); + var postcontext = this.diff_text1(bigpatch.diffs).substring( + 0, + this.Patch_Margin + ) if (postcontext !== '') { - patch.length1 += postcontext.length; - patch.length2 += postcontext.length; - if (patch.diffs.length !== 0 && - patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) { - patch.diffs[patch.diffs.length - 1][1] += postcontext; + patch.length1 += postcontext.length + patch.length2 += postcontext.length + if ( + patch.diffs.length !== 0 && + patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL + ) { + patch.diffs[patch.diffs.length - 1][1] += postcontext } else { - patch.diffs.push([DIFF_EQUAL, postcontext]); + patch.diffs.push([DIFF_EQUAL, postcontext]) } } if (!empty) { - patches.splice(++x, 0, patch); + patches.splice(++x, 0, patch) } } } -}; - +} /** * Take a list of patches and return a textual representation. * @param {!Array.} patches Array of Patch objects. * @return {string} Text representation of patches. */ -diff_match_patch.prototype.patch_toText = function(patches) { - var text = []; +diff_match_patch.prototype.patch_toText = function (patches) { + var text = [] for (var x = 0; x < patches.length; x++) { - text[x] = patches[x]; + text[x] = patches[x] } - return text.join(''); -}; - + return text.join('') +} /** * Parse a textual representation of patches and return a list of Patch objects. @@ -2051,94 +2201,92 @@ diff_match_patch.prototype.patch_toText = function(patches) { * @return {!Array.} Array of Patch objects. * @throws {!Error} If invalid input. */ -diff_match_patch.prototype.patch_fromText = function(textline) { - var patches = []; +diff_match_patch.prototype.patch_fromText = function (textline) { + var patches = [] if (!textline) { - return patches; + return patches } - var text = textline.split('\n'); - var textPointer = 0; - var patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/; + var text = textline.split('\n') + var textPointer = 0 + var patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/ while (textPointer < text.length) { - var m = text[textPointer].match(patchHeader); + var m = text[textPointer].match(patchHeader) if (!m) { - throw new Error('Invalid patch string: ' + text[textPointer]); + throw new Error('Invalid patch string: ' + text[textPointer]) } - var patch = new diff_match_patch.patch_obj(); - patches.push(patch); - patch.start1 = parseInt(m[1], 10); + var patch = new diff_match_patch.patch_obj() + patches.push(patch) + patch.start1 = parseInt(m[1], 10) if (m[2] === '') { - patch.start1--; - patch.length1 = 1; + patch.start1-- + patch.length1 = 1 } else if (m[2] == '0') { - patch.length1 = 0; + patch.length1 = 0 } else { - patch.start1--; - patch.length1 = parseInt(m[2], 10); + patch.start1-- + patch.length1 = parseInt(m[2], 10) } - patch.start2 = parseInt(m[3], 10); + patch.start2 = parseInt(m[3], 10) if (m[4] === '') { - patch.start2--; - patch.length2 = 1; + patch.start2-- + patch.length2 = 1 } else if (m[4] == '0') { - patch.length2 = 0; + patch.length2 = 0 } else { - patch.start2--; - patch.length2 = parseInt(m[4], 10); + patch.start2-- + patch.length2 = parseInt(m[4], 10) } - textPointer++; + textPointer++ while (textPointer < text.length) { - var sign = text[textPointer].charAt(0); + var sign = text[textPointer].charAt(0) try { - var line = decodeURI(text[textPointer].substring(1)); + var line = decodeURI(text[textPointer].substring(1)) } catch (ex) { // Malformed URI sequence. - throw new Error('Illegal escape in patch_fromText: ' + line); + throw new Error('Illegal escape in patch_fromText: ' + line) } if (sign == '-') { // Deletion. - patch.diffs.push([DIFF_DELETE, line]); + patch.diffs.push([DIFF_DELETE, line]) } else if (sign == '+') { // Insertion. - patch.diffs.push([DIFF_INSERT, line]); + patch.diffs.push([DIFF_INSERT, line]) } else if (sign == ' ') { // Minor equality. - patch.diffs.push([DIFF_EQUAL, line]); + patch.diffs.push([DIFF_EQUAL, line]) } else if (sign == '@') { // Start of next patch. - break; + break } else if (sign === '') { // Blank line? Whatever. } else { // WTF? - throw new Error('Invalid patch mode "' + sign + '" in: ' + line); + throw new Error('Invalid patch mode "' + sign + '" in: ' + line) } - textPointer++; + textPointer++ } } - return patches; -}; - + return patches +} /** * Class representing one patch operation. * @constructor */ -diff_match_patch.patch_obj = function() { +diff_match_patch.patch_obj = function () { /** @type {!Array.} */ - this.diffs = []; + this.diffs = [] /** @type {?number} */ - this.start1 = null; + this.start1 = null /** @type {?number} */ - this.start2 = null; + this.start2 = null /** @type {number} */ - this.length1 = 0; + this.length1 = 0 /** @type {number} */ - this.length2 = 0; -}; - + this.length2 = 0 +} /** * Emmulate GNU diff's format. @@ -2146,48 +2294,47 @@ diff_match_patch.patch_obj = function() { * Indicies are printed as 1-based, not 0-based. * @return {string} The GNU diff string. */ -diff_match_patch.patch_obj.prototype.toString = function() { - var coords1, coords2; +diff_match_patch.patch_obj.prototype.toString = function () { + var coords1, coords2 if (this.length1 === 0) { - coords1 = this.start1 + ',0'; + coords1 = this.start1 + ',0' } else if (this.length1 == 1) { - coords1 = this.start1 + 1; + coords1 = this.start1 + 1 } else { - coords1 = (this.start1 + 1) + ',' + this.length1; + coords1 = this.start1 + 1 + ',' + this.length1 } if (this.length2 === 0) { - coords2 = this.start2 + ',0'; + coords2 = this.start2 + ',0' } else if (this.length2 == 1) { - coords2 = this.start2 + 1; + coords2 = this.start2 + 1 } else { - coords2 = (this.start2 + 1) + ',' + this.length2; + coords2 = this.start2 + 1 + ',' + this.length2 } - var text = ['@@ -' + coords1 + ' +' + coords2 + ' @@\n']; - var op; + var text = ['@@ -' + coords1 + ' +' + coords2 + ' @@\n'] + var op // Escape the body of the patch with %xx notation. for (var x = 0; x < this.diffs.length; x++) { switch (this.diffs[x][0]) { case DIFF_INSERT: - op = '+'; - break; + op = '+' + break case DIFF_DELETE: - op = '-'; - break; + op = '-' + break case DIFF_EQUAL: - op = ' '; - break; + op = ' ' + break } - text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n'; + text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n' } - return text.join('').replace(/%20/g, ' '); -}; - + return text.join('').replace(/%20/g, ' ') +} // Export these global variables so that they survive Google's JS compiler. // In a browser, 'this' will be 'window'. // Users of node.js should 'require' the uncompressed version since Google's // JS compiler may break the following exports for non-browser environments. -this['diff_match_patch'] = diff_match_patch; -this['DIFF_DELETE'] = DIFF_DELETE; -this['DIFF_INSERT'] = DIFF_INSERT; -this['DIFF_EQUAL'] = DIFF_EQUAL; +this.diff_match_patch = diff_match_patch +this.DIFF_DELETE = DIFF_DELETE +this.DIFF_INSERT = DIFF_INSERT +this.DIFF_EQUAL = DIFF_EQUAL diff --git a/services/track-changes/config/settings.defaults.js b/services/track-changes/config/settings.defaults.js index 543feea917..2cee6df6af 100755 --- a/services/track-changes/config/settings.defaults.js +++ b/services/track-changes/config/settings.defaults.js @@ -17,19 +17,19 @@ module.exports = { }, apis: { documentupdater: { - url: `http://${process.env.DOCUMENT_UPDATER_HOST || + url: `http://${ + process.env.DOCUMENT_UPDATER_HOST || process.env.DOCUPDATER_HOST || - 'localhost'}:3003` + 'localhost' + }:3003` }, docstore: { url: `http://${process.env.DOCSTORE_HOST || 'localhost'}:3016` }, web: { - url: `http://${process.env.WEB_API_HOST || - process.env.WEB_HOST || - 'localhost'}:${process.env.WEB_API_PORT || - process.env.WEB_PORT || - 3000}`, + url: `http://${ + process.env.WEB_API_HOST || process.env.WEB_HOST || 'localhost' + }:${process.env.WEB_API_PORT || process.env.WEB_PORT || 3000}`, user: process.env.WEB_API_USER || 'sharelatex', pass: process.env.WEB_API_PASSWORD || 'password' } diff --git a/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js b/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js index c20703d71f..d6d6b44726 100644 --- a/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js @@ -24,13 +24,13 @@ const TrackChangesApp = require('./helpers/TrackChangesApp') const TrackChangesClient = require('./helpers/TrackChangesClient') const MockWebApi = require('./helpers/MockWebApi') -describe('Appending doc ops to the history', function() { - before(function(done) { +describe('Appending doc ops to the history', function () { + before(function (done) { return TrackChangesApp.ensureRunning(done) }) - describe('when the history does not exist yet', function() { - before(function(done) { + describe('when the history does not exist yet', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -55,7 +55,7 @@ describe('Appending doc ops to the history', function() { v: 5 } ], - error => { + (error) => { if (error != null) { throw error } @@ -75,7 +75,7 @@ describe('Appending doc ops to the history', function() { return null }) - it('should insert the compressed op into mongo', function() { + it('should insert the compressed op into mongo', function () { return expect(this.updates[0].pack[0].op).to.deep.equal([ { p: 3, @@ -84,21 +84,21 @@ describe('Appending doc ops to the history', function() { ]) }) - it('should insert the correct version number into mongo', function() { + it('should insert the correct version number into mongo', function () { return expect(this.updates[0].v).to.equal(5) }) - it('should store the doc id', function() { + it('should store the doc id', function () { return expect(this.updates[0].doc_id.toString()).to.equal(this.doc_id) }) - it('should store the project id', function() { + it('should store the project id', function () { return expect(this.updates[0].project_id.toString()).to.equal( this.project_id ) }) - return it('should clear the doc from the DocsWithHistoryOps set', function(done) { + return it('should clear the doc from the DocsWithHistoryOps set', function (done) { rclient.sismember( `DocsWithHistoryOps:${this.project_id}`, this.doc_id, @@ -111,8 +111,8 @@ describe('Appending doc ops to the history', function() { }) }) - describe('when the history has already been started', function() { - beforeEach(function(done) { + describe('when the history has already been started', function () { + beforeEach(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -137,7 +137,7 @@ describe('Appending doc ops to the history', function() { v: 5 } ], - error => { + (error) => { if (error != null) { throw error } @@ -156,8 +156,8 @@ describe('Appending doc ops to the history', function() { return null }) - describe('when the updates are recent and from the same user', function() { - beforeEach(function(done) { + describe('when the updates are recent and from the same user', function () { + beforeEach(function (done) { TrackChangesClient.pushRawUpdates( this.project_id, this.doc_id, @@ -178,7 +178,7 @@ describe('Appending doc ops to the history', function() { v: 8 } ], - error => { + (error) => { if (error != null) { throw error } @@ -198,7 +198,7 @@ describe('Appending doc ops to the history', function() { return null }) - it('should combine all the updates into one pack', function() { + it('should combine all the updates into one pack', function () { return expect(this.updates[0].pack[1].op).to.deep.equal([ { p: 6, @@ -207,13 +207,13 @@ describe('Appending doc ops to the history', function() { ]) }) - return it('should insert the correct version number into mongo', function() { + return it('should insert the correct version number into mongo', function () { return expect(this.updates[0].v_end).to.equal(8) }) }) - return describe('when the updates are far apart', function() { - beforeEach(function(done) { + return describe('when the updates are far apart', function () { + beforeEach(function (done) { const oneDay = 24 * 60 * 60 * 1000 TrackChangesClient.pushRawUpdates( this.project_id, @@ -235,7 +235,7 @@ describe('Appending doc ops to the history', function() { v: 8 } ], - error => { + (error) => { if (error != null) { throw error } @@ -255,7 +255,7 @@ describe('Appending doc ops to the history', function() { return null }) - return it('should combine the updates into one pack', function() { + return it('should combine the updates into one pack', function () { expect(this.updates[0].pack[0].op).to.deep.equal([ { p: 3, @@ -272,8 +272,8 @@ describe('Appending doc ops to the history', function() { }) }) - describe('when the updates need processing in batches', function() { - before(function(done) { + describe('when the updates need processing in batches', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -293,7 +293,7 @@ describe('Appending doc ops to the history', function() { this.project_id, this.doc_id, updates, - error => { + (error) => { if (error != null) { throw error } @@ -313,17 +313,17 @@ describe('Appending doc ops to the history', function() { return null }) - it('should concat the compressed op into mongo', function() { + it('should concat the compressed op into mongo', function () { return expect(this.updates[0].pack.length).to.deep.equal(3) }) // batch size is 100 - return it('should insert the correct version number into mongo', function() { + return it('should insert the correct version number into mongo', function () { return expect(this.updates[0].v_end).to.equal(250) }) }) - describe('when there are multiple ops in each update', function() { - before(function(done) { + describe('when there are multiple ops in each update', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -352,7 +352,7 @@ describe('Appending doc ops to the history', function() { v: 4 } ], - error => { + (error) => { if (error != null) { throw error } @@ -372,7 +372,7 @@ describe('Appending doc ops to the history', function() { return null }) - it('should insert the compressed ops into mongo', function() { + it('should insert the compressed ops into mongo', function () { expect(this.updates[0].pack[0].op).to.deep.equal([ { p: 3, @@ -387,14 +387,14 @@ describe('Appending doc ops to the history', function() { ]) }) - return it('should insert the correct version numbers into mongo', function() { + return it('should insert the correct version numbers into mongo', function () { expect(this.updates[0].pack[0].v).to.equal(3) return expect(this.updates[0].pack[1].v).to.equal(4) }) }) - describe('when there is a no-op update', function() { - before(function(done) { + describe('when there is a no-op update', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -415,7 +415,7 @@ describe('Appending doc ops to the history', function() { v: 4 } ], - error => { + (error) => { if (error != null) { throw error } @@ -435,11 +435,11 @@ describe('Appending doc ops to the history', function() { return null }) - it('should insert the compressed no-op into mongo', function() { + it('should insert the compressed no-op into mongo', function () { return expect(this.updates[0].pack[0].op).to.deep.equal([]) }) - it('should insert the compressed next update into mongo', function() { + it('should insert the compressed next update into mongo', function () { return expect(this.updates[0].pack[1].op).to.deep.equal([ { p: 3, @@ -448,14 +448,14 @@ describe('Appending doc ops to the history', function() { ]) }) - return it('should insert the correct version numbers into mongo', function() { + return it('should insert the correct version numbers into mongo', function () { expect(this.updates[0].pack[0].v).to.equal(3) return expect(this.updates[0].pack[1].v).to.equal(4) }) }) - describe('when there is a comment update', function() { - before(function(done) { + describe('when there is a comment update', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -473,7 +473,7 @@ describe('Appending doc ops to the history', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } @@ -493,19 +493,19 @@ describe('Appending doc ops to the history', function() { return null }) - it('should ignore the comment op', function() { + it('should ignore the comment op', function () { return expect(this.updates[0].pack[0].op).to.deep.equal([ { d: 'bar', p: 6 } ]) }) - return it('should insert the correct version numbers into mongo', function() { + return it('should insert the correct version numbers into mongo', function () { return expect(this.updates[0].pack[0].v).to.equal(3) }) }) - describe('when the project has versioning enabled', function() { - before(function(done) { + describe('when the project has versioning enabled', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -521,7 +521,7 @@ describe('Appending doc ops to the history', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } @@ -541,13 +541,13 @@ describe('Appending doc ops to the history', function() { return null }) - return it('should not add a expiresAt entry in the update in mongo', function() { + return it('should not add a expiresAt entry in the update in mongo', function () { return expect(this.updates[0].expiresAt).to.be.undefined }) }) - return describe('when the project does not have versioning enabled', function() { - before(function(done) { + return describe('when the project does not have versioning enabled', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -563,7 +563,7 @@ describe('Appending doc ops to the history', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } @@ -583,7 +583,7 @@ describe('Appending doc ops to the history', function() { return null }) - return it('should add a expiresAt entry in the update in mongo', function() { + return it('should add a expiresAt entry in the update in mongo', function () { return expect(this.updates[0].expiresAt).to.exist }) }) diff --git a/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js b/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js index d66ed60940..8ceb1b0ba7 100644 --- a/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js @@ -30,15 +30,15 @@ const TrackChangesClient = require('./helpers/TrackChangesClient') const MockDocStoreApi = require('./helpers/MockDocStoreApi') const MockWebApi = require('./helpers/MockWebApi') -describe('Archiving updates', function() { - before(function(done) { +describe('Archiving updates', function () { + before(function (done) { if ( __guard__( __guard__( Settings != null ? Settings.trackchanges : undefined, - x1 => x1.s3 + (x1) => x1.s3 ), - x => x.key.length + (x) => x.key.length ) < 1 ) { const message = new Error('s3 keys not setup, this test setup will fail') @@ -48,7 +48,7 @@ describe('Archiving updates', function() { return TrackChangesClient.waitForS3(done) }) - before(function(done) { + before(function (done) { this.now = Date.now() this.to = this.now this.user_id = ObjectId().toString() @@ -104,14 +104,14 @@ describe('Archiving updates', function() { this.project_id, this.doc_id, this.updates, - error => { + (error) => { if (error != null) { throw error } return TrackChangesClient.flushDoc( this.project_id, this.doc_id, - error => { + (error) => { if (error != null) { throw error } @@ -124,7 +124,7 @@ describe('Archiving updates', function() { return null }) - after(function(done) { + after(function (done) { MockWebApi.getUserInfo.restore() return db.docHistory.remove( { project_id: ObjectId(this.project_id) }, @@ -143,18 +143,22 @@ describe('Archiving updates', function() { ) }) - describe("archiving a doc's updates", function() { - before(function(done) { - TrackChangesClient.pushDocHistory(this.project_id, this.doc_id, error => { - if (error != null) { - throw error + describe("archiving a doc's updates", function () { + before(function (done) { + TrackChangesClient.pushDocHistory( + this.project_id, + this.doc_id, + (error) => { + if (error != null) { + throw error + } + return done() } - return done() - }) + ) return null }) - it('should have one cached pack', function(done) { + it('should have one cached pack', function (done) { return db.docHistory.count( { doc_id: ObjectId(this.doc_id), expiresAt: { $exists: true } }, (error, count) => { @@ -167,7 +171,7 @@ describe('Archiving updates', function() { ) }) - it('should have one remaining pack after cache is expired', function(done) { + it('should have one remaining pack after cache is expired', function (done) { return db.docHistory.remove( { doc_id: ObjectId(this.doc_id), @@ -191,7 +195,7 @@ describe('Archiving updates', function() { ) }) - it('should have a docHistoryIndex entry marked as inS3', function(done) { + it('should have a docHistoryIndex entry marked as inS3', function (done) { return db.docHistoryIndex.findOne( { _id: ObjectId(this.doc_id) }, (error, index) => { @@ -204,7 +208,7 @@ describe('Archiving updates', function() { ) }) - it('should have a docHistoryIndex entry with the last version', function(done) { + it('should have a docHistoryIndex entry with the last version', function (done) { return db.docHistoryIndex.findOne( { _id: ObjectId(this.doc_id) }, (error, index) => { @@ -217,7 +221,7 @@ describe('Archiving updates', function() { ) }) - return it('should store 1024 doc changes in S3 in one pack', function(done) { + return it('should store 1024 doc changes in S3 in one pack', function (done) { return db.docHistoryIndex.findOne( { _id: ObjectId(this.doc_id) }, (error, index) => { @@ -240,18 +244,22 @@ describe('Archiving updates', function() { }) }) - return describe("unarchiving a doc's updates", function() { - before(function(done) { - TrackChangesClient.pullDocHistory(this.project_id, this.doc_id, error => { - if (error != null) { - throw error + return describe("unarchiving a doc's updates", function () { + before(function (done) { + TrackChangesClient.pullDocHistory( + this.project_id, + this.doc_id, + (error) => { + if (error != null) { + throw error + } + return done() } - return done() - }) + ) return null }) - return it('should restore both packs', function(done) { + return it('should restore both packs', function (done) { return db.docHistory.count( { doc_id: ObjectId(this.doc_id) }, (error, count) => { diff --git a/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js b/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js index 9eaf86e85e..4a06e086e5 100644 --- a/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js @@ -24,13 +24,13 @@ const TrackChangesApp = require('./helpers/TrackChangesApp') const TrackChangesClient = require('./helpers/TrackChangesClient') const MockWebApi = require('./helpers/MockWebApi') -describe('Flushing updates', function() { - before(function(done) { +describe('Flushing updates', function () { + before(function (done) { return TrackChangesApp.ensureRunning(done) }) - describe("flushing a doc's updates", function() { - before(function(done) { + describe("flushing a doc's updates", function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -46,14 +46,14 @@ describe('Flushing updates', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } return TrackChangesClient.flushDoc( this.project_id, this.doc_id, - error => { + (error) => { if (error != null) { throw error } @@ -65,7 +65,7 @@ describe('Flushing updates', function() { return null }) - return it('should flush the op into mongo', function(done) { + return it('should flush the op into mongo', function (done) { TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => { expect(updates[0].pack[0].op).to.deep.equal([ { @@ -79,9 +79,9 @@ describe('Flushing updates', function() { }) }) - return describe("flushing a project's updates", function() { - describe('with versioning enabled', function() { - before(function(done) { + return describe("flushing a project's updates", function () { + describe('with versioning enabled', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -109,11 +109,11 @@ describe('Flushing updates', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } - return TrackChangesClient.flushProject(this.project_id, error => { + return TrackChangesClient.flushProject(this.project_id, (error) => { if (error != null) { throw error } @@ -124,7 +124,7 @@ describe('Flushing updates', function() { return null }) - it('should not mark the updates for deletion', function(done) { + it('should not mark the updates for deletion', function (done) { TrackChangesClient.getCompressedUpdates( this.doc_id, (error, updates) => { @@ -135,7 +135,7 @@ describe('Flushing updates', function() { return null }) - return it('should preserve history forever', function(done) { + return it('should preserve history forever', function (done) { TrackChangesClient.getProjectMetaData( this.project_id, (error, project) => { @@ -147,8 +147,8 @@ describe('Flushing updates', function() { }) }) - describe('without versioning enabled', function() { - before(function(done) { + describe('without versioning enabled', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -176,11 +176,11 @@ describe('Flushing updates', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } - return TrackChangesClient.flushProject(this.project_id, error => { + return TrackChangesClient.flushProject(this.project_id, (error) => { if (error != null) { throw error } @@ -191,7 +191,7 @@ describe('Flushing updates', function() { return null }) - return it('should mark the updates for deletion', function(done) { + return it('should mark the updates for deletion', function (done) { TrackChangesClient.getCompressedUpdates( this.doc_id, (error, updates) => { @@ -203,8 +203,8 @@ describe('Flushing updates', function() { }) }) - return describe('without versioning enabled but with preserveHistory set to true', function() { - before(function(done) { + return describe('without versioning enabled but with preserveHistory set to true', function () { + before(function (done) { this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() this.user_id = ObjectId().toString() @@ -219,7 +219,7 @@ describe('Flushing updates', function() { TrackChangesClient.setPreserveHistoryForProject( this.project_id, - error => { + (error) => { if (error != null) { throw error } @@ -241,13 +241,13 @@ describe('Flushing updates', function() { v: 3 } ], - error => { + (error) => { if (error != null) { throw error } return TrackChangesClient.flushProject( this.project_id, - error => { + (error) => { if (error != null) { throw error } @@ -261,7 +261,7 @@ describe('Flushing updates', function() { return null }) - return it('should not mark the updates for deletion', function(done) { + return it('should not mark the updates for deletion', function (done) { TrackChangesClient.getCompressedUpdates( this.doc_id, (error, updates) => { diff --git a/services/track-changes/test/acceptance/js/GettingADiffTests.js b/services/track-changes/test/acceptance/js/GettingADiffTests.js index 871258b30d..4830f338d4 100644 --- a/services/track-changes/test/acceptance/js/GettingADiffTests.js +++ b/services/track-changes/test/acceptance/js/GettingADiffTests.js @@ -23,8 +23,8 @@ const TrackChangesClient = require('./helpers/TrackChangesClient') const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi') const MockWebApi = require('./helpers/MockWebApi') -describe('Getting a diff', function() { - beforeEach(function(done) { +describe('Getting a diff', function () { + beforeEach(function (done) { sinon.spy(MockDocUpdaterApi, 'getDoc') this.now = Date.now() @@ -89,7 +89,7 @@ describe('Getting a diff', function() { this.project_id, this.doc_id, this.updates, - error => { + (error) => { if (error != null) { throw error } @@ -112,17 +112,17 @@ describe('Getting a diff', function() { return null }) - afterEach(function() { + afterEach(function () { MockDocUpdaterApi.getDoc.restore() MockWebApi.getUserInfo.restore() return null }) - it('should return the diff', function() { + it('should return the diff', function () { return expect(this.diff).to.deep.equal(this.expected_diff) }) - return it('should get the doc from the doc updater', function() { + return it('should get the doc from the doc updater', function () { MockDocUpdaterApi.getDoc .calledWith(this.project_id, this.doc_id) .should.equal(true) diff --git a/services/track-changes/test/acceptance/js/GettingUpdatesTests.js b/services/track-changes/test/acceptance/js/GettingUpdatesTests.js index d9cd43f1f8..052cb405e7 100644 --- a/services/track-changes/test/acceptance/js/GettingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/GettingUpdatesTests.js @@ -23,8 +23,8 @@ const TrackChangesApp = require('./helpers/TrackChangesApp') const TrackChangesClient = require('./helpers/TrackChangesClient') const MockWebApi = require('./helpers/MockWebApi') -describe('Getting updates', function() { - before(function(done) { +describe('Getting updates', function () { + before(function (done) { this.now = Date.now() this.to = this.now this.user_id = ObjectId().toString() @@ -72,7 +72,7 @@ describe('Getting updates', function() { this.project_id, this.doc_id, this.updates, - error => { + (error) => { if (error != null) { throw error } @@ -82,7 +82,6 @@ describe('Getting updates', function() { }) return null }) - ;({ after() { MockWebApi.getUserInfo.restore() @@ -90,8 +89,8 @@ describe('Getting updates', function() { } }) - describe('getting updates up to the limit', function() { - before(function(done) { + describe('getting updates up to the limit', function () { + before(function (done) { TrackChangesClient.getUpdates( this.project_id, { before: this.to + 1, min_count: 3 }, @@ -106,11 +105,11 @@ describe('Getting updates', function() { return null }) - it('should fetch the user details from the web api', function() { + it('should fetch the user details from the web api', function () { return MockWebApi.getUserInfo.calledWith(this.user_id).should.equal(true) }) - return it('should return at least the min_count number of summarized updates', function() { + return it('should return at least the min_count number of summarized updates', function () { const docs1 = {} docs1[this.doc_id] = { toV: 20, fromV: 19 } const docs2 = {} @@ -146,8 +145,8 @@ describe('Getting updates', function() { }) }) - return describe('getting updates beyond the end of the database', function() { - before(function(done) { + return describe('getting updates beyond the end of the database', function () { + before(function (done) { TrackChangesClient.getUpdates( this.project_id, { before: this.to - 8 * this.hours + 1, min_count: 30 }, @@ -162,7 +161,7 @@ describe('Getting updates', function() { return null }) - return it('should return as many updates as it can', function() { + return it('should return as many updates as it can', function () { const docs1 = {} docs1[this.doc_id] = { toV: 4, fromV: 3 } const docs2 = {} diff --git a/services/track-changes/test/acceptance/js/LockManagerTests.js b/services/track-changes/test/acceptance/js/LockManagerTests.js index ad5352ae44..484d1a9bc6 100644 --- a/services/track-changes/test/acceptance/js/LockManagerTests.js +++ b/services/track-changes/test/acceptance/js/LockManagerTests.js @@ -20,42 +20,42 @@ const LockManager = require('../../../app/js/LockManager') const rclient = require('redis').createClient(Settings.redis.history) // Only works locally for now const TrackChangesApp = require('./helpers/TrackChangesApp') -describe('Locking document', function() { - before(function(done) { +describe('Locking document', function () { + before(function (done) { TrackChangesApp.ensureRunning(done) return null }) - return describe('when the lock has expired in redis', function() { - before(function(done) { + return describe('when the lock has expired in redis', function () { + before(function (done) { LockManager.LOCK_TTL = 1 // second LockManager.runWithLock( 'doc123', - releaseA => { + (releaseA) => { // we create a lock A and allow it to expire in redis return setTimeout( () => // now we create a new lock B and try to release A LockManager.runWithLock( 'doc123', - releaseB => { + (releaseB) => { return releaseA() }, // try to release lock A to see if it wipes out lock B - error => {} + (error) => {} ), // we never release lock B so nothing should happen here 1500 ) }, // enough time to wait until the lock has expired - error => + (error) => // we get here after trying to release lock A done() ) return null }) - return it('the new lock should not be removed by the expired locker', function(done) { + return it('the new lock should not be removed by the expired locker', function (done) { LockManager.checkLock('doc123', (err, isFree) => { expect(isFree).to.equal(false) return done() diff --git a/services/track-changes/test/acceptance/js/RestoringVersions.js b/services/track-changes/test/acceptance/js/RestoringVersions.js index bfa55e8ba2..8afef4b168 100644 --- a/services/track-changes/test/acceptance/js/RestoringVersions.js +++ b/services/track-changes/test/acceptance/js/RestoringVersions.js @@ -23,8 +23,8 @@ const TrackChangesClient = require('./helpers/TrackChangesClient') const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi') const MockWebApi = require('./helpers/MockWebApi') -describe('Restoring a version', function() { - before(function(done) { +describe('Restoring a version', function () { + before(function (done) { sinon.spy(MockDocUpdaterApi, 'setDoc') this.now = Date.now() @@ -78,7 +78,7 @@ describe('Restoring a version', function() { this.project_id, this.doc_id, this.updates, - error => { + (error) => { if (error != null) { throw error } @@ -87,7 +87,7 @@ describe('Restoring a version', function() { this.doc_id, this.beforeVersion, this.user_id, - error => { + (error) => { if (error != null) { throw error } @@ -100,12 +100,12 @@ describe('Restoring a version', function() { return null }) - after(function() { + after(function () { MockDocUpdaterApi.setDoc.restore() return null }) - return it('should set the doc in the doc updater', function() { + return it('should set the doc in the doc updater', function () { MockDocUpdaterApi.setDoc .calledWith( this.project_id, diff --git a/services/track-changes/test/acceptance/js/helpers/MockDocStoreApi.js b/services/track-changes/test/acceptance/js/helpers/MockDocStoreApi.js index ef912948eb..b1ebcf9cef 100644 --- a/services/track-changes/test/acceptance/js/helpers/MockDocStoreApi.js +++ b/services/track-changes/test/acceptance/js/helpers/MockDocStoreApi.js @@ -19,7 +19,7 @@ module.exports = MockDocUpdaterApi = { getAllDoc(project_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return callback(null, this.docs) }, @@ -39,12 +39,12 @@ module.exports = MockDocUpdaterApi = { }) return app - .listen(3016, error => { + .listen(3016, (error) => { if (error != null) { throw error } }) - .on('error', error => { + .on('error', (error) => { console.error('error starting MockDocStoreApi:', error.message) return process.exit(1) }) diff --git a/services/track-changes/test/acceptance/js/helpers/MockDocUpdaterApi.js b/services/track-changes/test/acceptance/js/helpers/MockDocUpdaterApi.js index 449bf1e217..b3b5e23ba7 100644 --- a/services/track-changes/test/acceptance/js/helpers/MockDocUpdaterApi.js +++ b/services/track-changes/test/acceptance/js/helpers/MockDocUpdaterApi.js @@ -22,14 +22,14 @@ module.exports = MockDocUpdaterApi = { getDoc(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return callback(null, this.docs[doc_id]) }, setDoc(project_id, doc_id, lines, user_id, undoing, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } if (!this.docs[doc_id]) { this.docs[doc_id] = {} @@ -56,33 +56,30 @@ module.exports = MockDocUpdaterApi = { ) }) - app.post( - '/project/:project_id/doc/:doc_id', - (req, res, next) => { - return this.setDoc( - req.params.project_id, - req.params.doc_id, - req.body.lines, - req.body.user_id, - req.body.undoing, - (errr, doc) => { - if (typeof error !== 'undefined' && error !== null) { - return res.sendStatus(500) - } else { - return res.sendStatus(204) - } + app.post('/project/:project_id/doc/:doc_id', (req, res, next) => { + return this.setDoc( + req.params.project_id, + req.params.doc_id, + req.body.lines, + req.body.user_id, + req.body.undoing, + (errr, doc) => { + if (typeof error !== 'undefined' && error !== null) { + return res.sendStatus(500) + } else { + return res.sendStatus(204) } - ) - } - ) + } + ) + }) return app - .listen(3003, error => { + .listen(3003, (error) => { if (error != null) { throw error } }) - .on('error', error => { + .on('error', (error) => { console.error('error starting MockDocUpdaterApi:', error.message) return process.exit(1) }) diff --git a/services/track-changes/test/acceptance/js/helpers/MockWebApi.js b/services/track-changes/test/acceptance/js/helpers/MockWebApi.js index 45e94db8f8..b7ebbc876f 100644 --- a/services/track-changes/test/acceptance/js/helpers/MockWebApi.js +++ b/services/track-changes/test/acceptance/js/helpers/MockWebApi.js @@ -21,14 +21,14 @@ module.exports = MockWebApi = { getUserInfo(user_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return callback(null, this.users[user_id] || null) }, getProjectDetails(project_id, callback) { if (callback == null) { - callback = function(error, project) {} + callback = function (error, project) {} } return callback(null, this.projects[project_id]) }, @@ -61,12 +61,12 @@ module.exports = MockWebApi = { }) return app - .listen(3000, error => { + .listen(3000, (error) => { if (error != null) { throw error } }) - .on('error', error => { + .on('error', (error) => { console.error('error starting MockWebApiServer:', error.message) return process.exit(1) }) diff --git a/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js b/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js index 1ce662548e..81efb5c912 100644 --- a/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js +++ b/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js @@ -23,7 +23,7 @@ module.exports = { callbacks: [], ensureRunning(callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } if (this.running) { return callback() @@ -37,10 +37,10 @@ module.exports = { Settings.internal != null ? Settings.internal.trackchanges : undefined, - x => x.port + (x) => x.port ), 'localhost', - error => { + (error) => { if (error != null) { throw error } diff --git a/services/track-changes/test/acceptance/js/helpers/TrackChangesClient.js b/services/track-changes/test/acceptance/js/helpers/TrackChangesClient.js index d49980976b..cca55a87aa 100644 --- a/services/track-changes/test/acceptance/js/helpers/TrackChangesClient.js +++ b/services/track-changes/test/acceptance/js/helpers/TrackChangesClient.js @@ -33,9 +33,9 @@ const S3_BUCKET = Settings.trackchanges.stores.doc_history module.exports = TrackChangesClient = { flushAndGetCompressedUpdates(project_id, doc_id, callback) { if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } - return TrackChangesClient.flushDoc(project_id, doc_id, error => { + return TrackChangesClient.flushDoc(project_id, doc_id, (error) => { if (error != null) { return callback(error) } @@ -45,7 +45,7 @@ module.exports = TrackChangesClient = { flushDoc(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return request.post( { @@ -60,7 +60,7 @@ module.exports = TrackChangesClient = { flushProject(project_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return request.post( { @@ -75,7 +75,7 @@ module.exports = TrackChangesClient = { getCompressedUpdates(doc_id, callback) { if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } return db.docHistory .find({ doc_id: ObjectId(doc_id) }) @@ -85,7 +85,7 @@ module.exports = TrackChangesClient = { getProjectMetaData(project_id, callback) { if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } return db.projectHistoryMetaData.find( { @@ -97,7 +97,7 @@ module.exports = TrackChangesClient = { setPreserveHistoryForProject(project_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return db.projectHistoryMetaData.update( { @@ -115,18 +115,18 @@ module.exports = TrackChangesClient = { pushRawUpdates(project_id, doc_id, updates, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return rclient.sadd( Keys.docsWithHistoryOps({ project_id }), doc_id, - error => { + (error) => { if (error != null) { return callback(error) } return rclient.rpush( Keys.uncompressedHistoryOps({ doc_id }), - ...Array.from(Array.from(updates).map(u => JSON.stringify(u))), + ...Array.from(Array.from(updates).map((u) => JSON.stringify(u))), callback ) } @@ -135,7 +135,7 @@ module.exports = TrackChangesClient = { getDiff(project_id, doc_id, from, to, callback) { if (callback == null) { - callback = function(error, diff) {} + callback = function (error, diff) {} } return request.get( { @@ -150,7 +150,7 @@ module.exports = TrackChangesClient = { getUpdates(project_id, options, callback) { if (callback == null) { - callback = function(error, body) {} + callback = function (error, body) {} } return request.get( { @@ -165,7 +165,7 @@ module.exports = TrackChangesClient = { restoreDoc(project_id, doc_id, version, user_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return request.post( { @@ -183,7 +183,7 @@ module.exports = TrackChangesClient = { pushDocHistory(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return request.post( { @@ -198,7 +198,7 @@ module.exports = TrackChangesClient = { pullDocHistory(project_id, doc_id, callback) { if (callback == null) { - callback = function(error) {} + callback = function (error) {} } return request.post( { @@ -237,7 +237,7 @@ module.exports = TrackChangesClient = { getS3Doc(project_id, doc_id, pack_id, callback) { if (callback == null) { - callback = function(error, body) {} + callback = function (error, body) {} } const params = { Bucket: S3_BUCKET, @@ -263,7 +263,7 @@ module.exports = TrackChangesClient = { removeS3Doc(project_id, doc_id, callback) { if (callback == null) { - callback = function(error, res, body) {} + callback = function (error, res, body) {} } let params = { Bucket: S3_BUCKET, @@ -278,7 +278,7 @@ module.exports = TrackChangesClient = { params = { Bucket: S3_BUCKET, Delete: { - Objects: data.Contents.map(s3object => ({ Key: s3object.Key })) + Objects: data.Contents.map((s3object) => ({ Key: s3object.Key })) } } diff --git a/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js b/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js index b84775ddea..6526c9445d 100644 --- a/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js +++ b/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js @@ -17,8 +17,8 @@ const { expect } = chai const modulePath = '../../../../app/js/DiffGenerator.js' const SandboxedModule = require('sandboxed-module') -describe('DiffGenerator', function() { - beforeEach(function() { +describe('DiffGenerator', function () { + beforeEach(function () { this.DiffGenerator = SandboxedModule.require(modulePath, { requires: { 'logger-sharelatex': { warn: sinon.stub() } @@ -34,9 +34,9 @@ describe('DiffGenerator', function() { }) }) - describe('rewindOp', function() { - describe('rewinding an insert', function() { - return it('should undo the insert', function() { + describe('rewindOp', function () { + describe('rewinding an insert', function () { + return it('should undo the insert', function () { const content = 'hello world' const rewoundContent = this.DiffGenerator.rewindOp(content, { p: 6, @@ -46,8 +46,8 @@ describe('DiffGenerator', function() { }) }) - describe('rewinding a delete', function() { - return it('should undo the delete', function() { + describe('rewinding a delete', function () { + return it('should undo the delete', function () { const content = 'hello rld' const rewoundContent = this.DiffGenerator.rewindOp(content, { p: 6, @@ -57,8 +57,8 @@ describe('DiffGenerator', function() { }) }) - describe('with an inconsistent update', function() { - return it('should throw an error', function() { + describe('with an inconsistent update', function () { + return it('should throw an error', function () { const content = 'hello world' return expect(() => { return this.DiffGenerator.rewindOp(content, { p: 6, i: 'foo' }) @@ -66,8 +66,8 @@ describe('DiffGenerator', function() { }) }) - return describe('with an update which is beyond the length of the content', function() { - return it('should undo the insert as if it were at the end of the content', function() { + return describe('with an update which is beyond the length of the content', function () { + return it('should undo the insert as if it were at the end of the content', function () { const content = 'foobar' const rewoundContent = this.DiffGenerator.rewindOp(content, { p: 4, @@ -78,8 +78,8 @@ describe('DiffGenerator', function() { }) }) - describe('rewindUpdate', function() { - return it('should rewind ops in reverse', function() { + describe('rewindUpdate', function () { + return it('should rewind ops in reverse', function () { const content = 'aaabbbccc' const update = { op: [ @@ -92,8 +92,8 @@ describe('DiffGenerator', function() { }) }) - describe('rewindUpdates', function() { - return it('should rewind updates in reverse', function() { + describe('rewindUpdates', function () { + return it('should rewind updates in reverse', function () { const content = 'aaabbbccc' const updates = [ { op: [{ p: 3, i: 'bbb' }] }, @@ -104,8 +104,8 @@ describe('DiffGenerator', function() { }) }) - describe('buildDiff', function() { - beforeEach(function() { + describe('buildDiff', function () { + beforeEach(function () { this.diff = [{ u: 'mock-diff' }] this.content = 'Hello world' this.updates = [ @@ -121,11 +121,11 @@ describe('DiffGenerator', function() { )) }) - it('should return the diff', function() { + it('should return the diff', function () { return this.result.should.deep.equal(this.diff) }) - it('should build the content into an initial diff', function() { + it('should build the content into an initial diff', function () { return this.DiffGenerator.applyUpdateToDiff .calledWith( [ @@ -138,24 +138,24 @@ describe('DiffGenerator', function() { .should.equal(true) }) - it('should apply each update', function() { - return Array.from(this.updates).map(update => + it('should apply each update', function () { + return Array.from(this.updates).map((update) => this.DiffGenerator.applyUpdateToDiff .calledWith(sinon.match.any, update) .should.equal(true) ) }) - return it('should compress the diff', function() { + return it('should compress the diff', function () { return this.DiffGenerator.compressDiff .calledWith(this.diff) .should.equal(true) }) }) - describe('compressDiff', function() { - describe('with adjacent inserts with the same user_id', function() { - return it('should create one update with combined meta data and min/max timestamps', function() { + describe('compressDiff', function () { + describe('with adjacent inserts with the same user_id', function () { + return it('should create one update with combined meta data and min/max timestamps', function () { const diff = this.DiffGenerator.compressDiff([ { i: 'foo', @@ -175,8 +175,8 @@ describe('DiffGenerator', function() { }) }) - describe('with adjacent inserts with different user_ids', function() { - return it('should leave the inserts unchanged', function() { + describe('with adjacent inserts with different user_ids', function () { + return it('should leave the inserts unchanged', function () { const input = [ { i: 'foo', @@ -192,8 +192,8 @@ describe('DiffGenerator', function() { }) }) - describe('with adjacent deletes with the same user_id', function() { - return it('should create one update with combined meta data and min/max timestamps', function() { + describe('with adjacent deletes with the same user_id', function () { + return it('should create one update with combined meta data and min/max timestamps', function () { const diff = this.DiffGenerator.compressDiff([ { d: 'foo', @@ -213,8 +213,8 @@ describe('DiffGenerator', function() { }) }) - return describe('with adjacent deletes with different user_ids', function() { - return it('should leave the deletes unchanged', function() { + return describe('with adjacent deletes with different user_ids', function () { + return it('should leave the deletes unchanged', function () { const input = [ { d: 'foo', @@ -231,9 +231,9 @@ describe('DiffGenerator', function() { }) }) - return describe('applyUpdateToDiff', function() { - describe('an insert', function() { - it('should insert into the middle of (u)nchanged text', function() { + return describe('applyUpdateToDiff', function () { + describe('an insert', function () { + it('should insert into the middle of (u)nchanged text', function () { const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], { op: [{ p: 3, i: 'baz' }], meta: this.meta @@ -245,7 +245,7 @@ describe('DiffGenerator', function() { ]) }) - it('should insert into the start of (u)changed text', function() { + it('should insert into the start of (u)changed text', function () { const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], { op: [{ p: 0, i: 'baz' }], meta: this.meta @@ -256,7 +256,7 @@ describe('DiffGenerator', function() { ]) }) - it('should insert into the end of (u)changed text', function() { + it('should insert into the end of (u)changed text', function () { const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], { op: [{ p: 6, i: 'baz' }], meta: this.meta @@ -267,7 +267,7 @@ describe('DiffGenerator', function() { ]) }) - it('should insert into the middle of (i)inserted text', function() { + it('should insert into the middle of (i)inserted text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ i: 'foobar', meta: this.meta }], { op: [{ p: 3, i: 'baz' }], meta: this.meta } @@ -279,7 +279,7 @@ describe('DiffGenerator', function() { ]) }) - return it('should not count deletes in the running length total', function() { + return it('should not count deletes in the running length total', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ d: 'deleted', meta: this.meta }, { u: 'foobar' }], { op: [{ p: 3, i: 'baz' }], meta: this.meta } @@ -293,9 +293,9 @@ describe('DiffGenerator', function() { }) }) - return describe('a delete', function() { - describe('deleting unchanged text', function() { - it('should delete from the middle of (u)nchanged text', function() { + return describe('a delete', function () { + describe('deleting unchanged text', function () { + it('should delete from the middle of (u)nchanged text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foobazbar' }], { op: [{ p: 3, d: 'baz' }], meta: this.meta } @@ -307,7 +307,7 @@ describe('DiffGenerator', function() { ]) }) - it('should delete from the start of (u)nchanged text', function() { + it('should delete from the start of (u)nchanged text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foobazbar' }], { op: [{ p: 0, d: 'foo' }], meta: this.meta } @@ -318,7 +318,7 @@ describe('DiffGenerator', function() { ]) }) - it('should delete from the end of (u)nchanged text', function() { + it('should delete from the end of (u)nchanged text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foobazbar' }], { op: [{ p: 6, d: 'bar' }], meta: this.meta } @@ -329,7 +329,7 @@ describe('DiffGenerator', function() { ]) }) - return it('should delete across multiple (u)changed text parts', function() { + return it('should delete across multiple (u)changed text parts', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foo' }, { u: 'baz' }, { u: 'bar' }], { op: [{ p: 2, d: 'obazb' }], meta: this.meta } @@ -344,8 +344,8 @@ describe('DiffGenerator', function() { }) }) - describe('deleting inserts', function() { - it('should delete from the middle of (i)nserted text', function() { + describe('deleting inserts', function () { + it('should delete from the middle of (i)nserted text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ i: 'foobazbar', meta: this.meta }], { op: [{ p: 3, d: 'baz' }], meta: this.meta } @@ -356,7 +356,7 @@ describe('DiffGenerator', function() { ]) }) - it('should delete from the start of (u)nchanged text', function() { + it('should delete from the start of (u)nchanged text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ i: 'foobazbar', meta: this.meta }], { op: [{ p: 0, d: 'foo' }], meta: this.meta } @@ -364,7 +364,7 @@ describe('DiffGenerator', function() { return expect(diff).to.deep.equal([{ i: 'bazbar', meta: this.meta }]) }) - it('should delete from the end of (u)nchanged text', function() { + it('should delete from the end of (u)nchanged text', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ i: 'foobazbar', meta: this.meta }], { op: [{ p: 6, d: 'bar' }], meta: this.meta } @@ -372,7 +372,7 @@ describe('DiffGenerator', function() { return expect(diff).to.deep.equal([{ i: 'foobaz', meta: this.meta }]) }) - return it('should delete across multiple (u)changed and (i)nserted text parts', function() { + return it('should delete across multiple (u)changed and (i)nserted text parts', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foo' }, { i: 'baz', meta: this.meta }, { u: 'bar' }], { op: [{ p: 2, d: 'obazb' }], meta: this.meta } @@ -386,8 +386,8 @@ describe('DiffGenerator', function() { }) }) - describe('deleting over existing deletes', function() { - return it('should delete across multiple (u)changed and (d)deleted text parts', function() { + describe('deleting over existing deletes', function () { + return it('should delete across multiple (u)changed and (d)deleted text parts', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foo' }, { d: 'baz', meta: this.meta }, { u: 'bar' }], { op: [{ p: 2, d: 'ob' }], meta: this.meta } @@ -402,8 +402,8 @@ describe('DiffGenerator', function() { }) }) - describe("deleting when the text doesn't match", function() { - it('should throw an error when deleting from the middle of (u)nchanged text', function() { + describe("deleting when the text doesn't match", function () { + it('should throw an error when deleting from the middle of (u)nchanged text', function () { return expect(() => this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], { op: [{ p: 3, d: 'xxx' }], @@ -412,7 +412,7 @@ describe('DiffGenerator', function() { ).to.throw(this.DiffGenerator.ConsistencyError) }) - it('should throw an error when deleting from the start of (u)nchanged text', function() { + it('should throw an error when deleting from the start of (u)nchanged text', function () { return expect(() => this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], { op: [{ p: 0, d: 'xxx' }], @@ -421,7 +421,7 @@ describe('DiffGenerator', function() { ).to.throw(this.DiffGenerator.ConsistencyError) }) - return it('should throw an error when deleting from the end of (u)nchanged text', function() { + return it('should throw an error when deleting from the end of (u)nchanged text', function () { return expect(() => this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], { op: [{ p: 6, d: 'xxx' }], @@ -431,8 +431,8 @@ describe('DiffGenerator', function() { }) }) - describe('when the last update in the existing diff is a delete', function() { - return it('should insert the new update before the delete', function() { + describe('when the last update in the existing diff is a delete', function () { + return it('should insert the new update before the delete', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ u: 'foo' }, { d: 'bar', meta: this.meta }], { op: [{ p: 3, i: 'baz' }], meta: this.meta } @@ -445,8 +445,8 @@ describe('DiffGenerator', function() { }) }) - return describe('when the only update in the existing diff is a delete', function() { - return it('should insert the new update after the delete', function() { + return describe('when the only update in the existing diff is a delete', function () { + return it('should insert the new update after the delete', function () { const diff = this.DiffGenerator.applyUpdateToDiff( [{ d: 'bar', meta: this.meta }], { op: [{ p: 0, i: 'baz' }], meta: this.meta } diff --git a/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js b/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js index bee618badf..7b72f3a002 100644 --- a/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js +++ b/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js @@ -17,8 +17,8 @@ const { expect } = chai const modulePath = '../../../../app/js/DiffManager.js' const SandboxedModule = require('sandboxed-module') -describe('DiffManager', function() { - beforeEach(function() { +describe('DiffManager', function () { + beforeEach(function () { this.DiffManager = SandboxedModule.require(modulePath, { requires: { 'logger-sharelatex': (this.logger = { @@ -38,8 +38,8 @@ describe('DiffManager', function() { return (this.doc_id = 'mock-doc-id') }) - describe('getLatestDocAndUpdates', function() { - beforeEach(function() { + describe('getLatestDocAndUpdates', function () { + beforeEach(function () { this.content = 'hello world' this.version = 42 this.updates = ['mock-update-1', 'mock-update-2'] @@ -52,8 +52,8 @@ describe('DiffManager', function() { .callsArgWith(3, null, this.updates)) }) - describe('with a fromVersion', function() { - beforeEach(function() { + describe('with a fromVersion', function () { + beforeEach(function () { return this.DiffManager.getLatestDocAndUpdates( this.project_id, this.doc_id, @@ -62,27 +62,27 @@ describe('DiffManager', function() { ) }) - it('should get the latest version of the doc', function() { + it('should get the latest version of the doc', function () { return this.DocumentUpdaterManager.getDocument .calledWith(this.project_id, this.doc_id) .should.equal(true) }) - it('should get the latest updates', function() { + it('should get the latest updates', function () { return this.UpdatesManager.getDocUpdatesWithUserInfo .calledWith(this.project_id, this.doc_id, { from: this.from }) .should.equal(true) }) - return it('should call the callback with the content, version and updates', function() { + return it('should call the callback with the content, version and updates', function () { return this.callback .calledWith(null, this.content, this.version, this.updates) .should.equal(true) }) }) - return describe('with no fromVersion', function() { - beforeEach(function() { + return describe('with no fromVersion', function () { + beforeEach(function () { return this.DiffManager.getLatestDocAndUpdates( this.project_id, this.doc_id, @@ -91,19 +91,19 @@ describe('DiffManager', function() { ) }) - it('should get the latest version of the doc', function() { + it('should get the latest version of the doc', function () { return this.DocumentUpdaterManager.getDocument .calledWith(this.project_id, this.doc_id) .should.equal(true) }) - it('should not get the latest updates', function() { + it('should not get the latest updates', function () { return this.UpdatesManager.getDocUpdatesWithUserInfo.called.should.equal( false ) }) - return it('should call the callback with the content, version and blank updates', function() { + return it('should call the callback with the content, version and blank updates', function () { return this.callback .calledWith(null, this.content, this.version, []) .should.equal(true) @@ -111,8 +111,8 @@ describe('DiffManager', function() { }) }) - describe('getDiff', function() { - beforeEach(function() { + describe('getDiff', function () { + beforeEach(function () { this.content = 'hello world' // Op versions are the version they were applied to, so doc is always one version // ahead.s @@ -146,8 +146,8 @@ describe('DiffManager', function() { return (this.diff = [{ u: 'mock-diff' }]) }) - describe('with matching versions', function() { - beforeEach(function() { + describe('with matching versions', function () { + beforeEach(function () { this.DiffManager.getDocumentBeforeVersion = sinon .stub() .callsArgWith(3, null, this.rewound_content, this.updates) @@ -161,13 +161,13 @@ describe('DiffManager', function() { ) }) - it('should get the latest doc and version with all recent updates', function() { + it('should get the latest doc and version with all recent updates', function () { return this.DiffManager.getDocumentBeforeVersion .calledWith(this.project_id, this.doc_id, this.fromVersion) .should.equal(true) }) - it('should generate the diff', function() { + it('should generate the diff', function () { return this.DiffGenerator.buildDiff .calledWith( this.rewound_content, @@ -176,21 +176,20 @@ describe('DiffManager', function() { .should.equal(true) }) - return it('should call the callback with the diff', function() { + return it('should call the callback with the diff', function () { return this.callback.calledWith(null, this.diff).should.equal(true) }) }) - describe('when the updates are inconsistent', function() { - beforeEach(function() { + describe('when the updates are inconsistent', function () { + beforeEach(function () { this.DiffManager.getLatestDocAndUpdates = sinon .stub() .callsArgWith(3, null, this.content, this.version, this.updates) this.DiffGenerator.buildDiff = sinon .stub() .throws((this.error = new Error('inconsistent!'))) - this.DiffGenerator.rewindUpdates = sinon - .stub() + this.DiffGenerator.rewindUpdates = sinon.stub() this.DiffManager.getDiff( this.project_id, this.doc_id, @@ -200,7 +199,7 @@ describe('DiffManager', function() { ) }) - it('should call the callback with an error', function() { + it('should call the callback with an error', function () { this.callback.calledWith(sinon.match(Error)).should.equal(true) const errorObj = this.callback.args[0][0] expect(errorObj.message).to.include('inconsistent!') @@ -208,15 +207,15 @@ describe('DiffManager', function() { }) }) - describe('getDocumentBeforeVersion', function() { - beforeEach(function() { + describe('getDocumentBeforeVersion', function () { + beforeEach(function () { this.DiffManager._tryGetDocumentBeforeVersion = sinon.stub() this.document = 'mock-documents' return (this.rewound_updates = 'mock-rewound-updates') }) - describe('succesfully', function() { - beforeEach(function() { + describe('succesfully', function () { + beforeEach(function () { this.DiffManager._tryGetDocumentBeforeVersion.yields( null, this.document, @@ -230,21 +229,21 @@ describe('DiffManager', function() { ) }) - it('should call _tryGetDocumentBeforeVersion', function() { + it('should call _tryGetDocumentBeforeVersion', function () { return this.DiffManager._tryGetDocumentBeforeVersion .calledWith(this.project_id, this.doc_id, this.version) .should.equal(true) }) - return it('should call the callback with the response', function() { + return it('should call the callback with the response', function () { return this.callback .calledWith(null, this.document, this.rewound_updates) .should.equal(true) }) }) - describe('with a retry needed', function() { - beforeEach(function() { + describe('with a retry needed', function () { + beforeEach(function () { let retried = false this.DiffManager._tryGetDocumentBeforeVersion = ( project_id, @@ -270,21 +269,21 @@ describe('DiffManager', function() { ) }) - it('should call _tryGetDocumentBeforeVersion twice', function() { + it('should call _tryGetDocumentBeforeVersion twice', function () { return this.DiffManager._tryGetDocumentBeforeVersion.calledTwice.should.equal( true ) }) - return it('should call the callback with the response', function() { + return it('should call the callback with the response', function () { return this.callback .calledWith(null, this.document, this.rewound_updates) .should.equal(true) }) }) - describe('with a non-retriable error', function() { - beforeEach(function() { + describe('with a non-retriable error', function () { + beforeEach(function () { this.error = new Error('oops') this.DiffManager._tryGetDocumentBeforeVersion.yields(this.error) return this.DiffManager.getDocumentBeforeVersion( @@ -295,19 +294,19 @@ describe('DiffManager', function() { ) }) - it('should call _tryGetDocumentBeforeVersion once', function() { + it('should call _tryGetDocumentBeforeVersion once', function () { return this.DiffManager._tryGetDocumentBeforeVersion.calledOnce.should.equal( true ) }) - return it('should call the callback with the error', function() { + return it('should call the callback with the error', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) - return describe('when retry limit is matched', function() { - beforeEach(function() { + return describe('when retry limit is matched', function () { + beforeEach(function () { this.error = new Error('oops') this.error.retry = true this.DiffManager._tryGetDocumentBeforeVersion.yields(this.error) @@ -319,20 +318,20 @@ describe('DiffManager', function() { ) }) - it('should call _tryGetDocumentBeforeVersion three times (max retries)', function() { + it('should call _tryGetDocumentBeforeVersion three times (max retries)', function () { return this.DiffManager._tryGetDocumentBeforeVersion.calledThrice.should.equal( true ) }) - return it('should call the callback with the error', function() { + return it('should call the callback with the error', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) }) - return describe('_tryGetDocumentBeforeVersion', function() { - beforeEach(function() { + return describe('_tryGetDocumentBeforeVersion', function () { + beforeEach(function () { this.content = 'hello world' // Op versions are the version they were applied to, so doc is always one version // ahead.s @@ -364,8 +363,8 @@ describe('DiffManager', function() { return (this.diff = [{ u: 'mock-diff' }]) }) - describe('with matching versions', function() { - beforeEach(function() { + describe('with matching versions', function () { + beforeEach(function () { this.DiffManager.getLatestDocAndUpdates = sinon .stub() .callsArgWith(3, null, this.content, this.version, this.updates) @@ -386,25 +385,25 @@ describe('DiffManager', function() { ) }) - it('should get the latest doc and version with all recent updates', function() { + it('should get the latest doc and version with all recent updates', function () { return this.DiffManager.getLatestDocAndUpdates .calledWith(this.project_id, this.doc_id, this.fromVersion) .should.equal(true) }) - it('should rewind the diff', function() { + it('should rewind the diff', function () { return sinon.assert.calledOnce(this.rewindUpdatesWithArgs) }) - return it('should call the callback with the rewound document and updates', function() { + return it('should call the callback with the rewound document and updates', function () { return this.callback .calledWith(null, this.rewound_content, this.updates) .should.equal(true) }) }) - describe('with mismatching versions', function() { - beforeEach(function() { + describe('with mismatching versions', function () { + beforeEach(function () { this.version = 50 this.updates = [ { op: 'mock-1', v: 40 }, @@ -421,15 +420,15 @@ describe('DiffManager', function() { ) }) - return it('should call the callback with an error with retry = true set', function() { + return it('should call the callback with an error with retry = true set', function () { this.callback.calledOnce.should.equal(true) const error = this.callback.args[0][0] return expect(error.retry).to.equal(true) }) }) - return describe('when the updates are inconsistent', function() { - beforeEach(function() { + return describe('when the updates are inconsistent', function () { + beforeEach(function () { this.DiffManager.getLatestDocAndUpdates = sinon .stub() .callsArgWith(3, null, this.content, this.version, this.updates) @@ -444,7 +443,7 @@ describe('DiffManager', function() { ) }) - return it('should call the callback with an error', function() { + return it('should call the callback with an error', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/DocArchive/MongoAWS.js b/services/track-changes/test/unit/js/DocArchive/MongoAWS.js index ad0e33ca54..3eec0c1bbe 100644 --- a/services/track-changes/test/unit/js/DocArchive/MongoAWS.js +++ b/services/track-changes/test/unit/js/DocArchive/MongoAWS.js @@ -18,8 +18,8 @@ const { ObjectId } = require('mongojs') const MemoryStream = require('memorystream') const zlib = require('zlib') -describe('MongoAWS', function() { - beforeEach(function() { +describe('MongoAWS', function () { + beforeEach(function () { this.MongoAWS = SandboxedModule.require(modulePath, { singleOnly: true, requires: { @@ -58,8 +58,8 @@ describe('MongoAWS', function() { return (this.callback = sinon.stub()) }) - describe('archivePack', function() { - beforeEach(function(done) { + describe('archivePack', function () { + beforeEach(function (done) { this.awssdk.config = { update: sinon.stub() } this.awssdk.S3 = sinon.stub() this.S3S.WriteStream = () => MemoryStream.createWriteStream() @@ -79,13 +79,13 @@ describe('MongoAWS', function() { ) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - return describe('unArchivePack', function() { - beforeEach(function(done) { + return describe('unArchivePack', function () { + beforeEach(function (done) { return zlib.gzip('{"pack":"123"}', (err, zbuf) => { this.awssdk.config = { update: sinon.stub() } this.awssdk.S3 = sinon.stub() @@ -106,7 +106,7 @@ describe('MongoAWS', function() { }) }) - return it('should call db.docHistory.insert', function() { + return it('should call db.docHistory.insert', function () { return this.db.docHistory.insert.called.should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js b/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js index a1dcaa0ee5..83f4bf04ad 100644 --- a/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js +++ b/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js @@ -16,8 +16,8 @@ const { expect } = chai const modulePath = '../../../../app/js/DocumentUpdaterManager.js' const SandboxedModule = require('sandboxed-module') -describe('DocumentUpdaterManager', function() { - beforeEach(function() { +describe('DocumentUpdaterManager', function () { + beforeEach(function () { this.DocumentUpdaterManager = SandboxedModule.require(modulePath, { requires: { request: (this.request = {}), @@ -35,9 +35,9 @@ describe('DocumentUpdaterManager', function() { return (this.version = 42) }) - describe('getDocument', function() { - describe('successfully', function() { - beforeEach(function() { + describe('getDocument', function () { + describe('successfully', function () { + beforeEach(function () { this.body = JSON.stringify({ lines: this.lines, version: this.version, @@ -53,20 +53,20 @@ describe('DocumentUpdaterManager', function() { ) }) - it('should get the document from the document updater', function() { + it('should get the document from the document updater', function () { const url = `${this.settings.apis.documentupdater.url}/project/${this.project_id}/doc/${this.doc_id}` return this.request.get.calledWith(url).should.equal(true) }) - return it('should call the callback with the content and version', function() { + return it('should call the callback with the content and version', function () { return this.callback .calledWith(null, this.lines.join('\n'), this.version) .should.equal(true) }) }) - describe('when the document updater API returns an error', function() { - beforeEach(function() { + describe('when the document updater API returns an error', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith( @@ -82,13 +82,13 @@ describe('DocumentUpdaterManager', function() { ) }) - return it('should return an error to the callback', function() { + return it('should return an error to the callback', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) - return describe('when the document updater returns a failure error code', function() { - beforeEach(function() { + return describe('when the document updater returns a failure error code', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith(1, null, { statusCode: 500 }, '') @@ -99,7 +99,7 @@ describe('DocumentUpdaterManager', function() { ) }) - return it('should return the callback with an error', function() { + return it('should return the callback with an error', function () { return this.callback .calledWith( sinon.match.has( @@ -112,14 +112,14 @@ describe('DocumentUpdaterManager', function() { }) }) - return describe('setDocument', function() { - beforeEach(function() { + return describe('setDocument', function () { + beforeEach(function () { this.content = 'mock content' return (this.user_id = 'user-id-123') }) - describe('successfully', function() { - beforeEach(function() { + describe('successfully', function () { + beforeEach(function () { this.request.post = sinon .stub() .callsArgWith(1, null, { statusCode: 200 }) @@ -132,7 +132,7 @@ describe('DocumentUpdaterManager', function() { ) }) - it('should set the document in the document updater', function() { + it('should set the document in the document updater', function () { const url = `${this.settings.apis.documentupdater.url}/project/${this.project_id}/doc/${this.doc_id}` return this.request.post .calledWith({ @@ -147,13 +147,13 @@ describe('DocumentUpdaterManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.calledWith(null).should.equal(true) }) }) - describe('when the document updater API returns an error', function() { - beforeEach(function() { + describe('when the document updater API returns an error', function () { + beforeEach(function () { this.request.post = sinon .stub() .callsArgWith( @@ -171,13 +171,13 @@ describe('DocumentUpdaterManager', function() { ) }) - return it('should return an error to the callback', function() { + return it('should return an error to the callback', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) - return describe('when the document updater returns a failure error code', function() { - beforeEach(function() { + return describe('when the document updater returns a failure error code', function () { + beforeEach(function () { this.request.post = sinon .stub() .callsArgWith(1, null, { statusCode: 500 }, '') @@ -190,7 +190,7 @@ describe('DocumentUpdaterManager', function() { ) }) - return it('should return the callback with an error', function() { + return it('should return the callback with an error', function () { return this.callback .calledWith( sinon.match.has( diff --git a/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js b/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js index 52beb5a198..08509f6b28 100644 --- a/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js +++ b/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js @@ -16,8 +16,8 @@ const { expect } = chai const modulePath = '../../../../app/js/HttpController.js' const SandboxedModule = require('sandboxed-module') -describe('HttpController', function() { - beforeEach(function() { +describe('HttpController', function () { + beforeEach(function () { this.HttpController = SandboxedModule.require(modulePath, { singleOnly: true, requires: { @@ -37,8 +37,8 @@ describe('HttpController', function() { return (this.now = Date.now()) }) - describe('flushDoc', function() { - beforeEach(function() { + describe('flushDoc', function () { + beforeEach(function () { this.req = { params: { doc_id: this.doc_id, @@ -52,19 +52,19 @@ describe('HttpController', function() { return this.HttpController.flushDoc(this.req, this.res, this.next) }) - it('should process the updates', function() { + it('should process the updates', function () { return this.UpdatesManager.processUncompressedUpdatesWithLock .calledWith(this.project_id, this.doc_id) .should.equal(true) }) - return it('should return a success code', function() { + return it('should return a success code', function () { return this.res.sendStatus.calledWith(204).should.equal(true) }) }) - describe('flushProject', function() { - beforeEach(function() { + describe('flushProject', function () { + beforeEach(function () { this.req = { params: { project_id: this.project_id @@ -77,19 +77,19 @@ describe('HttpController', function() { return this.HttpController.flushProject(this.req, this.res, this.next) }) - it('should process the updates', function() { + it('should process the updates', function () { return this.UpdatesManager.processUncompressedUpdatesForProject .calledWith(this.project_id) .should.equal(true) }) - return it('should return a success code', function() { + return it('should return a success code', function () { return this.res.sendStatus.calledWith(204).should.equal(true) }) }) - describe('getDiff', function() { - beforeEach(function() { + describe('getDiff', function () { + beforeEach(function () { this.from = 42 this.to = 45 this.req = { @@ -108,7 +108,7 @@ describe('HttpController', function() { return this.HttpController.getDiff(this.req, this.res, this.next) }) - it('should get the diff', function() { + it('should get the diff', function () { return this.DiffManager.getDiff .calledWith( this.project_id, @@ -119,13 +119,13 @@ describe('HttpController', function() { .should.equal(true) }) - return it('should return the diff', function() { + return it('should return the diff', function () { return this.res.json.calledWith({ diff: this.diff }).should.equal(true) }) }) - describe('getUpdates', function() { - beforeEach(function() { + describe('getUpdates', function () { + beforeEach(function () { this.before = Date.now() this.nextBeforeTimestamp = this.before - 100 this.min_count = 10 @@ -146,7 +146,7 @@ describe('HttpController', function() { return this.HttpController.getUpdates(this.req, this.res, this.next) }) - it('should get the updates', function() { + it('should get the updates', function () { return this.UpdatesManager.getSummarizedProjectUpdates .calledWith(this.project_id, { before: this.before, @@ -155,7 +155,7 @@ describe('HttpController', function() { .should.equal(true) }) - return it('should return the formatted updates', function() { + return it('should return the formatted updates', function () { return this.res.json .calledWith({ updates: this.updates, @@ -165,8 +165,8 @@ describe('HttpController', function() { }) }) - return describe('RestoreManager', function() { - beforeEach(function() { + return describe('RestoreManager', function () { + beforeEach(function () { this.version = '42' this.req = { params: { @@ -184,7 +184,7 @@ describe('HttpController', function() { return this.HttpController.restore(this.req, this.res, this.next) }) - it('should restore the document', function() { + it('should restore the document', function () { return this.RestoreManager.restoreToBeforeVersion .calledWith( this.project_id, @@ -195,7 +195,7 @@ describe('HttpController', function() { .should.equal(true) }) - return it('should return a success code', function() { + return it('should return a success code', function () { return this.res.sendStatus.calledWith(204).should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/LockManager/LockManagerTests.js b/services/track-changes/test/unit/js/LockManager/LockManagerTests.js index 9c5a8fdebc..991e5ee2c6 100644 --- a/services/track-changes/test/unit/js/LockManager/LockManagerTests.js +++ b/services/track-changes/test/unit/js/LockManager/LockManagerTests.js @@ -22,8 +22,8 @@ const { expect } = chai const modulePath = '../../../../app/js/LockManager.js' const SandboxedModule = require('sandboxed-module') -describe('LockManager', function() { - beforeEach(function() { +describe('LockManager', function () { + beforeEach(function () { this.Settings = { redis: { lock: {} @@ -45,37 +45,37 @@ describe('LockManager', function() { return (this.callback = sinon.stub()) }) - describe('checkLock', function() { - describe('when the lock is taken', function() { - beforeEach(function() { + describe('checkLock', function () { + describe('when the lock is taken', function () { + beforeEach(function () { this.rclient.exists = sinon.stub().callsArgWith(1, null, '1') return this.LockManager.checkLock(this.key, this.callback) }) - it('should check the lock in redis', function() { + it('should check the lock in redis', function () { return this.rclient.exists.calledWith(this.key).should.equal(true) }) - return it('should return the callback with false', function() { + return it('should return the callback with false', function () { return this.callback.calledWith(null, false).should.equal(true) }) }) - return describe('when the lock is free', function() { - beforeEach(function() { + return describe('when the lock is free', function () { + beforeEach(function () { this.rclient.exists = sinon.stub().callsArgWith(1, null, '0') return this.LockManager.checkLock(this.key, this.callback) }) - return it('should return the callback with true', function() { + return it('should return the callback with true', function () { return this.callback.calledWith(null, true).should.equal(true) }) }) }) - describe('tryLock', function() { - describe('when the lock is taken', function() { - beforeEach(function() { + describe('tryLock', function () { + describe('when the lock is taken', function () { + beforeEach(function () { this.rclient.set = sinon.stub().callsArgWith(5, null, null) this.LockManager.randomLock = sinon .stub() @@ -83,7 +83,7 @@ describe('LockManager', function() { return this.LockManager.tryLock(this.key, this.callback) }) - it('should check the lock in redis', function() { + it('should check the lock in redis', function () { return this.rclient.set .calledWith( this.key, @@ -95,43 +95,43 @@ describe('LockManager', function() { .should.equal(true) }) - return it('should return the callback with false', function() { + return it('should return the callback with false', function () { return this.callback.calledWith(null, false).should.equal(true) }) }) - return describe('when the lock is free', function() { - beforeEach(function() { + return describe('when the lock is free', function () { + beforeEach(function () { this.rclient.set = sinon.stub().callsArgWith(5, null, 'OK') return this.LockManager.tryLock(this.key, this.callback) }) - return it('should return the callback with true', function() { + return it('should return the callback with true', function () { return this.callback.calledWith(null, true).should.equal(true) }) }) }) - describe('deleteLock', function() { - return beforeEach(function() { - beforeEach(function() { + describe('deleteLock', function () { + return beforeEach(function () { + beforeEach(function () { this.rclient.del = sinon.stub().callsArg(1) return this.LockManager.deleteLock(this.key, this.callback) }) - it('should delete the lock in redis', function() { + it('should delete the lock in redis', function () { return this.rclient.del.calledWith(key).should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) - describe('getLock', function() { - describe('when the lock is not taken', function() { - beforeEach(function(done) { + describe('getLock', function () { + describe('when the lock is not taken', function () { + beforeEach(function (done) { this.LockManager.tryLock = sinon.stub().callsArgWith(1, null, true) return this.LockManager.getLock(this.key, (...args) => { this.callback(...Array.from(args || [])) @@ -139,26 +139,26 @@ describe('LockManager', function() { }) }) - it('should try to get the lock', function() { + it('should try to get the lock', function () { return this.LockManager.tryLock.calledWith(this.key).should.equal(true) }) - it('should only need to try once', function() { + it('should only need to try once', function () { return this.LockManager.tryLock.callCount.should.equal(1) }) - return it('should return the callback', function() { + return it('should return the callback', function () { return this.callback.calledWith(null).should.equal(true) }) }) - describe('when the lock is initially set', function() { - beforeEach(function(done) { + describe('when the lock is initially set', function () { + beforeEach(function (done) { const startTime = Date.now() this.LockManager.LOCK_TEST_INTERVAL = 5 - this.LockManager.tryLock = function(doc_id, callback) { + this.LockManager.tryLock = function (doc_id, callback) { if (callback == null) { - callback = function(error, isFree) {} + callback = function (error, isFree) {} } if (Date.now() - startTime < 100) { return callback(null, false) @@ -174,17 +174,17 @@ describe('LockManager', function() { }) }) - it('should call tryLock multiple times until free', function() { + it('should call tryLock multiple times until free', function () { return (this.LockManager.tryLock.callCount > 1).should.equal(true) }) - return it('should return the callback', function() { + return it('should return the callback', function () { return this.callback.calledWith(null).should.equal(true) }) }) - return describe('when the lock times out', function() { - beforeEach(function(done) { + return describe('when the lock times out', function () { + beforeEach(function (done) { const time = Date.now() this.LockManager.MAX_LOCK_WAIT_TIME = 5 this.LockManager.tryLock = sinon.stub().callsArgWith(1, null, false) @@ -194,7 +194,7 @@ describe('LockManager', function() { }) }) - return it('should return the callback with an error', function() { + return it('should return the callback with an error', function () { return this.callback .calledWith(sinon.match.instanceOf(Error)) .should.equal(true) @@ -202,12 +202,12 @@ describe('LockManager', function() { }) }) - return describe('runWithLock', function() { - describe('with successful run', function() { - beforeEach(function() { - this.runner = function(releaseLock) { + return describe('runWithLock', function () { + describe('with successful run', function () { + beforeEach(function () { + this.runner = function (releaseLock) { if (releaseLock == null) { - releaseLock = function(error) {} + releaseLock = function (error) {} } return releaseLock() } @@ -221,31 +221,31 @@ describe('LockManager', function() { ) }) - it('should get the lock', function() { + it('should get the lock', function () { return this.LockManager.getLock.calledWith(this.key).should.equal(true) }) - it('should run the passed function', function() { + it('should run the passed function', function () { return this.runner.called.should.equal(true) }) - it('should release the lock', function() { + it('should release the lock', function () { return this.LockManager.releaseLock .calledWith(this.key) .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('when the runner function returns an error', function() { - beforeEach(function() { + describe('when the runner function returns an error', function () { + beforeEach(function () { this.error = new Error('oops') - this.runner = releaseLock => { + this.runner = (releaseLock) => { if (releaseLock == null) { - releaseLock = function(error) {} + releaseLock = function (error) {} } return releaseLock(this.error) } @@ -259,20 +259,20 @@ describe('LockManager', function() { ) }) - it('should release the lock', function() { + it('should release the lock', function () { return this.LockManager.releaseLock .calledWith(this.key) .should.equal(true) }) - return it('should call the callback with the error', function() { + return it('should call the callback with the error', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) - return describe('releaseLock', function() { - describe('when the lock is current', function() { - beforeEach(function() { + return describe('releaseLock', function () { + describe('when the lock is current', function () { + beforeEach(function () { this.rclient.eval = sinon.stub().yields(null, 1) return this.LockManager.releaseLock( this.key, @@ -281,7 +281,7 @@ describe('LockManager', function() { ) }) - it('should clear the data from redis', function() { + it('should clear the data from redis', function () { return this.rclient.eval .calledWith( this.LockManager.unlockScript, @@ -292,13 +292,13 @@ describe('LockManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - return describe('when the lock has expired', function() { - beforeEach(function() { + return describe('when the lock has expired', function () { + beforeEach(function () { this.rclient.eval = sinon.stub().yields(null, 0) return this.LockManager.releaseLock( this.key, @@ -307,7 +307,7 @@ describe('LockManager', function() { ) }) - return it('should return an error if the lock has expired', function() { + return it('should return an error if the lock has expired', function () { return this.callback .calledWith( sinon.match.has('message', 'tried to release timed out lock') diff --git a/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js b/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js index 8adc8dd202..dc044cf288 100644 --- a/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js +++ b/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js @@ -19,8 +19,8 @@ const SandboxedModule = require('sandboxed-module') const { ObjectId } = require('mongojs') const tk = require('timekeeper') -describe('MongoManager', function() { - beforeEach(function() { +describe('MongoManager', function () { + beforeEach(function () { tk.freeze(new Date()) this.MongoManager = SandboxedModule.require(modulePath, { requires: { @@ -35,12 +35,12 @@ describe('MongoManager', function() { return (this.project_id = ObjectId().toString()) }) - afterEach(function() { + afterEach(function () { return tk.reset() }) - describe('getLastCompressedUpdate', function() { - beforeEach(function() { + describe('getLastCompressedUpdate', function () { + beforeEach(function () { this.update = 'mock-update' this.db.docHistory = {} this.db.docHistory.find = sinon.stub().returns(this.db.docHistory) @@ -57,28 +57,28 @@ describe('MongoManager', function() { ) }) - it('should find the updates for the doc', function() { + it('should find the updates for the doc', function () { return this.db.docHistory.find .calledWith({ doc_id: ObjectId(this.doc_id) }) .should.equal(true) }) - it('should limit to one result', function() { + it('should limit to one result', function () { return this.db.docHistory.limit.calledWith(1).should.equal(true) }) - it('should sort in descending version order', function() { + it('should sort in descending version order', function () { return this.db.docHistory.sort.calledWith({ v: -1 }).should.equal(true) }) - return it('should call the call back with the update', function() { + return it('should call the call back with the update', function () { return this.callback.calledWith(null, this.update).should.equal(true) }) }) - describe('peekLastCompressedUpdate', function() { - describe('when there is no last update', function() { - beforeEach(function() { + describe('peekLastCompressedUpdate', function () { + describe('when there is no last update', function () { + beforeEach(function () { this.PackManager.getLastPackFromIndex = sinon .stub() .callsArgWith(1, null, null) @@ -91,19 +91,19 @@ describe('MongoManager', function() { ) }) - it('should get the last update', function() { + it('should get the last update', function () { return this.MongoManager.getLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - return it('should call the callback with no update', function() { + return it('should call the callback with no update', function () { return this.callback.calledWith(null, null).should.equal(true) }) }) - describe('when there is an update', function() { - beforeEach(function() { + describe('when there is an update', function () { + beforeEach(function () { this.update = { _id: Object() } this.MongoManager.getLastCompressedUpdate = sinon .stub() @@ -114,19 +114,19 @@ describe('MongoManager', function() { ) }) - it('should get the last update', function() { + it('should get the last update', function () { return this.MongoManager.getLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - return it('should call the callback with the update', function() { + return it('should call the callback with the update', function () { return this.callback.calledWith(null, this.update).should.equal(true) }) }) - return describe('when there is a last update in S3', function() { - beforeEach(function() { + return describe('when there is a last update in S3', function () { + beforeEach(function () { this.update = { _id: Object(), v: 12345, v_end: 12345, inS3: true } this.PackManager.getLastPackFromIndex = sinon .stub() @@ -140,13 +140,13 @@ describe('MongoManager', function() { ) }) - it('should get the last update', function() { + it('should get the last update', function () { return this.MongoManager.getLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - return it('should call the callback with a null update and the correct version', function() { + return it('should call the callback with a null update and the correct version', function () { return this.callback .calledWith(null, null, this.update.v_end) .should.equal(true) @@ -154,8 +154,8 @@ describe('MongoManager', function() { }) }) - describe('backportProjectId', function() { - beforeEach(function() { + describe('backportProjectId', function () { + beforeEach(function () { this.db.docHistory = { update: sinon.stub().callsArg(3) } return this.MongoManager.backportProjectId( this.project_id, @@ -164,7 +164,7 @@ describe('MongoManager', function() { ) }) - it("should insert the project_id into all entries for the doc_id which don't have it set", function() { + it("should insert the project_id into all entries for the doc_id which don't have it set", function () { return this.db.docHistory.update .calledWith( { @@ -181,13 +181,13 @@ describe('MongoManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('getProjectMetaData', function() { - beforeEach(function() { + describe('getProjectMetaData', function () { + beforeEach(function () { this.metadata = { mock: 'metadata' } this.db.projectHistoryMetaData = { find: sinon.stub().callsArgWith(1, null, [this.metadata]) @@ -198,19 +198,19 @@ describe('MongoManager', function() { ) }) - it('should look up the meta data in the db', function() { + it('should look up the meta data in the db', function () { return this.db.projectHistoryMetaData.find .calledWith({ project_id: ObjectId(this.project_id) }) .should.equal(true) }) - return it('should return the metadata', function() { + return it('should return the metadata', function () { return this.callback.calledWith(null, this.metadata).should.equal(true) }) }) - return describe('setProjectMetaData', function() { - beforeEach(function() { + return describe('setProjectMetaData', function () { + beforeEach(function () { this.metadata = { mock: 'metadata' } this.db.projectHistoryMetaData = { update: sinon.stub().callsArgWith(3, null, [this.metadata]) @@ -222,7 +222,7 @@ describe('MongoManager', function() { ) }) - it('should upsert the metadata into the DB', function() { + it('should upsert the metadata into the DB', function () { return this.db.projectHistoryMetaData.update .calledWith( { @@ -238,7 +238,7 @@ describe('MongoManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/PackManager/PackManagerTests.js b/services/track-changes/test/unit/js/PackManager/PackManagerTests.js index 843a010f8f..6a5708fd9f 100644 --- a/services/track-changes/test/unit/js/PackManager/PackManagerTests.js +++ b/services/track-changes/test/unit/js/PackManager/PackManagerTests.js @@ -24,8 +24,8 @@ const _ = require('underscore') const tk = require('timekeeper') -describe('PackManager', function() { - beforeEach(function() { +describe('PackManager', function () { + beforeEach(function () { tk.freeze(new Date()) this.PackManager = SandboxedModule.require(modulePath, { requires: { @@ -46,12 +46,12 @@ describe('PackManager', function() { return (this.PackManager.MAX_COUNT = 512) }) - afterEach(function() { + afterEach(function () { return tk.reset() }) - describe('insertCompressedUpdates', function() { - beforeEach(function() { + describe('insertCompressedUpdates', function () { + beforeEach(function () { this.lastUpdate = { _id: '12345', pack: [ @@ -72,8 +72,8 @@ describe('PackManager', function() { }) }) - describe('with no last update', function() { - beforeEach(function() { + describe('with no last update', function () { + beforeEach(function () { this.PackManager.insertUpdatesIntoNewPack = sinon.stub().callsArg(4) return this.PackManager.insertCompressedUpdates( this.project_id, @@ -85,21 +85,21 @@ describe('PackManager', function() { ) }) - describe('for a small update', function() { - it('should insert the update into a new pack', function() { + describe('for a small update', function () { + it('should insert the update into a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith(this.project_id, this.doc_id, this.newUpdates, true) .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - return describe('for many small updates', function() { - beforeEach(function() { - this.newUpdates = __range__(0, 2048, true).map(i => ({ + return describe('for many small updates', function () { + beforeEach(function () { + this.newUpdates = __range__(0, 2048, true).map((i) => ({ op: `op-${i}`, meta: `meta-${i}`, v: i @@ -114,7 +114,7 @@ describe('PackManager', function() { ) }) - it('should append the initial updates to the existing pack', function() { + it('should append the initial updates to the existing pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -125,7 +125,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the first set remaining updates as a new pack', function() { + it('should insert the first set remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -136,7 +136,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the second set of remaining updates as a new pack', function() { + it('should insert the second set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -147,7 +147,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the third set of remaining updates as a new pack', function() { + it('should insert the third set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -158,7 +158,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the final set of remaining updates as a new pack', function() { + it('should insert the final set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -169,14 +169,14 @@ describe('PackManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) - describe('with an existing pack as the last update', function() { - beforeEach(function() { + describe('with an existing pack as the last update', function () { + beforeEach(function () { this.PackManager.appendUpdatesToExistingPack = sinon.stub().callsArg(5) this.PackManager.insertUpdatesIntoNewPack = sinon.stub().callsArg(4) return this.PackManager.insertCompressedUpdates( @@ -189,8 +189,8 @@ describe('PackManager', function() { ) }) - describe('for a small update', function() { - it('should append the update to the existing pack', function() { + describe('for a small update', function () { + it('should append the update to the existing pack', function () { return this.PackManager.appendUpdatesToExistingPack .calledWith( this.project_id, @@ -201,19 +201,19 @@ describe('PackManager', function() { ) .should.equal(true) }) - it('should not insert any new packs', function() { + it('should not insert any new packs', function () { return this.PackManager.insertUpdatesIntoNewPack.called.should.equal( false ) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('for many small updates', function() { - beforeEach(function() { - this.newUpdates = __range__(0, 2048, true).map(i => ({ + describe('for many small updates', function () { + beforeEach(function () { + this.newUpdates = __range__(0, 2048, true).map((i) => ({ op: `op-${i}`, meta: `meta-${i}`, v: i @@ -228,7 +228,7 @@ describe('PackManager', function() { ) }) - it('should append the initial updates to the existing pack', function() { + it('should append the initial updates to the existing pack', function () { return this.PackManager.appendUpdatesToExistingPack .calledWith( this.project_id, @@ -240,7 +240,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the first set remaining updates as a new pack', function() { + it('should insert the first set remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -251,7 +251,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the second set of remaining updates as a new pack', function() { + it('should insert the second set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -262,7 +262,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the third set of remaining updates as a new pack', function() { + it('should insert the third set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -273,7 +273,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the final set of remaining updates as a new pack', function() { + it('should insert the final set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -284,21 +284,21 @@ describe('PackManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - return describe('for many big updates', function() { - beforeEach(function() { + return describe('for many big updates', function () { + beforeEach(function () { const longString = __range__( 0, 0.75 * this.PackManager.MAX_SIZE, true ) - .map(j => 'a') + .map((j) => 'a') .join('') - this.newUpdates = [0, 1, 2, 3, 4].map(i => ({ + this.newUpdates = [0, 1, 2, 3, 4].map((i) => ({ op: `op-${i}-${longString}`, meta: `meta-${i}`, v: i @@ -313,7 +313,7 @@ describe('PackManager', function() { ) }) - it('should append the initial updates to the existing pack', function() { + it('should append the initial updates to the existing pack', function () { return this.PackManager.appendUpdatesToExistingPack .calledWith( this.project_id, @@ -325,7 +325,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the first set remaining updates as a new pack', function() { + it('should insert the first set remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -336,7 +336,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the second set of remaining updates as a new pack', function() { + it('should insert the second set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -347,7 +347,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the third set of remaining updates as a new pack', function() { + it('should insert the third set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -358,7 +358,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should insert the final set of remaining updates as a new pack', function() { + it('should insert the final set of remaining updates as a new pack', function () { return this.PackManager.insertUpdatesIntoNewPack .calledWith( this.project_id, @@ -369,15 +369,15 @@ describe('PackManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) - describe('flushCompressedUpdates', function() { - return describe('when there is no previous update', function() { - beforeEach(function() { + describe('flushCompressedUpdates', function () { + return describe('when there is no previous update', function () { + beforeEach(function () { return this.PackManager.flushCompressedUpdates( this.project_id, this.doc_id, @@ -388,8 +388,8 @@ describe('PackManager', function() { ) }) - return describe('for a small update that will expire', function() { - it('should insert the update into mongo', function() { + return describe('for a small update that will expire', function () { + it('should insert the update into mongo', function () { return this.db.docHistory.save .calledWithMatch({ pack: this.newUpdates, @@ -402,7 +402,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should set an expiry time in the future', function() { + it('should set an expiry time in the future', function () { return this.db.docHistory.save .calledWithMatch({ expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) @@ -410,15 +410,15 @@ describe('PackManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) }) - describe('when there is a recent previous update in mongo that expires', function() { - beforeEach(function() { + describe('when there is a recent previous update in mongo that expires', function () { + beforeEach(function () { this.lastUpdate = { _id: '12345', pack: [ @@ -441,8 +441,8 @@ describe('PackManager', function() { ) }) - return describe('for a small update that will expire', function() { - it('should append the update in mongo', function() { + return describe('for a small update that will expire', function () { + it('should append the update in mongo', function () { return this.db.docHistory.findAndModify .calledWithMatch({ query: { _id: this.lastUpdate._id }, @@ -454,7 +454,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should set an expiry time in the future', function() { + it('should set an expiry time in the future', function () { return this.db.docHistory.findAndModify .calledWithMatch({ update: { @@ -464,14 +464,14 @@ describe('PackManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) - describe('when there is a recent previous update in mongo that expires', function() { - beforeEach(function() { + describe('when there is a recent previous update in mongo that expires', function () { + beforeEach(function () { this.PackManager.updateIndex = sinon.stub().callsArg(2) this.lastUpdate = { @@ -496,8 +496,8 @@ describe('PackManager', function() { ) }) - return describe('for a small update that will not expire', function() { - it('should insert the update into mongo', function() { + return describe('for a small update that will not expire', function () { + it('should insert the update into mongo', function () { return this.db.docHistory.save .calledWithMatch({ pack: this.newUpdates, @@ -510,20 +510,20 @@ describe('PackManager', function() { .should.equal(true) }) - it('should not set any expiry time', function() { + it('should not set any expiry time', function () { return this.db.docHistory.save .neverCalledWithMatch(sinon.match.has('expiresAt')) .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) - return describe('when there is an old previous update in mongo', function() { - beforeEach(function() { + return describe('when there is an old previous update in mongo', function () { + beforeEach(function () { this.lastUpdate = { _id: '12345', pack: [ @@ -546,8 +546,8 @@ describe('PackManager', function() { ) }) - return describe('for a small update that will expire', function() { - it('should insert the update into mongo', function() { + return describe('for a small update that will expire', function () { + it('should insert the update into mongo', function () { return this.db.docHistory.save .calledWithMatch({ pack: this.newUpdates, @@ -560,7 +560,7 @@ describe('PackManager', function() { .should.equal(true) }) - it('should set an expiry time in the future', function() { + it('should set an expiry time in the future', function () { return this.db.docHistory.save .calledWithMatch({ expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000) @@ -568,28 +568,28 @@ describe('PackManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) }) - describe('getOpsByVersionRange', function() {}) + describe('getOpsByVersionRange', function () {}) - describe('loadPacksByVersionRange', function() {}) + describe('loadPacksByVersionRange', function () {}) - describe('fetchPacksIfNeeded', function() {}) + describe('fetchPacksIfNeeded', function () {}) - describe('makeProjectIterator', function() {}) + describe('makeProjectIterator', function () {}) - describe('getPackById', function() {}) + describe('getPackById', function () {}) - describe('increaseTTL', function() {}) + describe('increaseTTL', function () {}) - describe('getIndex', function() {}) + describe('getIndex', function () {}) - describe('getPackFromIndex', function() {}) + describe('getPackFromIndex', function () {}) // getLastPackFromIndex: // getIndexWithKeys // initialiseIndex @@ -604,9 +604,9 @@ describe('PackManager', function() { // updateIndexIfNeeded // findUnarchivedPacks - return describe('checkArchiveNotInProgress', function() { - describe('when an archive is in progress', function() { - beforeEach(function() { + return describe('checkArchiveNotInProgress', function () { + describe('when an archive is in progress', function () { + beforeEach(function () { this.db.docHistoryIndex = { findOne: sinon.stub().callsArgWith(2, null, { inS3: false }) } @@ -617,18 +617,18 @@ describe('PackManager', function() { this.callback ) }) - it('should call the callback', function() { + it('should call the callback', function () { return this.callback.called.should.equal(true) }) - return it('should return an error', function() { + return it('should return an error', function () { return this.callback .calledWith(sinon.match.has('message')) .should.equal(true) }) }) - describe('when an archive is completed', function() { - beforeEach(function() { + describe('when an archive is completed', function () { + beforeEach(function () { this.db.docHistoryIndex = { findOne: sinon.stub().callsArgWith(2, null, { inS3: true }) } @@ -639,18 +639,18 @@ describe('PackManager', function() { this.callback ) }) - it('should call the callback', function() { + it('should call the callback', function () { return this.callback.called.should.equal(true) }) - return it('should return an error', function() { + return it('should return an error', function () { return this.callback .calledWith(sinon.match.has('message')) .should.equal(true) }) }) - return describe('when the archive has not started or completed', function() { - beforeEach(function() { + return describe('when the archive has not started or completed', function () { + beforeEach(function () { this.db.docHistoryIndex = { findOne: sinon.stub().callsArgWith(2, null, {}) } @@ -661,10 +661,10 @@ describe('PackManager', function() { this.callback ) }) - it('should call the callback with no error', function() { + it('should call the callback with no error', function () { return this.callback.called.should.equal(true) }) - return it('should return with no error', function() { + return it('should return with no error', function () { return (typeof this.callback.lastCall.args[0]).should.equal('undefined') }) }) diff --git a/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js b/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js index d05bf50814..fcfc17b1bb 100644 --- a/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js +++ b/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js @@ -18,8 +18,8 @@ const { expect } = chai const modulePath = '../../../../app/js/RedisManager.js' const SandboxedModule = require('sandboxed-module') -describe('RedisManager', function() { - beforeEach(function() { +describe('RedisManager', function () { + beforeEach(function () { this.RedisManager = SandboxedModule.require(modulePath, { requires: { 'redis-sharelatex': { @@ -52,13 +52,13 @@ describe('RedisManager', function() { return (this.callback = sinon.stub()) }) - describe('getOldestDocUpdates', function() { - beforeEach(function() { + describe('getOldestDocUpdates', function () { + beforeEach(function () { this.rawUpdates = [ { v: 42, op: 'mock-op-42' }, { v: 45, op: 'mock-op-45' } ] - this.jsonUpdates = Array.from(this.rawUpdates).map(update => + this.jsonUpdates = Array.from(this.rawUpdates).map((update) => JSON.stringify(update) ) this.rclient.lrange = sinon.stub().callsArgWith(3, null, this.jsonUpdates) @@ -69,7 +69,7 @@ describe('RedisManager', function() { ) }) - it('should read the updates from redis', function() { + it('should read the updates from redis', function () { return this.rclient.lrange .calledWith( `UncompressedHistoryOps:${this.doc_id}`, @@ -79,27 +79,27 @@ describe('RedisManager', function() { .should.equal(true) }) - it('should call the callback with the unparsed ops', function() { + it('should call the callback with the unparsed ops', function () { return this.callback.calledWith(null, this.jsonUpdates).should.equal(true) }) - describe('expandDocUpdates', function() { - beforeEach(function() { + describe('expandDocUpdates', function () { + beforeEach(function () { return this.RedisManager.expandDocUpdates( this.jsonUpdates, this.callback ) }) - return it('should call the callback with the parsed ops', function() { + return it('should call the callback with the parsed ops', function () { return this.callback .calledWith(null, this.rawUpdates) .should.equal(true) }) }) - return describe('deleteAppliedDocUpdates', function() { - beforeEach(function() { + return describe('deleteAppliedDocUpdates', function () { + beforeEach(function () { this.rclient.lrem = sinon.stub() this.rclient.srem = sinon.stub() this.rclient.exec = sinon.stub().callsArgWith(0) @@ -111,7 +111,7 @@ describe('RedisManager', function() { ) }) - it('should delete the first update from redis', function() { + it('should delete the first update from redis', function () { return this.rclient.lrem .calledWith( `UncompressedHistoryOps:${this.doc_id}`, @@ -121,7 +121,7 @@ describe('RedisManager', function() { .should.equal(true) }) - it('should delete the second update from redis', function() { + it('should delete the second update from redis', function () { return this.rclient.lrem .calledWith( `UncompressedHistoryOps:${this.doc_id}`, @@ -131,20 +131,20 @@ describe('RedisManager', function() { .should.equal(true) }) - it('should delete the doc from the set of docs with history ops', function() { + it('should delete the doc from the set of docs with history ops', function () { return this.rclient.srem .calledWith(`DocsWithHistoryOps:${this.project_id}`, this.doc_id) .should.equal(true) }) - return it('should call the callback ', function() { + return it('should call the callback ', function () { return this.callback.called.should.equal(true) }) }) }) - return describe('getDocIdsWithHistoryOps', function() { - beforeEach(function() { + return describe('getDocIdsWithHistoryOps', function () { + beforeEach(function () { this.doc_ids = ['mock-id-1', 'mock-id-2'] this.rclient.smembers = sinon.stub().callsArgWith(1, null, this.doc_ids) return this.RedisManager.getDocIdsWithHistoryOps( @@ -153,13 +153,13 @@ describe('RedisManager', function() { ) }) - it('should read the doc_ids from redis', function() { + it('should read the doc_ids from redis', function () { return this.rclient.smembers .calledWith(`DocsWithHistoryOps:${this.project_id}`) .should.equal(true) }) - return it('should call the callback with the doc_ids', function() { + return it('should call the callback with the doc_ids', function () { return this.callback.calledWith(null, this.doc_ids).should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js b/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js index 86d2f92f0c..7e9c6896b0 100644 --- a/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js +++ b/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js @@ -16,8 +16,8 @@ const { expect } = chai const modulePath = '../../../../app/js/RestoreManager.js' const SandboxedModule = require('sandboxed-module') -describe('RestoreManager', function() { - beforeEach(function() { +describe('RestoreManager', function () { + beforeEach(function () { this.RestoreManager = SandboxedModule.require(modulePath, { requires: { 'logger-sharelatex': (this.logger = { @@ -35,8 +35,8 @@ describe('RestoreManager', function() { return (this.version = 42) }) - return describe('restoreToBeforeVersion', function() { - beforeEach(function() { + return describe('restoreToBeforeVersion', function () { + beforeEach(function () { this.content = 'mock content' this.DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4) this.DiffManager.getDocumentBeforeVersion = sinon @@ -51,19 +51,19 @@ describe('RestoreManager', function() { ) }) - it('should get the content before the requested version', function() { + it('should get the content before the requested version', function () { return this.DiffManager.getDocumentBeforeVersion .calledWith(this.project_id, this.doc_id, this.version) .should.equal(true) }) - it('should set the document in the document updater', function() { + it('should set the document in the document updater', function () { return this.DocumentUpdaterManager.setDocument .calledWith(this.project_id, this.doc_id, this.content, this.user_id) .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js b/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js index 9a88db6357..110b8ed1c8 100644 --- a/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js +++ b/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js @@ -17,14 +17,14 @@ const modulePath = '../../../../app/js/UpdateCompressor.js' const SandboxedModule = require('sandboxed-module') const bigstring = __range__(0, 2 * 1024 * 1024, true) - .map(i => 'a') + .map((i) => 'a') .join('') const mediumstring = __range__(0, 1024 * 1024, true) - .map(j => 'a') + .map((j) => 'a') .join('') -describe('UpdateCompressor', function() { - beforeEach(function() { +describe('UpdateCompressor', function () { + beforeEach(function () { this.UpdateCompressor = SandboxedModule.require(modulePath, { requires: { '../lib/diff_match_patch': require('../../../../app/lib/diff_match_patch') @@ -36,8 +36,8 @@ describe('UpdateCompressor', function() { return (this.ts2 = Date.now() + 1000) }) - describe('convertToSingleOpUpdates', function() { - it('should split grouped updates into individual updates', function() { + describe('convertToSingleOpUpdates', function () { + it('should split grouped updates into individual updates', function () { return expect( this.UpdateCompressor.convertToSingleOpUpdates([ { @@ -77,7 +77,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should return no-op updates when the op list is empty', function() { + it('should return no-op updates when the op list is empty', function () { return expect( this.UpdateCompressor.convertToSingleOpUpdates([ { @@ -95,7 +95,7 @@ describe('UpdateCompressor', function() { ]) }) - return it('should ignore comment ops', function() { + return it('should ignore comment ops', function () { return expect( this.UpdateCompressor.convertToSingleOpUpdates([ { @@ -123,8 +123,8 @@ describe('UpdateCompressor', function() { }) }) - describe('concatUpdatesWithSameVersion', function() { - it('should concat updates with the same version', function() { + describe('concatUpdatesWithSameVersion', function () { + it('should concat updates with the same version', function () { return expect( this.UpdateCompressor.concatUpdatesWithSameVersion([ { @@ -173,7 +173,7 @@ describe('UpdateCompressor', function() { ]) }) - return it('should turn a noop into an empty op', function() { + return it('should turn a noop into an empty op', function () { return expect( this.UpdateCompressor.concatUpdatesWithSameVersion([ { @@ -196,9 +196,9 @@ describe('UpdateCompressor', function() { }) }) - describe('compress', function() { - describe('insert - insert', function() { - it('should append one insert to the other', function() { + describe('compress', function () { + describe('insert - insert', function () { + it('should append one insert to the other', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -225,7 +225,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should insert one insert inside the other', function() { + it('should insert one insert inside the other', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -252,7 +252,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should not append separated inserts', function() { + it('should not append separated inserts', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -288,7 +288,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should not append inserts that are too big (second op)', function() { + it('should not append inserts that are too big (second op)', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -324,7 +324,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should not append inserts that are too big (first op)', function() { + it('should not append inserts that are too big (first op)', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -360,7 +360,7 @@ describe('UpdateCompressor', function() { ]) }) - return it('should not append inserts that are too big (first and second op)', function() { + return it('should not append inserts that are too big (first and second op)', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -397,8 +397,8 @@ describe('UpdateCompressor', function() { }) }) - describe('delete - delete', function() { - it('should append one delete to the other', function() { + describe('delete - delete', function () { + it('should append one delete to the other', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -425,7 +425,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should insert one delete inside the other', function() { + it('should insert one delete inside the other', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -452,7 +452,7 @@ describe('UpdateCompressor', function() { ]) }) - return it('should not append separated deletes', function() { + return it('should not append separated deletes', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -489,8 +489,8 @@ describe('UpdateCompressor', function() { }) }) - describe('insert - delete', function() { - it('should undo a previous insert', function() { + describe('insert - delete', function () { + it('should undo a previous insert', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -517,7 +517,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should remove part of an insert from the middle', function() { + it('should remove part of an insert from the middle', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -544,7 +544,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should cancel out two opposite updates', function() { + it('should cancel out two opposite updates', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -571,7 +571,7 @@ describe('UpdateCompressor', function() { ]) }) - it('should not combine separated updates', function() { + it('should not combine separated updates', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -607,7 +607,7 @@ describe('UpdateCompressor', function() { ]) }) - return it('should not combine updates with overlap beyond the end', function() { + return it('should not combine updates with overlap beyond the end', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -644,8 +644,8 @@ describe('UpdateCompressor', function() { }) }) - describe('delete - insert', function() { - it('should do a diff of the content', function() { + describe('delete - insert', function () { + it('should do a diff of the content', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -681,7 +681,7 @@ describe('UpdateCompressor', function() { ]) }) - return it('should return a no-op if the delete and insert are the same', function() { + return it('should return a no-op if the delete and insert are the same', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -709,8 +709,8 @@ describe('UpdateCompressor', function() { }) }) - describe('noop - insert', function() { - return it('should leave them untouched', function() { + describe('noop - insert', function () { + return it('should leave them untouched', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -747,8 +747,8 @@ describe('UpdateCompressor', function() { }) }) - return describe('noop - delete', function() { - return it('should leave them untouched', function() { + return describe('noop - delete', function () { + return it('should leave them untouched', function () { return expect( this.UpdateCompressor.compressUpdates([ { @@ -786,9 +786,9 @@ describe('UpdateCompressor', function() { }) }) - return describe('compressRawUpdates', function() { - return describe('merging in-place with an array op', function() { - return it('should not change the existing last updates', function() { + return describe('compressRawUpdates', function () { + return describe('merging in-place with an array op', function () { + return it('should not change the existing last updates', function () { return expect( this.UpdateCompressor.compressRawUpdates( { diff --git a/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js b/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js index 1a4e0f7861..5623954230 100644 --- a/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js +++ b/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js @@ -17,8 +17,8 @@ const modulePath = '../../../../app/js/UpdateTrimmer.js' const SandboxedModule = require('sandboxed-module') const tk = require('timekeeper') -describe('UpdateTrimmer', function() { - beforeEach(function() { +describe('UpdateTrimmer', function () { + beforeEach(function () { this.now = new Date() tk.freeze(this.now) @@ -37,12 +37,12 @@ describe('UpdateTrimmer', function() { return (this.project_id = 'mock-project-id') }) - afterEach(function() { + afterEach(function () { return tk.reset() }) - return describe('shouldTrimUpdates', function() { - beforeEach(function() { + return describe('shouldTrimUpdates', function () { + beforeEach(function () { this.metadata = {} this.details = { features: {} } this.MongoManager.getProjectMetaData = sinon @@ -55,8 +55,8 @@ describe('UpdateTrimmer', function() { .callsArgWith(1, null, this.details)) }) - describe('with preserveHistory set in the project meta data', function() { - beforeEach(function() { + describe('with preserveHistory set in the project meta data', function () { + beforeEach(function () { this.metadata.preserveHistory = true return this.UpdateTrimmer.shouldTrimUpdates( this.project_id, @@ -64,28 +64,28 @@ describe('UpdateTrimmer', function() { ) }) - it('should look up the meta data', function() { + it('should look up the meta data', function () { return this.MongoManager.getProjectMetaData .calledWith(this.project_id) .should.equal(true) }) - it('should not look up the project details', function() { + it('should not look up the project details', function () { return this.WebApiManager.getProjectDetails.called.should.equal(false) }) - return it('should return false', function() { + return it('should return false', function () { return this.callback.calledWith(null, false).should.equal(true) }) }) - describe('without preserveHistory set in the project meta data', function() { - beforeEach(function() { + describe('without preserveHistory set in the project meta data', function () { + beforeEach(function () { return (this.metadata.preserveHistory = false) }) - describe('when the project has the versioning feature', function() { - beforeEach(function() { + describe('when the project has the versioning feature', function () { + beforeEach(function () { this.details.features.versioning = true return this.UpdateTrimmer.shouldTrimUpdates( this.project_id, @@ -93,37 +93,37 @@ describe('UpdateTrimmer', function() { ) }) - it('should look up the meta data', function() { + it('should look up the meta data', function () { return this.MongoManager.getProjectMetaData .calledWith(this.project_id) .should.equal(true) }) - it('should look up the project details', function() { + it('should look up the project details', function () { return this.WebApiManager.getProjectDetails .calledWith(this.project_id) .should.equal(true) }) - it('should insert preserveHistory into the metadata', function() { + it('should insert preserveHistory into the metadata', function () { return this.MongoManager.setProjectMetaData .calledWith(this.project_id, { preserveHistory: true }) .should.equal(true) }) - it('should upgrade any existing history', function() { + it('should upgrade any existing history', function () { return this.MongoManager.upgradeHistory .calledWith(this.project_id) .should.equal(true) }) - return it('should return false', function() { + return it('should return false', function () { return this.callback.calledWith(null, false).should.equal(true) }) }) - return describe('when the project does not have the versioning feature', function() { - beforeEach(function() { + return describe('when the project does not have the versioning feature', function () { + beforeEach(function () { this.details.features.versioning = false return this.UpdateTrimmer.shouldTrimUpdates( this.project_id, @@ -131,21 +131,21 @@ describe('UpdateTrimmer', function() { ) }) - return it('should return true', function() { + return it('should return true', function () { return this.callback.calledWith(null, true).should.equal(true) }) }) }) - return describe('without any meta data', function() { - beforeEach(function() { + return describe('without any meta data', function () { + beforeEach(function () { return (this.MongoManager.getProjectMetaData = sinon .stub() .callsArgWith(1, null, null)) }) - describe('when the project has the versioning feature', function() { - beforeEach(function() { + describe('when the project has the versioning feature', function () { + beforeEach(function () { this.details.features.versioning = true return this.UpdateTrimmer.shouldTrimUpdates( this.project_id, @@ -153,25 +153,25 @@ describe('UpdateTrimmer', function() { ) }) - it('should insert preserveHistory into the metadata', function() { + it('should insert preserveHistory into the metadata', function () { return this.MongoManager.setProjectMetaData .calledWith(this.project_id, { preserveHistory: true }) .should.equal(true) }) - it('should upgrade any existing history', function() { + it('should upgrade any existing history', function () { return this.MongoManager.upgradeHistory .calledWith(this.project_id) .should.equal(true) }) - return it('should return false', function() { + return it('should return false', function () { return this.callback.calledWith(null, false).should.equal(true) }) }) - return describe('when the project does not have the versioning feature', function() { - beforeEach(function() { + return describe('when the project does not have the versioning feature', function () { + beforeEach(function () { this.details.features.versioning = false return this.UpdateTrimmer.shouldTrimUpdates( this.project_id, @@ -179,7 +179,7 @@ describe('UpdateTrimmer', function() { ) }) - return it('should return true', function() { + return it('should return true', function () { return this.callback.calledWith(null, true).should.equal(true) }) }) diff --git a/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js b/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js index 788821aea1..cb2af00c16 100644 --- a/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js +++ b/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js @@ -20,8 +20,8 @@ const { expect } = chai const modulePath = '../../../../app/js/UpdatesManager.js' const SandboxedModule = require('sandboxed-module') -describe('UpdatesManager', function() { - beforeEach(function() { +describe('UpdatesManager', function () { + beforeEach(function () { this.UpdatesManager = SandboxedModule.require(modulePath, { singleOnly: true, requires: { @@ -53,9 +53,9 @@ describe('UpdatesManager', function() { return (this.temporary = 'temp-mock') }) - describe('compressAndSaveRawUpdates', function() { - describe('when there are no raw ops', function() { - beforeEach(function() { + describe('compressAndSaveRawUpdates', function () { + describe('when there are no raw ops', function () { + beforeEach(function () { this.MongoManager.peekLastCompressedUpdate = sinon.stub() return this.UpdatesManager.compressAndSaveRawUpdates( this.project_id, @@ -66,19 +66,19 @@ describe('UpdatesManager', function() { ) }) - it('should not need to access the database', function() { + it('should not need to access the database', function () { return this.MongoManager.peekLastCompressedUpdate.called.should.equal( false ) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('when there is no compressed history to begin with', function() { - beforeEach(function() { + describe('when there is no compressed history to begin with', function () { + beforeEach(function () { this.rawUpdates = [ { v: 12, op: 'mock-op-12' }, { v: 13, op: 'mock-op-13' } @@ -101,13 +101,13 @@ describe('UpdatesManager', function() { ) }) - it('should look at the last compressed op', function() { + it('should look at the last compressed op', function () { return this.MongoManager.peekLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - it('should save the compressed ops as a pack', function() { + it('should save the compressed ops as a pack', function () { return this.PackManager.insertCompressedUpdates .calledWith( this.project_id, @@ -119,13 +119,13 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('when the raw ops need appending to existing history', function() { - beforeEach(function() { + describe('when the raw ops need appending to existing history', function () { + beforeEach(function () { this.lastCompressedUpdate = { v: 11, op: 'compressed-op-11' } this.compressedUpdates = [ { v: 12, op: 'compressed-op-11+12' }, @@ -146,8 +146,8 @@ describe('UpdatesManager', function() { .returns(this.compressedUpdates)) }) - describe('when the raw ops start where the existing history ends', function() { - beforeEach(function() { + describe('when the raw ops start where the existing history ends', function () { + beforeEach(function () { this.rawUpdates = [ { v: 12, op: 'mock-op-12' }, { v: 13, op: 'mock-op-13' } @@ -161,19 +161,19 @@ describe('UpdatesManager', function() { ) }) - it('should look at the last compressed op', function() { + it('should look at the last compressed op', function () { return this.MongoManager.peekLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - it('should compress the raw ops', function() { + it('should compress the raw ops', function () { return this.UpdateCompressor.compressRawUpdates .calledWith(null, this.rawUpdates) .should.equal(true) }) - it('should save the new compressed ops into a pack', function() { + it('should save the new compressed ops into a pack', function () { return this.PackManager.insertCompressedUpdates .calledWith( this.project_id, @@ -185,13 +185,13 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('when the raw ops start where the existing history ends and the history is in a pack', function() { - beforeEach(function() { + describe('when the raw ops start where the existing history ends and the history is in a pack', function () { + beforeEach(function () { this.lastCompressedUpdate = { pack: [{ v: 11, op: 'compressed-op-11' }], v: 11 @@ -217,19 +217,19 @@ describe('UpdatesManager', function() { ) }) - it('should look at the last compressed op', function() { + it('should look at the last compressed op', function () { return this.MongoManager.peekLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - it('should compress the raw ops', function() { + it('should compress the raw ops', function () { return this.UpdateCompressor.compressRawUpdates .calledWith(null, this.rawUpdates) .should.equal(true) }) - it('should save the new compressed ops into a pack', function() { + it('should save the new compressed ops into a pack', function () { return this.PackManager.insertCompressedUpdates .calledWith( this.project_id, @@ -241,13 +241,13 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('when some raw ops are passed that have already been compressed', function() { - beforeEach(function() { + describe('when some raw ops are passed that have already been compressed', function () { + beforeEach(function () { this.rawUpdates = [ { v: 10, op: 'mock-op-10' }, { v: 11, op: 'mock-op-11' }, @@ -264,15 +264,15 @@ describe('UpdatesManager', function() { ) }) - return it('should only compress the more recent raw ops', function() { + return it('should only compress the more recent raw ops', function () { return this.UpdateCompressor.compressRawUpdates .calledWith(null, this.rawUpdates.slice(-2)) .should.equal(true) }) }) - describe('when the raw ops do not follow from the last compressed op version', function() { - beforeEach(function() { + describe('when the raw ops do not follow from the last compressed op version', function () { + beforeEach(function () { this.rawUpdates = [{ v: 13, op: 'mock-op-13' }] return this.UpdatesManager.compressAndSaveRawUpdates( this.project_id, @@ -283,7 +283,7 @@ describe('UpdatesManager', function() { ) }) - it('should call the callback with an error', function() { + it('should call the callback with an error', function () { return this.callback .calledWith( sinon.match.has( @@ -294,15 +294,15 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should not insert any update into mongo', function() { + return it('should not insert any update into mongo', function () { return this.PackManager.insertCompressedUpdates.called.should.equal( false ) }) }) - return describe('when the raw ops are out of order', function() { - beforeEach(function() { + return describe('when the raw ops are out of order', function () { + beforeEach(function () { this.rawUpdates = [ { v: 13, op: 'mock-op-13' }, { v: 12, op: 'mock-op-12' } @@ -316,13 +316,13 @@ describe('UpdatesManager', function() { ) }) - it('should call the callback with an error', function() { + it('should call the callback with an error', function () { return this.callback .calledWith(sinon.match.has('message')) .should.equal(true) }) - return it('should not insert any update into mongo', function() { + return it('should not insert any update into mongo', function () { return this.PackManager.insertCompressedUpdates.called.should.equal( false ) @@ -330,8 +330,8 @@ describe('UpdatesManager', function() { }) }) - return describe('when the raw ops need appending to existing history which is in S3', function() { - beforeEach(function() { + return describe('when the raw ops need appending to existing history which is in S3', function () { + beforeEach(function () { this.lastCompressedUpdate = null this.lastVersion = 11 this.compressedUpdates = [{ v: 13, op: 'compressed-op-12' }] @@ -345,8 +345,8 @@ describe('UpdatesManager', function() { .returns(this.compressedUpdates)) }) - return describe('when the raw ops start where the existing history ends', function() { - beforeEach(function() { + return describe('when the raw ops start where the existing history ends', function () { + beforeEach(function () { this.rawUpdates = [ { v: 12, op: 'mock-op-12' }, { v: 13, op: 'mock-op-13' } @@ -360,19 +360,19 @@ describe('UpdatesManager', function() { ) }) - it('should try to look at the last compressed op', function() { + it('should try to look at the last compressed op', function () { return this.MongoManager.peekLastCompressedUpdate .calledWith(this.doc_id) .should.equal(true) }) - it('should compress the last compressed op and the raw ops', function() { + it('should compress the last compressed op and the raw ops', function () { return this.UpdateCompressor.compressRawUpdates .calledWith(this.lastCompressedUpdate, this.rawUpdates) .should.equal(true) }) - it('should save the compressed ops', function() { + it('should save the compressed ops', function () { return this.PackManager.insertCompressedUpdates .calledWith( this.project_id, @@ -384,15 +384,15 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) }) - describe('processUncompressedUpdates', function() { - beforeEach(function() { + describe('processUncompressedUpdates', function () { + beforeEach(function () { this.UpdatesManager.compressAndSaveRawUpdates = sinon .stub() .callsArgWith(4) @@ -403,8 +403,8 @@ describe('UpdatesManager', function() { .callsArgWith(1, null, (this.temporary = 'temp mock'))) }) - describe('when there is fewer than one batch to send', function() { - beforeEach(function() { + describe('when there is fewer than one batch to send', function () { + beforeEach(function () { this.updates = ['mock-update'] this.RedisManager.getOldestDocUpdates = sinon .stub() @@ -420,13 +420,13 @@ describe('UpdatesManager', function() { ) }) - it('should get the oldest updates', function() { + it('should get the oldest updates', function () { return this.RedisManager.getOldestDocUpdates .calledWith(this.doc_id, this.UpdatesManager.REDIS_READ_BATCH_SIZE) .should.equal(true) }) - it('should compress and save the updates', function() { + it('should compress and save the updates', function () { return this.UpdatesManager.compressAndSaveRawUpdates .calledWith( this.project_id, @@ -437,19 +437,19 @@ describe('UpdatesManager', function() { .should.equal(true) }) - it('should delete the batch of uncompressed updates that was just processed', function() { + it('should delete the batch of uncompressed updates that was just processed', function () { return this.RedisManager.deleteAppliedDocUpdates .calledWith(this.project_id, this.doc_id, this.updates) .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - return describe('when there are multiple batches to send', function() { - beforeEach(function(done) { + return describe('when there are multiple batches to send', function () { + beforeEach(function (done) { this.UpdatesManager.REDIS_READ_BATCH_SIZE = 2 this.updates = [ 'mock-update-0', @@ -465,7 +465,7 @@ describe('UpdatesManager', function() { callback ) => { if (callback == null) { - callback = function(error, updates) {} + callback = function (error, updates) {} } const updates = this.redisArray.slice(0, batchSize) this.redisArray = this.redisArray.slice(batchSize) @@ -487,11 +487,11 @@ describe('UpdatesManager', function() { ) }) - it('should get the oldest updates in three batches ', function() { + it('should get the oldest updates in three batches ', function () { return this.RedisManager.getOldestDocUpdates.callCount.should.equal(3) }) - it('should compress and save the updates in batches', function() { + it('should compress and save the updates in batches', function () { this.UpdatesManager.compressAndSaveRawUpdates .calledWith( this.project_id, @@ -518,20 +518,20 @@ describe('UpdatesManager', function() { .should.equal(true) }) - it('should delete the batches of uncompressed updates', function() { + it('should delete the batches of uncompressed updates', function () { return this.RedisManager.deleteAppliedDocUpdates.callCount.should.equal( 3 ) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) }) - describe('processCompressedUpdatesWithLock', function() { - beforeEach(function() { + describe('processCompressedUpdatesWithLock', function () { + beforeEach(function () { this.UpdateTrimmer.shouldTrimUpdates = sinon .stub() .callsArgWith(1, null, (this.temporary = 'temp mock')) @@ -545,31 +545,31 @@ describe('UpdatesManager', function() { ) }) - it('should check if the updates are temporary', function() { + it('should check if the updates are temporary', function () { return this.UpdateTrimmer.shouldTrimUpdates .calledWith(this.project_id) .should.equal(true) }) - it('should backport the project id', function() { + it('should backport the project id', function () { return this.MongoManager.backportProjectId .calledWith(this.project_id, this.doc_id) .should.equal(true) }) - it('should run processUncompressedUpdates with the lock', function() { + it('should run processUncompressedUpdates with the lock', function () { return this.LockManager.runWithLock .calledWith(`HistoryLock:${this.doc_id}`) .should.equal(true) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('getDocUpdates', function() { - beforeEach(function() { + describe('getDocUpdates', function () { + beforeEach(function () { this.updates = ['mock-updates'] this.options = { to: 'mock-to', limit: 'mock-limit' } this.PackManager.getOpsByVersionRange = sinon @@ -586,13 +586,13 @@ describe('UpdatesManager', function() { ) }) - it('should process outstanding updates', function() { + it('should process outstanding updates', function () { return this.UpdatesManager.processUncompressedUpdatesWithLock .calledWith(this.project_id, this.doc_id) .should.equal(true) }) - it('should get the updates from the database', function() { + it('should get the updates from the database', function () { return this.PackManager.getOpsByVersionRange .calledWith( this.project_id, @@ -603,13 +603,13 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should return the updates', function() { + return it('should return the updates', function () { return this.callback.calledWith(null, this.updates).should.equal(true) }) }) - describe('getDocUpdatesWithUserInfo', function() { - beforeEach(function() { + describe('getDocUpdatesWithUserInfo', function () { + beforeEach(function () { this.updates = ['mock-updates'] this.options = { to: 'mock-to', limit: 'mock-limit' } this.updatesWithUserInfo = ['updates-with-user-info'] @@ -627,27 +627,27 @@ describe('UpdatesManager', function() { ) }) - it('should get the updates', function() { + it('should get the updates', function () { return this.UpdatesManager.getDocUpdates .calledWith(this.project_id, this.doc_id, this.options) .should.equal(true) }) - it('should file the updates with the user info', function() { + it('should file the updates with the user info', function () { return this.UpdatesManager.fillUserInfo .calledWith(this.updates) .should.equal(true) }) - return it('should return the updates with the filled details', function() { + return it('should return the updates with the filled details', function () { return this.callback .calledWith(null, this.updatesWithUserInfo) .should.equal(true) }) }) - describe('processUncompressedUpdatesForProject', function() { - beforeEach(function(done) { + describe('processUncompressedUpdatesForProject', function () { + beforeEach(function (done) { this.doc_ids = ['mock-id-1', 'mock-id-2'] this.UpdateTrimmer.shouldTrimUpdates = sinon .stub() @@ -668,27 +668,27 @@ describe('UpdatesManager', function() { ) }) - it('should get all the docs with history ops', function() { + it('should get all the docs with history ops', function () { return this.RedisManager.getDocIdsWithHistoryOps .calledWith(this.project_id) .should.equal(true) }) - it('should process the doc ops for the each doc_id', function() { - return Array.from(this.doc_ids).map(doc_id => + it('should process the doc ops for the each doc_id', function () { + return Array.from(this.doc_ids).map((doc_id) => this.UpdatesManager._processUncompressedUpdatesForDocWithLock .calledWith(this.project_id, doc_id, this.temporary) .should.equal(true) ) }) - return it('should call the callback', function() { + return it('should call the callback', function () { return this.callback.called.should.equal(true) }) }) - describe('getSummarizedProjectUpdates', function() { - beforeEach(function() { + describe('getSummarizedProjectUpdates', function () { + beforeEach(function () { this.updates = [ { doc_id: 123, @@ -707,7 +707,7 @@ describe('UpdatesManager', function() { this.updatesWithUserInfo = ['updates-with-user-info'] this.done_state = false this.iterator = { - next: cb => { + next: (cb) => { this.done_state = true return cb(null, this.updates) }, @@ -731,25 +731,25 @@ describe('UpdatesManager', function() { ) }) - it('should process any outstanding updates', function() { + it('should process any outstanding updates', function () { return this.UpdatesManager.processUncompressedUpdatesForProject .calledWith(this.project_id) .should.equal(true) }) - it('should get the updates', function() { + it('should get the updates', function () { return this.PackManager.makeProjectIterator .calledWith(this.project_id, this.options.before) .should.equal(true) }) - it('should fill the updates with the user info', function() { + it('should fill the updates with the user info', function () { return this.UpdatesManager.fillSummarizedUserInfo .calledWith(this.summarizedUpdates) .should.equal(true) }) - return it('should return the updates with the filled details', function() { + return it('should return the updates with the filled details', function () { return this.callback .calledWith(null, this.updatesWithUserInfo) .should.equal(true) @@ -861,9 +861,9 @@ describe('UpdatesManager', function() { // it "should call the callback with the updates", -> // @callback.calledWith(null, @updates, null).should.equal true - describe('fillUserInfo', function() { - describe('with valid users', function() { - beforeEach(function(done) { + describe('fillUserInfo', function () { + describe('with valid users', function () { + beforeEach(function (done) { const { ObjectId } = require('mongojs') this.user_id_1 = ObjectId().toString() this.user_id_2 = ObjectId().toString() @@ -893,7 +893,7 @@ describe('UpdatesManager', function() { this.WebApiManager.getUserInfo = (user_id, callback) => { if (callback == null) { - callback = function(error, userInfo) {} + callback = function (error, userInfo) {} } return callback(null, this.user_info[user_id]) } @@ -908,7 +908,7 @@ describe('UpdatesManager', function() { ) }) - it('should only call getUserInfo once for each user_id', function() { + it('should only call getUserInfo once for each user_id', function () { this.WebApiManager.getUserInfo.calledTwice.should.equal(true) this.WebApiManager.getUserInfo .calledWith(this.user_id_1) @@ -918,7 +918,7 @@ describe('UpdatesManager', function() { .should.equal(true) }) - return it('should return the updates with the user info filled', function() { + return it('should return the updates with the user info filled', function () { return expect(this.results).to.deep.equal([ { meta: { @@ -948,8 +948,8 @@ describe('UpdatesManager', function() { }) }) - return describe('with invalid user ids', function() { - beforeEach(function(done) { + return describe('with invalid user ids', function () { + beforeEach(function (done) { this.updates = [ { meta: { @@ -966,7 +966,7 @@ describe('UpdatesManager', function() { ] this.WebApiManager.getUserInfo = (user_id, callback) => { if (callback == null) { - callback = function(error, userInfo) {} + callback = function (error, userInfo) {} } return callback(null, this.user_info[user_id]) } @@ -981,11 +981,11 @@ describe('UpdatesManager', function() { ) }) - it('should not call getUserInfo', function() { + it('should not call getUserInfo', function () { return this.WebApiManager.getUserInfo.called.should.equal(false) }) - return it('should return the updates without the user info filled', function() { + return it('should return the updates without the user info filled', function () { return expect(this.results).to.deep.equal([ { meta: {}, @@ -1000,14 +1000,14 @@ describe('UpdatesManager', function() { }) }) - return describe('_summarizeUpdates', function() { - beforeEach(function() { + return describe('_summarizeUpdates', function () { + beforeEach(function () { this.now = Date.now() this.user_1 = { id: 'mock-user-1' } return (this.user_2 = { id: 'mock-user-2' }) }) - it('should concat updates that are close in time', function() { + it('should concat updates that are close in time', function () { const result = this.UpdatesManager._summarizeUpdates([ { doc_id: 'doc-id-1', @@ -1046,7 +1046,7 @@ describe('UpdatesManager', function() { ]) }) - it('should leave updates that are far apart in time', function() { + it('should leave updates that are far apart in time', function () { const oneDay = 1000 * 60 * 60 * 24 const result = this.UpdatesManager._summarizeUpdates([ { @@ -1098,7 +1098,7 @@ describe('UpdatesManager', function() { ]) }) - it('should concat onto existing summarized updates', function() { + it('should concat onto existing summarized updates', function () { const result = this.UpdatesManager._summarizeUpdates( [ { @@ -1157,7 +1157,7 @@ describe('UpdatesManager', function() { ]) }) - it('should include null user values', function() { + it('should include null user values', function () { const result = this.UpdatesManager._summarizeUpdates([ { doc_id: 'doc-id-1', @@ -1195,7 +1195,7 @@ describe('UpdatesManager', function() { ]) }) - it('should include null user values, when the null is earlier in the updates list', function() { + it('should include null user values, when the null is earlier in the updates list', function () { const result = this.UpdatesManager._summarizeUpdates([ { doc_id: 'doc-id-1', @@ -1233,7 +1233,7 @@ describe('UpdatesManager', function() { ]) }) - it('should roll several null user values into one', function() { + it('should roll several null user values into one', function () { const result = this.UpdatesManager._summarizeUpdates([ { doc_id: 'doc-id-1', @@ -1280,7 +1280,7 @@ describe('UpdatesManager', function() { ]) }) - return it('should split updates before a big delete', function() { + return it('should split updates before a big delete', function () { const result = this.UpdatesManager._summarizeUpdates([ { doc_id: 'doc-id-1', diff --git a/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js b/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js index d62466b0b9..5aca308be2 100644 --- a/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js +++ b/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js @@ -16,8 +16,8 @@ const { expect } = chai const modulePath = '../../../../app/js/WebApiManager.js' const SandboxedModule = require('sandboxed-module') -describe('WebApiManager', function() { - beforeEach(function() { +describe('WebApiManager', function () { + beforeEach(function () { this.WebApiManager = SandboxedModule.require(modulePath, { requires: { requestretry: (this.request = {}), @@ -49,9 +49,9 @@ describe('WebApiManager', function() { return (this.project = { features: 'mock-features' }) }) - describe('getUserInfo', function() { - describe('successfully', function() { - beforeEach(function() { + describe('getUserInfo', function () { + describe('successfully', function () { + beforeEach(function () { this.body = JSON.stringify(this.user_info) this.request.get = sinon .stub() @@ -59,7 +59,7 @@ describe('WebApiManager', function() { return this.WebApiManager.getUserInfo(this.user_id, this.callback) }) - it('should get the user from the web api', function() { + it('should get the user from the web api', function () { return this.request.get .calledWithMatch({ url: `${this.settings.apis.web.url}/user/${this.user_id}/personal_info`, @@ -72,7 +72,7 @@ describe('WebApiManager', function() { .should.equal(true) }) - return it('should call the callback with only the email, id and names', function() { + return it('should call the callback with only the email, id and names', function () { return this.callback .calledWith(null, { id: this.user_id, @@ -84,8 +84,8 @@ describe('WebApiManager', function() { }) }) - describe('when the web API returns an error', function() { - beforeEach(function() { + describe('when the web API returns an error', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith( @@ -97,20 +97,20 @@ describe('WebApiManager', function() { return this.WebApiManager.getUserInfo(this.user_id, this.callback) }) - return it('should return an error to the callback', function() { + return it('should return an error to the callback', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) - describe('when the web returns a failure error code', function() { - beforeEach(function() { + describe('when the web returns a failure error code', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith(1, null, { statusCode: 500, attempts: 42 }, '') return this.WebApiManager.getUserInfo(this.user_id, this.callback) }) - return it('should return the callback with an error', function() { + return it('should return the callback with an error', function () { return this.callback .calledWith( sinon.match.has( @@ -122,23 +122,23 @@ describe('WebApiManager', function() { }) }) - return describe('when the user cannot be found', function() { - beforeEach(function() { + return describe('when the user cannot be found', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith(1, null, { statusCode: 404 }, 'nothing') return this.WebApiManager.getUserInfo(this.user_id, this.callback) }) - return it('should return a null value', function() { + return it('should return a null value', function () { return this.callback.calledWith(null, null).should.equal(true) }) }) }) - return describe('getProjectDetails', function() { - describe('successfully', function() { - beforeEach(function() { + return describe('getProjectDetails', function () { + describe('successfully', function () { + beforeEach(function () { this.body = JSON.stringify(this.project) this.request.get = sinon .stub() @@ -149,7 +149,7 @@ describe('WebApiManager', function() { ) }) - it('should get the project from the web api', function() { + it('should get the project from the web api', function () { return this.request.get .calledWithMatch({ url: `${this.settings.apis.web.url}/project/${this.project_id}/details`, @@ -162,13 +162,13 @@ describe('WebApiManager', function() { .should.equal(true) }) - return it('should call the callback with the project', function() { + return it('should call the callback with the project', function () { return this.callback.calledWith(null, this.project).should.equal(true) }) }) - describe('when the web API returns an error', function() { - beforeEach(function() { + describe('when the web API returns an error', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith( @@ -183,13 +183,13 @@ describe('WebApiManager', function() { ) }) - return it('should return an error to the callback', function() { + return it('should return an error to the callback', function () { return this.callback.calledWith(this.error).should.equal(true) }) }) - return describe('when the web returns a failure error code', function() { - beforeEach(function() { + return describe('when the web returns a failure error code', function () { + beforeEach(function () { this.request.get = sinon .stub() .callsArgWith(1, null, { statusCode: 500, attempts: 42 }, '') @@ -199,7 +199,7 @@ describe('WebApiManager', function() { ) }) - return it('should return the callback with an error', function() { + return it('should return the callback with an error', function () { return this.callback .calledWith( sinon.match.has(