refactor: move crdt files into separate directory
This commit is contained in:
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
1
packages/loot-core/bin/get-db-schema
Executable file → Normal 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 = [
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
4
packages/loot-core/src/server/crdt/index.js
Normal file
4
packages/loot-core/src/server/crdt/index.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import * as merkle from "./merkle";
|
||||
|
||||
export { merkle };
|
||||
export { getClock, setClock, makeClock, makeClientId, serializeClock, deserializeClock, Timestamp } from "./timestamp"
|
|
@ -1,5 +1,5 @@
|
|||
import * as merkle from './merkle';
|
||||
import Timestamp from './timestamp';
|
||||
import { Timestamp } from './timestamp';
|
||||
|
||||
function pretty(n) {
|
||||
if (n < 60) {
|
|
@ -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;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import Timestamp from './timestamp';
|
||||
import { Timestamp } from './timestamp';
|
||||
|
||||
describe('Timestamp', function() {
|
||||
let now = 0;
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
Loading…
Reference in a new issue