Skip to content

Commit 3dbec93

Browse files
committed
eslint
1 parent dfe34d7 commit 3dbec93

5 files changed

Lines changed: 29 additions & 36 deletions

File tree

lib/hlc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ function create () {
9999
/**
100100
* Only for testing purposes
101101
*/
102-
function _reset() {
102+
function _reset () {
103103
highestRemoteHLC = 0;
104104
counter = 0;
105105
}
106106

107-
function getClockDriftMs() {
107+
function getClockDriftMs () {
108108
return toTimestamp(clockDriftHLC);
109109
}
110110

lib/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
140140
return;
141141
}
142142
db.backup(_backupFileName, {
143-
progress({ totalPages: t, remainingPages: r }) {
143+
progress ({ totalPages: t, remainingPages: r }) {
144144
const _progress = ((t - r) / t * 100).toFixed(1);
145145
debug('database backup progress: %s%', _progress);
146146
eventEmitter.emit('backup:progress', trigger, _backupFileName, _progress);
@@ -292,13 +292,13 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
292292
_getLastPatchInfo.push(_generateGetLastPatchInfoQuery('pending_patches'));
293293
_getPatchFromColumn.push(_generateGetPatchFromPendingTableQuery());
294294
// Get all tables ending with _patches except pending_patches
295-
const _patchTables = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%_patches' AND name != 'pending_patches'`).all();
295+
const _patchTables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%_patches' AND name != 'pending_patches'").all();
296296
// Generate merge patches query plan for each table
297297
for (const table of _patchTables) {
298298
const _tableName = table.name.slice(0, -8); // Remove '_patches' suffix
299299
try {
300300
// Check if index exists on _patchedAt column
301-
const _indexExists = db.prepare(`SELECT 1 FROM sqlite_master WHERE type='index' AND tbl_name=? AND sql LIKE '%_patchedAt%'`).get([table.name]);
301+
const _indexExists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='index' AND tbl_name=? AND sql LIKE '%_patchedAt%'").get([table.name]);
302302
if (!_indexExists) {
303303
console.warn(`Warning: Table ${table.name} is missing an index on _patchedAt column which may impact performance`);
304304
}
@@ -379,7 +379,7 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
379379
*
380380
* This function applies migration scripts (up or down) as needed to synchronize the database schema to the target version
381381
* as determined by the length of the `appMigrations` array. If the target version is less than the current database version,
382-
* down migrations are executed in reverse order. If the target version is greater than the current version, up migrations are
382+
* down migrations are executed in reverse order. If the target version is greater than the current version, up migrations are
383383
* applied in order. Migration changes are transactional.
384384
*
385385
* @param {Array<{ up: string, down: string }>} appMigrations Array of migration objects describing the changes required for each version.
@@ -439,8 +439,8 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
439439
* Detects missing patches since a given timestamp.
440440
*
441441
* This function analyzes the database for missing sequence IDs from a provided timestamp onward.
442-
* For each peer that has missing patches, it optionally updates that peer's statistics and
443-
* sends a retransmission request for the missing sequence range to the peer, provided a socket
442+
* For each peer that has missing patches, it optionally updates that peer's statistics and
443+
* sends a retransmission request for the missing sequence range to the peer, provided a socket
444444
* connection exists. Updates statistics for synchronized peers as well.
445445
*
446446
* TODO: Add test for case where peerSockets[peerId] does not exist but peerId exists in DB with missing patches.
@@ -530,7 +530,7 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
530530
* @param {Object} rowPatch - The row data to use as the delta for the generated patch.
531531
* @param {function(Error|null, string=):void} [callback] - Optional callback invoked with error or the session token.
532532
*/
533-
function upsert(tableName, rowPatch, callback) {
533+
function upsert (tableName, rowPatch, callback) {
534534
if (!dbVersion) {
535535
return callback(new Error('Database version is not set'));
536536
}
@@ -612,9 +612,9 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
612612
/**
613613
* Handles patches received from connected peers.
614614
*
615-
* This function processes an incoming patch message from a remote peer.
616-
* It ignores self-generated patches, handles version mismatches by storing
617-
* incompatible patches in the pending_patches table, and applies valid patches
615+
* This function processes an incoming patch message from a remote peer.
616+
* It ignores self-generated patches, handles version mismatches by storing
617+
* incompatible patches in the pending_patches table, and applies valid patches
618618
* to the relevant table. Patch application is debounced to batch updates.
619619
*
620620
* @param {Object} patch - The patch object received from a remote peer.
@@ -623,7 +623,7 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
623623
* @param {string} patch.tab - The table name to which the patch applies.
624624
* @param {number} patch.at - The timestamp when the patch was created.
625625
*/
626-
function _onPatchReceivedFromPeers(patch) {
626+
function _onPatchReceivedFromPeers (patch) {
627627
try {
628628
if (parseInt(patch.peer, 10) === myPeerId) {
629629
debug('Received patch from myself. Ignore it.');
@@ -820,7 +820,7 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
820820
_peerStat[LAST_SEQUENCE_ID] = msg.seq;
821821
_peerStat[LAST_PATCH_AT_TIMESTAMP] = msg.at;
822822
}
823-
// Otherwise, it's an old packet, or a ping (same sequence), if so do nothing.
823+
// Otherwise, it's an old packet, or a ping (same sequence), if so do nothing.
824824
// (Sequences can never go backward. If we receive a packet with a sequence less than the guaranteed one, we can ignore it—a double resend.)
825825
}
826826

@@ -918,7 +918,7 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
918918
* TODO: Return an error if the request is too old (patch table has been cleaned up)?
919919
*/
920920
function _onRequestForMissingPatchFromPeers (msg) {
921-
let _missingPatch = [];
921+
let _missingPatch;
922922
try {
923923
_missingPatch = globalStatements.getPatchFromColumn(msg.peer, msg.minSeq, msg.maxSeq);
924924
}
@@ -1012,9 +1012,9 @@ const SQLiteOnSteroid = (db, myPeerId = null, options) => {
10121012
/**
10131013
* Handles synchronization status update for a peer.
10141014
*
1015-
* This function is called when a peer is considered synced, i.e., when it has received
1015+
* This function is called when a peer is considered synced, i.e., when it has received
10161016
* the last contiguous sequence for that peer. When a peer becomes synced
1017-
* for the first time, it is removed from the `peerStartedNotSynced` set and
1017+
* for the first time, it is removed from the `peerStartedNotSynced` set and
10181018
* the 'synced' event is emitted for that peer.
10191019
*
10201020
* @param {number|string} peerId - ID of the peer that is now synced. May be a string if from a for-in loop.

test/test.global.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
const assert = require('assert');
22
const SQLiteOnSteroid = require('../lib/index.js');
3-
const path = require('path');
4-
const fs = require('fs');
53
const Database = require('better-sqlite3');
6-
const debug = require('debug');
74
const EventEmitter = require('events');
85
const { simplifyStats } = require('./helper.js');
96
const hlc = require('../lib/hlc.js');

test/test.main.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const hlc = require('../lib/hlc.js');
44
const path = require('path');
55
const fs = require('fs');
66
const Database = require('better-sqlite3');
7-
const debug = require('debug');
8-
const { simplifyStats, removeLastTimestampInStats } = require('./helper.js');
7+
const { removeLastTimestampInStats } = require('./helper.js');
98
const MockDate = require('mockdate');
109

1110
describe('main', function () {
@@ -657,15 +656,15 @@ describe('main', function () {
657656
app._onPatchReceivedFromPeers(_rowPatch1);
658657
}
659658
catch (e) {
660-
assert.fail('app._onPatchReceivedFromPeers should not throw an error');
659+
assert.fail(e);
661660
}
662661
try {
663-
app.upsert('testA', { id : 1, tenantId : ['Bad data'], name : '2d' }, (err) => {
662+
app.upsert('testA', { id : 1, tenantId : ['Bad data'], name : '2d' }, () => {
664663
done();
665664
});
666665
}
667666
catch (e) {
668-
assert.fail('app.upsert should not throw an error');
667+
assert.fail(e);
669668
}
670669
});
671670

@@ -716,14 +715,14 @@ describe('main', function () {
716715
_patchedAt : hlc.from(_constantTimestamp),
717716
_peerId : 20,
718717
_sequenceId : 1,
719-
delta : '{\"20\":[0,0]}',
718+
delta : '{"20":[0,0]}',
720719
patchVersion : 1,
721720
tableName : '_'
722721
}, {
723722
_patchedAt : hlc.from(_constantTimestamp),
724723
_peerId : 10,
725724
_sequenceId : 20,
726-
delta : '{\"20\":[1,1]}',
725+
delta : '{"20":[1,1]}',
727726
patchVersion : 2,
728727
tableName : '_'
729728
}]);
@@ -1088,7 +1087,7 @@ describe('main', function () {
10881087
app._onRequestForMissingPatchFromPeers({ type : 30 /* MISSING_PATCH */, peer : 2, minSeq : 2, maxSeq : 2, forPeer : 2 }); // missing A
10891088
}
10901089
catch (e) {
1091-
assert.fail('app._onRequestForMissingPatchFromPeers should not throw an error');
1090+
assert.fail(e);
10921091
}
10931092
done();
10941093
}, patchApplyDelayMs);
@@ -1288,7 +1287,7 @@ describe('main', function () {
12881287
it('should backup the database', function (done) {
12891288
// define a custom function to observe the provided backup file path and ensure it's called
12901289
let _capturedFileName;
1291-
function databaseBackupAbsolutePathFn(trigger, cb) {
1290+
function databaseBackupAbsolutePathFn (trigger, cb) {
12921291
const _date = new Date().toISOString().slice(0, 19).replace(/:/g, '-') + 'Z';
12931292
_capturedFileName = path.join(_testDir, `${trigger}-${_date}.sqlite`);
12941293
cb(_capturedFileName);
@@ -1313,11 +1312,11 @@ describe('main', function () {
13131312
});
13141313
});
13151314
it('should not create a backup if the function does not return a path for backup', function (done) {
1316-
function databaseBackupAbsolutePathFn(trigger, cb) {
1315+
function databaseBackupAbsolutePathFn (trigger, cb) {
13171316
cb(null);
13181317
}
13191318
const _app = SQLiteOnSteroid(db, 1, { databaseBackupAbsolutePathFn });
1320-
_app.backupDatabase('scheduled', function (err, trigger, backupFileName) {
1319+
_app.backupDatabase('scheduled', function (err) {
13211320
try {
13221321
assert.strictEqual(err.message, 'No backup file name for scheduled trigger');
13231322
assert.strictEqual(fs.existsSync(_testDir), true, 'Backup directory should exist');
@@ -1333,7 +1332,7 @@ describe('main', function () {
13331332
let gotCompleted = false;
13341333
let gotProgress = false;
13351334
// Use a real absolute path fn
1336-
function databaseBackupAbsolutePathFn(trigger, cb) {
1335+
function databaseBackupAbsolutePathFn (trigger, cb) {
13371336
const _date = new Date().toISOString().slice(0, 19).replace(/:/g, '-') + 'Z';
13381337
cb(path.join(_testDir, `${trigger}-${_date}.sqlite`));
13391338
}
@@ -1367,7 +1366,7 @@ describe('main', function () {
13671366
// No callback to backupDatabase, so events must fire
13681367
_app.backupDatabase('scheduled');
13691368
// Helper to call done when both events are received
1370-
function finishTestIfReady() {
1369+
function finishTestIfReady () {
13711370
if (gotCompleted && gotProgress) {
13721371
done();
13731372
}

test/test.migrate.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
const assert = require('assert');
22
const SQLiteOnSteroid = require('../lib/index.js');
3-
const path = require('path');
4-
const fs = require('fs');
53
const Database = require('better-sqlite3');
6-
const debug = require('debug');
74

85
describe('migrate', function () {
96
let db, app;

0 commit comments

Comments
 (0)