refactor: move crdt files into separate directory

This commit is contained in:
Tom French 2022-05-15 23:15:04 +01:00 committed by James Long
parent fc4f120487
commit 6967698d32
20 changed files with 36 additions and 31 deletions

1
packages/loot-core/bin/get-db-schema Executable file → Normal file
View file

@ -3,7 +3,6 @@ process.env.LOOT_DATA_DIR = __dirname + '/../../../../data';
import * as sqlite from '../platform/server/sqlite';
import * as db from '../server/db';
import { getMessages } from '../server/sync';
import Timestamp from '../server/timestamp';
let dbPath = process.argv[2];
let tables = [

View file

@ -4,7 +4,6 @@ import os from 'os';
import * as sqlite from '../src/platform/server/sqlite';
import * as db from '../src/server/db';
import { batchMessages, setSyncingMode } from '../src/server/sync';
import Timestamp from '../src/server/timestamp';
import { runQuery } from '../src/server/aql/schema/run-query';
import asyncStorage from '../src/platform/server/asyncStorage';
import { makeChild } from '../src/shared/transactions';

View file

@ -17,7 +17,7 @@ import * as prefs from './prefs';
import * as monthUtils from '../shared/months';
import * as cloudStorage from './cloud-storage';
import { setSyncingMode, batchMessages } from './sync';
import { getClock } from './timestamp';
import { getClock } from './crdt';
import { runMutator } from './mutators';
import { integerToAmount } from '../shared/util';
import { runQuery as aqlQuery } from './aql/schema/run-query';

View file

@ -2,7 +2,7 @@ import fc from 'fast-check';
import * as db from '../../db';
import query from '../../../shared/query';
import { batchMessages, setSyncingMode } from '../../sync/index';
import { setClock } from '../../timestamp';
import { setClock } from '../../crdt';
import { groupById } from '../../../shared/util';
import arbs from '../../../mocks/arbitrary-schema';
import { runQuery } from './run-query';

View file

@ -0,0 +1,4 @@
import * as merkle from "./merkle";
export { merkle };
export { getClock, setClock, makeClock, makeClientId, serializeClock, deserializeClock, Timestamp } from "./timestamp"

View file

@ -1,5 +1,5 @@
import * as merkle from './merkle';
import Timestamp from './timestamp';
import { Timestamp } from './timestamp';
function pretty(n) {
if (n < 60) {

View file

@ -1,5 +1,5 @@
import murmurhash from 'murmurhash';
const uuid = require('../platform/uuid');
const uuid = require('../../platform/uuid');
/**
* Hybrid Unique Logical Clock (HULC) timestamp generator
@ -81,7 +81,7 @@ const MAX_NODE_LENGTH = 16;
/**
* timestamp instance class
*/
export default class Timestamp {
export class Timestamp {
constructor(millis, counter, node) {
this._state = {
millis: millis,
@ -124,7 +124,7 @@ export default class Timestamp {
}
}
export class MutableTimestamp extends Timestamp {
class MutableTimestamp extends Timestamp {
setMillis(n) {
this._state.millis = n;
}

View file

@ -1,4 +1,4 @@
import Timestamp from './timestamp';
import { Timestamp } from './timestamp';
describe('Timestamp', function() {
let now = 0;

View file

@ -11,13 +11,14 @@ import {
payeeRuleModel
} from '../models';
import { groupById } from '../../shared/util';
import Timestamp, {
import {
makeClock,
setClock,
serializeClock,
deserializeClock,
makeClientId
} from '../timestamp';
makeClientId,
Timestamp
} from '../crdt';
import {
convertForInsert,
convertForUpdate,

View file

@ -30,8 +30,7 @@ import * as bankSync from './accounts/sync';
import * as link from './accounts/link';
import { uniqueFileName, idFromFileName } from './util/budget-name';
import { mutator, runHandler } from './mutators';
import * as timestamp from './timestamp';
import * as merkle from './merkle';
import { getClock, setClock, makeClock, makeClientId, serializeClock, deserializeClock, Timestamp, merkle } from './crdt';
import {
initialFullSync,
fullSync,
@ -1968,10 +1967,10 @@ async function loadBudget(id, appVersion, { showUpdate } = {}) {
//
// TODO: The client id should be stored elsewhere. It shouldn't
// work this way, but it's fine for now.
timestamp.getClock().timestamp.setNode(timestamp.makeClientId());
getClock().timestamp.setNode(makeClientId());
await db.runQuery(
'INSERT OR REPLACE INTO messages_clock (id, clock) VALUES (1, ?)',
[timestamp.serializeClock(timestamp.getClock())]
[serializeClock(getClock())]
);
await prefs.savePrefs({ resetClock: false });
@ -2253,7 +2252,9 @@ export const lib = {
// Expose CRDT mechanisms so server can use them
merkle,
timestamp,
timestamp: {
getClock, setClock, makeClock, makeClientId, serializeClock, deserializeClock, Timestamp
},
SyncProtoBuf: SyncPb
};

View file

@ -3,7 +3,7 @@ import * as prefs from './prefs';
import * as db from './db';
import * as budget from './budget/base';
import * as monthUtils from '../shared/months';
import { getClock, deserializeClock } from './timestamp';
import { getClock, deserializeClock } from './crdt';
import {
runHandler,
runMutator,

View file

@ -1,5 +1,5 @@
import { sendMessages } from './sync';
import Timestamp from './timestamp';
import { Timestamp } from './crdt';
const fs = require('../platform/server/fs');
let prefs = null;

View file

@ -11,12 +11,13 @@ import { triggerBudgetChanges, setType as setBudgetType } from '../budget/base';
import * as undo from '../undo';
import { runMutator } from '../mutators';
import { setIn, getIn } from '../../shared/util';
import Timestamp, {
import {
serializeClock,
deserializeClock,
getClock
} from '../timestamp';
import * as merkle from '../merkle';
getClock,
Timestamp,
merkle
} from '../crdt';
import * as encoder from './encoder';
import { getServer } from '../server-config';
import { rebuildMerkleHash } from './repair';

View file

@ -1,5 +1,5 @@
import { addSyncListener, applyMessages } from './index';
import Timestamp from '../timestamp';
import { Timestamp } from '../crdt';
function migrateParentIds(oldValues, newValues) {
newValues.forEach((items, table) => {

View file

@ -1,6 +1,5 @@
import * as db from '../db';
import Timestamp, { serializeClock, getClock } from '../timestamp';
import * as merkle from '../merkle';
import { serializeClock, getClock, Timestamp, merkle } from '../crdt';
export function rebuildMerkleHash() {
let rows = db.runQuery('SELECT timestamp FROM messages_crdt', [], true);

View file

@ -2,7 +2,7 @@ import * as prefs from '../prefs';
import * as db from '../db';
import * as sheet from '../sheet';
import * as sync from './index';
import Timestamp, { getClock } from '../timestamp';
import { getClock, Timestamp } from '../crdt';
import * as merkle from '../merkle';
import * as encoder from './encoder';
const jsc = require('jsverify');

View file

@ -1,7 +1,8 @@
import * as prefs from '../prefs';
import * as db from '../db';
import * as sheet from '../sheet';
import Timestamp, { getClock } from '../timestamp';
import { getClock, Timestamp } from '../crdt';
import { resolveName } from '../spreadsheet/util';
import { setSyncingMode, sendMessages, applyMessages, fullSync } from './index';
import * as encoder from './encoder';
const mockSyncServer = require('../tests/mockSyncServer');

View file

@ -1,5 +1,5 @@
import * as merkle from '../merkle';
import Timestamp, { makeClock } from '../timestamp';
import dateFns from 'date-fns';
import { makeClock, Timestamp, merkle } from '../crdt';
const defaultMockData = require('./mockData').basic;
const SyncPb = require('../sync/proto/sync_pb');

View file

@ -1,6 +1,6 @@
import { sendMessages } from './sync';
import { getIn } from '../shared/util';
import Timestamp from './timestamp';
import { Timestamp } from './crdt';
import { withMutatorContext, getMutatorContext } from './mutators';
const connection = require('../platform/server/connection');