From a94d2a791877c9af4c61abf71e2131c043e09367 Mon Sep 17 00:00:00 2001 From: haad Date: Thu, 6 Apr 2023 08:32:31 +0300 Subject: [PATCH] Renaming pass --- src/OrbitDB.js | 6 +-- src/db/{document-store.js => documents.js} | 6 +-- src/db/{event-store.js => events.js} | 2 +- src/db/index.js | 6 +-- ...value-persisted.js => keyvalue-indexed.js} | 4 +- src/identities/identities.js | 6 +-- src/identities/index.js | 2 + src/identities/providers/index.js | 2 +- .../providers/{orbitdb.js => publickey.js} | 8 ++-- src/oplog/{lamport-clock.js => clock.js} | 11 +++--- .../{sorting.js => conflict-resolution.js} | 2 +- src/oplog/entry.js | 6 +-- src/oplog/index.js | 4 +- src/oplog/log.js | 8 ++-- test/database-replication.test.js | 2 +- test/database.test.js | 4 +- test/db/document-store.test.js | 16 ++++---- test/db/event-store.test.js | 10 ++--- ...value-persisted.js => keyvalue-indexed.js} | 32 ++++++++-------- test/db/keyvalue.test.js | 18 ++++----- test/db/replication/document-store.test.js | 8 ++-- test/db/replication/event-store.test.js | 12 +++--- ...isted.test.js => keyvalue-indexed.test.js} | 16 ++++---- test/identities/identities.test.js | 5 +-- .../{lamport-clock.test.js => clock.test.js} | 4 +- ...ng.test.js => conflict-resolution.test.js} | 38 +++++++++---------- test/oplog/entry.test.js | 4 +- test/orbitdb-multiple-databases.test.js | 2 +- test/orbitdb-open.test.js | 14 +++---- 29 files changed, 130 insertions(+), 128 deletions(-) rename src/db/{document-store.js => documents.js} (91%) rename src/db/{event-store.js => events.js} (97%) rename src/db/{keyvalue-persisted.js => keyvalue-indexed.js} (92%) rename src/identities/providers/{orbitdb.js => publickey.js} (84%) rename src/oplog/{lamport-clock.js => clock.js} (73%) rename src/oplog/{sorting.js => conflict-resolution.js} (98%) rename test/db/{keyvalue-persisted.js => keyvalue-indexed.js} (81%) rename test/db/replication/{keyvalue-persisted.test.js => keyvalue-indexed.test.js} (82%) rename test/oplog/{lamport-clock.test.js => clock.test.js} (97%) rename test/oplog/{sorting.test.js => conflict-resolution.test.js} (75%) diff --git a/src/OrbitDB.js b/src/OrbitDB.js index ceabf5e..7723c38 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -1,5 +1,5 @@ import Database from './database.js' -import { EventStore, KeyValue, DocumentStore } from './db/index.js' +import { Events, KeyValue, Documents } from './db/index.js' import { Log, Entry } from './oplog/index.js' import { ComposedStorage, IPFSBlockStorage, LevelStorage, LRUStorage } from './storage/index.js' import KeyStore from './key-store.js' @@ -22,8 +22,8 @@ const hasher = sha256 // Mapping for 'database type' -> Store const databaseTypes = { - events: EventStore, - documents: DocumentStore, + events: Events, + documents: Documents, keyvalue: KeyValue } // diff --git a/src/db/document-store.js b/src/db/documents.js similarity index 91% rename from src/db/document-store.js rename to src/db/documents.js index bdc7b40..ad2d157 100644 --- a/src/db/document-store.js +++ b/src/db/documents.js @@ -1,4 +1,4 @@ -const DocumentStore = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically, indexBy = '_id' }) => { +const Documents = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically, indexBy = '_id' }) => { const database = await Database({ OpLog, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically }) const { addOperation, log } = database @@ -90,7 +90,7 @@ const DocumentStore = async ({ OpLog, Database, ipfs, identity, address, name, a return { ...database, - type: 'documentstore', + type: 'documents', put, del, get, @@ -101,4 +101,4 @@ const DocumentStore = async ({ OpLog, Database, ipfs, identity, address, name, a } } -export default DocumentStore +export default Documents diff --git a/src/db/event-store.js b/src/db/events.js similarity index 97% rename from src/db/event-store.js rename to src/db/events.js index 89fd040..2ff7f23 100644 --- a/src/db/event-store.js +++ b/src/db/events.js @@ -35,7 +35,7 @@ const Events = async ({ OpLog, Database, ipfs, identity, address, name, access, return { ...database, - type: 'eventstore', + type: 'events', put, add, get, diff --git a/src/db/index.js b/src/db/index.js index a5d34ec..632ad1a 100644 --- a/src/db/index.js +++ b/src/db/index.js @@ -1,4 +1,4 @@ -export { default as DocumentStore } from './document-store.js' -export { default as EventStore } from './event-store.js' -export { default as KeyValuePersisted } from './keyvalue-persisted.js' +export { default as Documents } from './documents.js' +export { default as Events } from './events.js' export { default as KeyValue } from './keyvalue.js' +export { default as KeyValueIndexed } from './keyvalue-indexed.js' diff --git a/src/db/keyvalue-persisted.js b/src/db/keyvalue-indexed.js similarity index 92% rename from src/db/keyvalue-persisted.js rename to src/db/keyvalue-indexed.js index 08c6bc5..12c5ebe 100644 --- a/src/db/keyvalue-persisted.js +++ b/src/db/keyvalue-indexed.js @@ -5,7 +5,7 @@ import PQueue from 'p-queue' const valueEncoding = 'json' -const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta }) => { +const KeyValueIndexed = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta }) => { const keyValueStore = await KeyValue({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta }) const { events, log } = keyValueStore @@ -80,4 +80,4 @@ const KeyValuePersisted = async ({ OpLog, Database, ipfs, identity, address, nam } } -export default KeyValuePersisted +export default KeyValueIndexed diff --git a/src/identities/identities.js b/src/identities/identities.js index 762f44b..5b92e8b 100644 --- a/src/identities/identities.js +++ b/src/identities/identities.js @@ -1,16 +1,16 @@ import Identity, { isIdentity, isEqual, decodeIdentity } from './identity.js' -import OrbitDBIdentityProvider from './providers/orbitdb.js' +import { PublicKeyIdentityProvider } from './providers/index.js' // import DIDIdentityProvider from './identity-providers/did.js' // import EthIdentityProvider from './identity-providers/ethereum.js' import KeyStore, { signMessage, verifyMessage } from '../key-store.js' import { LRUStorage, IPFSBlockStorage, MemoryStorage, ComposedStorage } from '../storage/index.js' import pathJoin from '../utils/path-join.js' -const DefaultProviderType = 'orbitdb' +const DefaultProviderType = PublicKeyIdentityProvider.type const DefaultIdentityKeysPath = pathJoin('./orbitdb', 'identities') const supportedTypes = { - orbitdb: OrbitDBIdentityProvider + publickey: PublicKeyIdentityProvider // [DIDIdentityProvider.type]: DIDIdentityProvider, // [EthIdentityProvider.type]: EthIdentityProvider } diff --git a/src/identities/index.js b/src/identities/index.js index fb40316..efaeaca 100644 --- a/src/identities/index.js +++ b/src/identities/index.js @@ -10,3 +10,5 @@ export { isIdentity, isEqual } from './identity.js' + +export { default as PublicKeyIdentityProvider } from './providers/publickey.js' diff --git a/src/identities/providers/index.js b/src/identities/providers/index.js index 217ec78..d772903 100644 --- a/src/identities/providers/index.js +++ b/src/identities/providers/index.js @@ -1,4 +1,4 @@ // export { default as DIDIdentityProvider } from './did.js' // export { default as EthIdentityProvider } from './ethereum.js' export { default as IdentityProvider } from './interface.js' -export { default as OrbitDBIdentityProvider } from './orbitdb.js' +export { default as PublicKeyIdentityProvider } from './publickey.js' diff --git a/src/identities/providers/orbitdb.js b/src/identities/providers/publickey.js similarity index 84% rename from src/identities/providers/orbitdb.js rename to src/identities/providers/publickey.js index b46cfe7..ed2a068 100644 --- a/src/identities/providers/orbitdb.js +++ b/src/identities/providers/publickey.js @@ -2,14 +2,14 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import IdentityProvider from './interface.js' import { signMessage, verifyMessage } from '../../key-store.js' -const type = 'orbitdb' +const type = 'publickey' -class OrbitDBIdentityProvider extends IdentityProvider { +class PublicKeyIdentityProvider extends IdentityProvider { constructor ({ keystore }) { super() if (!keystore) { - throw new Error('OrbitDBIdentityProvider requires a keystore parameter') + throw new Error('PublicKeyIdentityProvider requires a keystore parameter') } this._keystore = keystore @@ -46,4 +46,4 @@ class OrbitDBIdentityProvider extends IdentityProvider { } } -export default OrbitDBIdentityProvider +export default PublicKeyIdentityProvider diff --git a/src/oplog/lamport-clock.js b/src/oplog/clock.js similarity index 73% rename from src/oplog/lamport-clock.js rename to src/oplog/clock.js index c916b94..9753970 100644 --- a/src/oplog/lamport-clock.js +++ b/src/oplog/clock.js @@ -1,20 +1,21 @@ -class LamportClock { +/* Lamport Clock */ +class Clock { constructor (id, time) { this.id = id this.time = time || 0 } tick () { - return new LamportClock(this.id, ++this.time) + return new Clock(this.id, ++this.time) } merge (clock) { this.time = Math.max(this.time, clock.time) - return new LamportClock(this.id, this.time) + return new Clock(this.id, this.time) } clone () { - return new LamportClock(this.id, this.time) + return new Clock(this.id, this.time) } static compare (a, b) { @@ -29,4 +30,4 @@ class LamportClock { } } -export default LamportClock +export default Clock diff --git a/src/oplog/sorting.js b/src/oplog/conflict-resolution.js similarity index 98% rename from src/oplog/sorting.js rename to src/oplog/conflict-resolution.js index 98da9f8..06b52a4 100644 --- a/src/oplog/sorting.js +++ b/src/oplog/conflict-resolution.js @@ -1,4 +1,4 @@ -import Clock from './lamport-clock.js' +import Clock from './clock.js' /** * Sort two entries as Last-Write-Wins (LWW). diff --git a/src/oplog/entry.js b/src/oplog/entry.js index 6d9da38..53b5f10 100644 --- a/src/oplog/entry.js +++ b/src/oplog/entry.js @@ -1,4 +1,4 @@ -import Clock from './lamport-clock.js' +import Clock from './clock.js' import * as Block from 'multiformats/block' import * as dagCbor from '@ipld/dag-cbor' import { sha256 } from 'multiformats/hashes/sha2' @@ -18,7 +18,7 @@ const hashStringEncoding = base58btc * @param {Identity} identity The identity instance * @param {string} logId The unique identifier for this log * @param {*} data Data of the entry to be added. Can be any JSON.stringifyable data - * @param {LamportClock} [clock] The lamport clock + * @param {Clock} [clock] The clock * @param {Array} [next=[]] An array of CIDs as base58btc encoded strings * @param {Array} [refs=[]] An array of CIDs as base58btc encoded strings * @returns {Promise} @@ -40,7 +40,7 @@ const create = async (identity, id, payload, clock = null, next = [], refs = []) payload, // Can be any dag-cbor encodeable data next, // Array of strings of CIDs refs, // Array of strings of CIDs - clock, // Lamport Clock + clock, // Clock v: 2 // To tag the version of this data structure } diff --git a/src/oplog/index.js b/src/oplog/index.js index 6893808..7e582ac 100644 --- a/src/oplog/index.js +++ b/src/oplog/index.js @@ -1,4 +1,4 @@ export { default as Log, DefaultAccessController } from './log.js' export { default as Entry } from './entry.js' -export { default as Clock } from './lamport-clock.js' -export { default as Sorting } from './sorting.js' +export { default as Clock } from './clock.js' +export { default as ConflictResolution } from './conflict-resolution.js' diff --git a/src/oplog/log.js b/src/oplog/log.js index d485af8..02a9b33 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -1,12 +1,12 @@ import LRU from 'lru' import Entry from './entry.js' -import Clock from './lamport-clock.js' +import Clock from './clock.js' import Heads from './heads.js' -import Sorting from './sorting.js' +import ConflictResolution from './conflict-resolution.js' import MemoryStorage from '../storage/memory.js' import pMap from 'p-map' -const { LastWriteWins, NoZeroes } = Sorting +const { LastWriteWins, NoZeroes } = ConflictResolution const randomId = () => new Date().getTime().toString() const maxClockTimeReducer = (res, acc) => Math.max(res, acc.clock.time) @@ -72,7 +72,7 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora /** * Returns the clock of the log. - * @returns {LamportClock} + * @returns {Clock} */ const clock = async () => { // Find the latest clock from the heads diff --git a/test/database-replication.test.js b/test/database-replication.test.js index edd2f2c..eb422e5 100644 --- a/test/database-replication.test.js +++ b/test/database-replication.test.js @@ -23,7 +23,7 @@ describe('Database - Replication', function () { let testIdentity1, testIdentity2 let db1, db2 - const databaseId = 'documentstore-AAA' + const databaseId = 'documents-AAA' const accessController = { canAppend: async (entry) => { diff --git a/test/database.test.js b/test/database.test.js index ef59d0e..4ce6c53 100644 --- a/test/database.test.js +++ b/test/database.test.js @@ -22,7 +22,7 @@ describe('Database', function () { let testIdentity let db - const databaseId = 'documentstore-AAA' + const databaseId = 'database-AAA' const accessController = { canAppend: async (entry) => { @@ -59,7 +59,7 @@ describe('Database', function () { it('adds an operation', async () => { db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' }) - const expected = 'zdpuAqQ9TJpMhPShuT315m2D9LUBkBPy8YX9zatjEynd2suZv' + const expected = 'zdpuAwhx6xVpnMPUA7Q4JrvZsyoti5wZ18iDeFwBjPAwsRNof' const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' } const actual = await db.addOperation(op) diff --git a/test/db/document-store.test.js b/test/db/document-store.test.js index 7cbc5b7..34accc5 100644 --- a/test/db/document-store.test.js +++ b/test/db/document-store.test.js @@ -3,14 +3,14 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import * as IPFS from 'ipfs-core' import { Log, Entry, Database, KeyStore, Identities } from '../../src/index.js' -import { DocumentStore } from '../../src/db/index.js' +import { Documents } from '../../src/db/index.js' import config from '../config.js' import testKeysPath from '../fixtures/test-keys-path.js' const OpLog = { Log, Entry } const keysPath = './testkeys' -describe('DocumentStore Database', function () { +describe('Documents Database', function () { let ipfs let keystore let accessController @@ -18,7 +18,7 @@ describe('DocumentStore Database', function () { let testIdentity1 let db - const databaseId = 'documentstore-AAA' + const databaseId = 'documents-AAA' before(async () => { ipfs = await IPFS.create({ ...config.daemon1, repo: './ipfs1' }) @@ -45,7 +45,7 @@ describe('DocumentStore Database', function () { describe('Default index \'_id\'', () => { beforeEach(async () => { - db = await DocumentStore({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) }) afterEach(async () => { @@ -57,7 +57,7 @@ describe('DocumentStore Database', function () { it('creates a document store', async () => { strictEqual(db.address.toString(), databaseId) - strictEqual(db.type, 'documentstore') + strictEqual(db.type, 'documents') strictEqual(db.indexBy, '_id') }) @@ -149,7 +149,7 @@ describe('DocumentStore Database', function () { describe('Custom index \'doc\'', () => { beforeEach(async () => { - db = await DocumentStore({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController, indexBy: 'doc' }) + db = await Documents({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController, indexBy: 'doc' }) }) afterEach(async () => { @@ -161,7 +161,7 @@ describe('DocumentStore Database', function () { it('creates a document store', async () => { strictEqual(db.address.toString(), databaseId) - strictEqual(db.type, 'documentstore') + strictEqual(db.type, 'documents') strictEqual(db.indexBy, 'doc') }) @@ -252,7 +252,7 @@ describe('DocumentStore Database', function () { describe('Iterator', () => { before(async () => { - db = await DocumentStore({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Documents({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) }) after(async () => { diff --git a/test/db/event-store.test.js b/test/db/event-store.test.js index 9ad21c4..eafd69f 100644 --- a/test/db/event-store.test.js +++ b/test/db/event-store.test.js @@ -4,14 +4,14 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import * as IPFS from 'ipfs-core' import { Log, Entry, Database, KeyStore, Identities } from '../../src/index.js' -import { EventStore } from '../../src/db/index.js' +import { Events } from '../../src/db/index.js' import config from '../config.js' import testKeysPath from '../fixtures/test-keys-path.js' const OpLog = { Log, Entry } const keysPath = './testkeys' -describe('EventStore Database', function () { +describe('Events Database', function () { let ipfs let keystore let accessController @@ -19,7 +19,7 @@ describe('EventStore Database', function () { let testIdentity1 let db - const databaseId = 'eventstore-AAA' + const databaseId = 'events-AAA' before(async () => { ipfs = await IPFS.create({ ...config.daemon1, repo: './ipfs1' }) @@ -45,7 +45,7 @@ describe('EventStore Database', function () { }) beforeEach(async () => { - db = await EventStore({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await Events({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) }) afterEach(async () => { @@ -57,7 +57,7 @@ describe('EventStore Database', function () { it('creates an event store', async () => { strictEqual(db.address.toString(), databaseId) - strictEqual(db.type, 'eventstore') + strictEqual(db.type, 'events') }) it('puts an event', async () => { diff --git a/test/db/keyvalue-persisted.js b/test/db/keyvalue-indexed.js similarity index 81% rename from test/db/keyvalue-persisted.js rename to test/db/keyvalue-indexed.js index 1e849f2..32ac42a 100644 --- a/test/db/keyvalue-persisted.js +++ b/test/db/keyvalue-indexed.js @@ -5,14 +5,14 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import * as IPFS from 'ipfs-core' import { Log, Entry, Database, KeyStore, Identities } from '../../src/index.js' -import { KeyValuePersisted } from '../../src/db/index.js' +import { KeyValueIndexed } from '../../src/db/index.js' import config from '../config.js' import testKeysPath from '../fixtures/test-keys-path.js' const OpLog = { Log, Entry } const keysPath = './testkeys' -describe('KeyValuePersisted Database', function () { +describe('KeyValueIndexed Database', function () { let ipfs let keystore let accessController @@ -45,9 +45,9 @@ describe('KeyValuePersisted Database', function () { await rmrf('./ipfs1') }) - describe('Creating a KeyValuePersisted database', () => { + describe('Creating a KeyValueIndexed database', () => { beforeEach(async () => { - db = await KeyValuePersisted({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) }) afterEach(async () => { @@ -78,9 +78,9 @@ describe('KeyValuePersisted Database', function () { }) }) - describe('KeyValuePersisted database API', () => { + describe('KeyValueIndexed database API', () => { beforeEach(async () => { - db = await KeyValuePersisted({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) }) afterEach(async () => { @@ -91,14 +91,14 @@ describe('KeyValuePersisted Database', function () { }) it('sets a key/value pair', async () => { - const expected = 'zdpuAqEDJtUf3Kxg6qZgGv8XFqjtSyyxjF8qbz176Kcro5zwr' + const expected = 'zdpuAwr2JfE9TNMoXwupvsssCzemc3g8MTKRfVTG7ZS5gH6md' const actual = await db.set('key1', 'value1') strictEqual(actual, expected) }) it('puts a key/value pair', async () => { - const expected = 'zdpuAqEDJtUf3Kxg6qZgGv8XFqjtSyyxjF8qbz176Kcro5zwr' + const expected = 'zdpuAwr2JfE9TNMoXwupvsssCzemc3g8MTKRfVTG7ZS5gH6md' const actual = await db.put('key1', 'value1') strictEqual(actual, expected) @@ -173,13 +173,13 @@ describe('KeyValuePersisted Database', function () { it('returns all key/value pairs', async () => { const keyvalue = [ - { hash: 'zdpuAm6QEA29wFnd6re7X2XWe7AmrzVbsvdHhSPXci2CqXryw', key: 'key1', value: 'init' }, - { hash: 'zdpuAvfTQwogEAhEaAtb85ugEzxvfDVUnALoZeNbrz3s4jMYd', key: 'key2', value: true }, - { hash: 'zdpuB2ZCXwfkbgXQDHaP13rGSLVzZdZXuFPAk988VCZyMV1Er', key: 'key3', value: 'hello' }, - { hash: 'zdpuAnDHm5qkyzkdtEiedF2VwyuUvrgsgM7mCVrjLya3G7nFS', key: 'key4', value: 'friend' }, - { hash: 'zdpuB2XjqLhSEEB6CxCwCLWoas77Db6T9TJDNKcyX35kwbNmb', key: 'key5', value: '12345' }, - { hash: 'zdpuB1GyECVHxwFBxa9QYeTYRFJRLDnujyekhXAmStG26stU9', key: 'key6', value: 'empty' }, - { hash: 'zdpuAsj9ZgSCWSuRYFkQ56Eiffpi6j6761ueHHNwNf3VaZfms', key: 'key7', value: 'friend33' } + { hash: 'zdpuAnpWUWQFo7E7Q4fredrBdHWHTtSzMmo8CG7HRkWCu8Pbq', key: 'key1', value: 'init' }, + { hash: 'zdpuAwTM75uy1xbBJzHRHUeYTJR67rhHND1w6EpHVH6ThHdos', key: 'key2', value: true }, + { hash: 'zdpuAvYtscmvsQT7sgsJVsK7Gf7S3HweRJzs2D5TWBqz8wPGq', key: 'key3', value: 'hello' }, + { hash: 'zdpuAqAGnfa8eryZZm4z4UHcGQKZe4ACwoe1bwfq1AnJRwcPC', key: 'key4', value: 'friend' }, + { hash: 'zdpuAxHZs93Ys31jktM28GCwzrGP2vwuotr7MrSzLacGAS3dS', key: 'key5', value: '12345' }, + { hash: 'zdpuAuGJ6UoncMuTjkknG4ySjxvAgkdMiRNecR6nDbLoPFDXX', key: 'key6', value: 'empty' }, + { hash: 'zdpuAyi1oGLiYbH2UmRvXdGGC7z1vQYGE8oCvrfUvR5bGx6PN', key: 'key7', value: 'friend33' } ] for (const { key, value } of Object.values(keyvalue)) { @@ -197,7 +197,7 @@ describe('KeyValuePersisted Database', function () { describe('Iterator', () => { before(async () => { - db = await KeyValuePersisted({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) + db = await KeyValueIndexed({ OpLog, Database, ipfs, identity: testIdentity1, address: databaseId, accessController }) }) after(async () => { diff --git a/test/db/keyvalue.test.js b/test/db/keyvalue.test.js index 3696ae8..c1dec2a 100644 --- a/test/db/keyvalue.test.js +++ b/test/db/keyvalue.test.js @@ -83,14 +83,14 @@ describe('KeyValue Database', function () { }) it('sets a key/value pair', async () => { - const expected = 'zdpuAqEDJtUf3Kxg6qZgGv8XFqjtSyyxjF8qbz176Kcro5zwr' + const expected = 'zdpuAwr2JfE9TNMoXwupvsssCzemc3g8MTKRfVTG7ZS5gH6md' const actual = await db.set('key1', 'value1') strictEqual(actual, expected) }) it('puts a key/value pair', async () => { - const expected = 'zdpuAqEDJtUf3Kxg6qZgGv8XFqjtSyyxjF8qbz176Kcro5zwr' + const expected = 'zdpuAwr2JfE9TNMoXwupvsssCzemc3g8MTKRfVTG7ZS5gH6md' const actual = await db.put('key1', 'value1') strictEqual(actual, expected) @@ -165,13 +165,13 @@ describe('KeyValue Database', function () { it('returns all key/value pairs', async () => { const keyvalue = [ - { hash: 'zdpuAm6QEA29wFnd6re7X2XWe7AmrzVbsvdHhSPXci2CqXryw', key: 'key1', value: 'init' }, - { hash: 'zdpuAvfTQwogEAhEaAtb85ugEzxvfDVUnALoZeNbrz3s4jMYd', key: 'key2', value: true }, - { hash: 'zdpuB2ZCXwfkbgXQDHaP13rGSLVzZdZXuFPAk988VCZyMV1Er', key: 'key3', value: 'hello' }, - { hash: 'zdpuAnDHm5qkyzkdtEiedF2VwyuUvrgsgM7mCVrjLya3G7nFS', key: 'key4', value: 'friend' }, - { hash: 'zdpuB2XjqLhSEEB6CxCwCLWoas77Db6T9TJDNKcyX35kwbNmb', key: 'key5', value: '12345' }, - { hash: 'zdpuB1GyECVHxwFBxa9QYeTYRFJRLDnujyekhXAmStG26stU9', key: 'key6', value: 'empty' }, - { hash: 'zdpuAsj9ZgSCWSuRYFkQ56Eiffpi6j6761ueHHNwNf3VaZfms', key: 'key7', value: 'friend33' } + { hash: 'zdpuAnpWUWQFo7E7Q4fredrBdHWHTtSzMmo8CG7HRkWCu8Pbq', key: 'key1', value: 'init' }, + { hash: 'zdpuAwTM75uy1xbBJzHRHUeYTJR67rhHND1w6EpHVH6ThHdos', key: 'key2', value: true }, + { hash: 'zdpuAvYtscmvsQT7sgsJVsK7Gf7S3HweRJzs2D5TWBqz8wPGq', key: 'key3', value: 'hello' }, + { hash: 'zdpuAqAGnfa8eryZZm4z4UHcGQKZe4ACwoe1bwfq1AnJRwcPC', key: 'key4', value: 'friend' }, + { hash: 'zdpuAxHZs93Ys31jktM28GCwzrGP2vwuotr7MrSzLacGAS3dS', key: 'key5', value: '12345' }, + { hash: 'zdpuAuGJ6UoncMuTjkknG4ySjxvAgkdMiRNecR6nDbLoPFDXX', key: 'key6', value: 'empty' }, + { hash: 'zdpuAyi1oGLiYbH2UmRvXdGGC7z1vQYGE8oCvrfUvR5bGx6PN', key: 'key7', value: 'friend33' } ] for (const { key, value } of Object.values(keyvalue)) { diff --git a/test/db/replication/document-store.test.js b/test/db/replication/document-store.test.js index 83dbcd7..fb0b0c4 100644 --- a/test/db/replication/document-store.test.js +++ b/test/db/replication/document-store.test.js @@ -3,7 +3,7 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import * as IPFS from 'ipfs-core' import { Log, Entry, Database, KeyStore, Identities } from '../../../src/index.js' -import { DocumentStore } from '../../../src/db/index.js' +import { Documents } from '../../../src/db/index.js' import config from '../../config.js' import testKeysPath from '../../fixtures/test-keys-path.js' import connectPeers from '../../utils/connect-nodes.js' @@ -21,7 +21,7 @@ describe('Documents Database Replication', function () { let testIdentity1, testIdentity2 let db1, db2 - const databaseId = 'documentstore-AAA' + const databaseId = 'documents-AAA' const accessController = { canAppend: async (entry) => { @@ -64,8 +64,8 @@ describe('Documents Database Replication', function () { }) beforeEach(async () => { - db1 = await DocumentStore({ OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await DocumentStore({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Documents({ OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + db2 = await Documents({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) }) afterEach(async () => { diff --git a/test/db/replication/event-store.test.js b/test/db/replication/event-store.test.js index 8485f67..d24d637 100644 --- a/test/db/replication/event-store.test.js +++ b/test/db/replication/event-store.test.js @@ -3,7 +3,7 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import * as IPFS from 'ipfs-core' import { Log, Entry, Database, KeyStore, Identities } from '../../../src/index.js' -import { EventStore } from '../../../src/db/index.js' +import { Events } from '../../../src/db/index.js' import config from '../../config.js' import testKeysPath from '../../fixtures/test-keys-path.js' import connectPeers from '../../utils/connect-nodes.js' @@ -100,8 +100,8 @@ describe('Events Database Replication', function () { console.error(err) } - db1 = await EventStore({ OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await EventStore({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Events({ OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + db2 = await Events({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) db2.events.on('join', onConnected) db2.events.on('update', onUpdate) @@ -131,8 +131,8 @@ describe('Events Database Replication', function () { }) it('loads the database after replication', async () => { - db1 = await EventStore({ OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - db2 = await EventStore({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db1 = await Events({ OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + db2 = await Events({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) let replicated = false let expectedEntryHash = null @@ -172,7 +172,7 @@ describe('Events Database Replication', function () { await db2.close() - db2 = await EventStore({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + db2 = await Events({ OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) const all2 = [] for await (const event of db2.iterator()) { diff --git a/test/db/replication/keyvalue-persisted.test.js b/test/db/replication/keyvalue-indexed.test.js similarity index 82% rename from test/db/replication/keyvalue-persisted.test.js rename to test/db/replication/keyvalue-indexed.test.js index 255e6ce..652b25e 100644 --- a/test/db/replication/keyvalue-persisted.test.js +++ b/test/db/replication/keyvalue-indexed.test.js @@ -3,7 +3,7 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import * as IPFS from 'ipfs-core' import { Log, Entry, Database, KeyStore, Identities } from '../../../src/index.js' -import { KeyValue, KeyValuePersisted } from '../../../src/db/index.js' +import { KeyValue, KeyValueIndexed } from '../../../src/db/index.js' import config from '../../config.js' import testKeysPath from '../../fixtures/test-keys-path.js' import connectPeers from '../../utils/connect-nodes.js' @@ -12,7 +12,7 @@ import waitFor from '../../utils/wait-for.js' const OpLog = { Log, Entry } const keysPath = './testkeys' -describe('KeyValue-persisted Database Replication', function () { +describe('KeyValueIndexed Database Replication', function () { this.timeout(30000) let ipfs1, ipfs2 @@ -89,8 +89,8 @@ describe('KeyValue-persisted Database Replication', function () { console.error(err) } - kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv2 = await KeyValueIndexed({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) kv2.events.on('join', onConnected) kv2.events.on('update', onUpdate) @@ -156,8 +156,8 @@ describe('KeyValue-persisted Database Replication', function () { console.error(err) } - kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv2 = await KeyValueIndexed({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) kv2.events.on('join', onConnected) kv2.events.on('update', onUpdate) @@ -179,8 +179,8 @@ describe('KeyValue-persisted Database Replication', function () { await kv1.close() await kv2.close() - kv1 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) - kv2 = await KeyValuePersisted({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) + kv1 = await KeyValueIndexed({ KeyValue, OpLog, Database, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' }) + kv2 = await KeyValueIndexed({ KeyValue, OpLog, Database, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' }) const value0 = await kv2.get('init') deepStrictEqual(value0, true) diff --git a/test/identities/identities.test.js b/test/identities/identities.test.js index ec8610a..9315dc2 100644 --- a/test/identities/identities.test.js +++ b/test/identities/identities.test.js @@ -3,11 +3,10 @@ import rmrf from 'rimraf' import { copy } from 'fs-extra' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js' -import Identities, { addIdentityProvider } from '../../src/identities/identities.js' -import Identity from '../../src/identities/identity.js' +import { Identities, addIdentityProvider, Identity, PublicKeyIdentityProvider } from '../../src/identities/index.js' import testKeysPath from '../fixtures/test-keys-path.js' -const type = 'orbitdb' +const type = PublicKeyIdentityProvider.type const keysPath = './testkeys' describe('Identities', function () { diff --git a/test/oplog/lamport-clock.test.js b/test/oplog/clock.test.js similarity index 97% rename from test/oplog/lamport-clock.test.js rename to test/oplog/clock.test.js index f40eb6e..1afac73 100644 --- a/test/oplog/lamport-clock.test.js +++ b/test/oplog/clock.test.js @@ -1,7 +1,7 @@ -import Clock from '../../src/oplog/lamport-clock.js' +import Clock from '../../src/oplog/clock.js' import { strictEqual } from 'assert' -describe('Lamport Clock', () => { +describe('Clock', () => { it('creates a new clock', () => { const id = 'A' const time = 0 diff --git a/test/oplog/sorting.test.js b/test/oplog/conflict-resolution.test.js similarity index 75% rename from test/oplog/sorting.test.js rename to test/oplog/conflict-resolution.test.js index ccd569e..615a949 100644 --- a/test/oplog/sorting.test.js +++ b/test/oplog/conflict-resolution.test.js @@ -1,13 +1,13 @@ import { strictEqual, deepStrictEqual } from 'assert' -import Clock from '../../src/oplog/lamport-clock.js' -import Sorting from '../../src/oplog/sorting.js' +import Clock from '../../src/oplog/clock.js' +import ConflictResolution from '../../src/oplog/conflict-resolution.js' -describe('Sorting', () => { +describe('ConflictResolution', () => { describe('NoZeroes', () => { it('passed function cannot return 0', () => { let err const func = (a, b) => { return 0 } - const sortFn = Sorting.NoZeroes(func) + const sortFn = ConflictResolution.NoZeroes(func) const expected = 'Error: Your log\'s tiebreaker function, func, has returned zero and therefore cannot be' const record1 = 1 @@ -33,21 +33,21 @@ describe('Sorting', () => { const expected = -1 const record1 = { clock: new Clock('A') } const record2 = { clock: new Clock('B') } - strictEqual(Sorting.SortByClockId(record1, record2, fallbackFn), expected) + strictEqual(ConflictResolution.SortByClockId(record1, record2, fallbackFn), expected) }) it('returns 1 when first clock\'s id is greater than second clock\'s', () => { const expected = 1 const record1 = { clock: new Clock('B') } const record2 = { clock: new Clock('A') } - strictEqual(Sorting.SortByClockId(record1, record2, fallbackFn), expected) + strictEqual(ConflictResolution.SortByClockId(record1, record2, fallbackFn), expected) }) it('returns the clock when clocks have the same id', () => { const expected = { clock: new Clock('A') } const record1 = { clock: new Clock('A') } const record2 = { clock: new Clock('A') } - deepStrictEqual(Sorting.SortByClockId(record1, record2, fallbackFn), expected) + deepStrictEqual(ConflictResolution.SortByClockId(record1, record2, fallbackFn), expected) }) }) @@ -61,21 +61,21 @@ describe('Sorting', () => { const expected = -1 const record1 = { clock: new Clock('A', 1) } const record2 = { clock: new Clock('B', 2) } - strictEqual(Sorting.SortByClocks(record1, record2, fallbackFn), expected) + strictEqual(ConflictResolution.SortByClocks(record1, record2, fallbackFn), expected) }) it('returns 1 when a\'s time is greater than b\'s', () => { const expected = 1 const record1 = { clock: new Clock('A', 2) } const record2 = { clock: new Clock('B', 1) } - strictEqual(Sorting.SortByClocks(record1, record2, fallbackFn), expected) + strictEqual(ConflictResolution.SortByClocks(record1, record2, fallbackFn), expected) }) it('returns -1 when a\'s time is equal to b\'s', () => { const expected = -1 const record1 = { clock: new Clock('A', 1) } const record2 = { clock: new Clock('B', 1) } - strictEqual(Sorting.SortByClocks(record1, record2, fallbackFn), expected) + strictEqual(ConflictResolution.SortByClocks(record1, record2, fallbackFn), expected) }) }) @@ -84,32 +84,32 @@ describe('Sorting', () => { const expected = -1 const record1 = { clock: new Clock('A', 1) } const record2 = { clock: new Clock('B', 2) } - strictEqual(Sorting.LastWriteWins(record1, record2), expected) + strictEqual(ConflictResolution.LastWriteWins(record1, record2), expected) }) it('returns 1 when a\'s time is greater than b\'s', () => { const expected = 1 const record1 = { clock: new Clock('A', 2) } const record2 = { clock: new Clock('B', 1) } - strictEqual(Sorting.LastWriteWins(record1, record2), expected) + strictEqual(ConflictResolution.LastWriteWins(record1, record2), expected) }) it('returns -1 when a\'s time is equal to b\'s', () => { const expected = -1 const record1 = { clock: new Clock('A', 1) } const record2 = { clock: new Clock('B', 1) } - strictEqual(Sorting.LastWriteWins(record1, record2), expected) + strictEqual(ConflictResolution.LastWriteWins(record1, record2), expected) }) it('returns the clock when a and b are the same', () => { const expected = { clock: new Clock('A') } const record1 = { clock: new Clock('A') } const record2 = { clock: new Clock('A') } - deepStrictEqual(Sorting.LastWriteWins(record1, record2), expected) + deepStrictEqual(ConflictResolution.LastWriteWins(record1, record2), expected) }) }) - describe('Sorting records', () => { + describe('ConflictResolution records', () => { it('sorts by clock time', () => { const expected = [ { clock: new Clock('A', 1) }, @@ -125,7 +125,7 @@ describe('Sorting', () => { { clock: new Clock('B', 2) } ] - deepStrictEqual(records.sort(Sorting.LastWriteWins), expected) + deepStrictEqual(records.sort(ConflictResolution.LastWriteWins), expected) }) it('sorts by clock time when id is the same', () => { @@ -143,7 +143,7 @@ describe('Sorting', () => { { clock: new Clock('A', 2) } ] - deepStrictEqual(records.sort(Sorting.LastWriteWins), expected) + deepStrictEqual(records.sort(ConflictResolution.LastWriteWins), expected) }) it('sorts by clock id', () => { @@ -161,7 +161,7 @@ describe('Sorting', () => { { clock: new Clock('B') } ] - deepStrictEqual(records.sort(Sorting.LastWriteWins), expected) + deepStrictEqual(records.sort(ConflictResolution.LastWriteWins), expected) }) it('sorts the same clock', () => { @@ -179,7 +179,7 @@ describe('Sorting', () => { { clock: new Clock('A') } ] - deepStrictEqual(records.sort(Sorting.LastWriteWins), expected) + deepStrictEqual(records.sort(ConflictResolution.LastWriteWins), expected) }) }) }) diff --git a/test/oplog/entry.test.js b/test/oplog/entry.test.js index c789834..bb04e1a 100644 --- a/test/oplog/entry.test.js +++ b/test/oplog/entry.test.js @@ -30,7 +30,7 @@ describe('Entry', function () { describe('create', () => { it('creates a an empty entry', async () => { - const expectedHash = 'zdpuAyX6yUV5BQMGPaLEvQRa5SDxebEYvQPni6FHyPsRZ7San' + const expectedHash = 'zdpuAsKzwUEa8cz9pkJxxFMxLuP3cutA9PDGoLZytrg4RSVEa' const entry = await create(testIdentity, 'A', 'hello') strictEqual(entry.hash, expectedHash) strictEqual(entry.id, 'A') @@ -43,7 +43,7 @@ describe('Entry', function () { }) it('creates a entry with payload', async () => { - const expectedHash = 'zdpuAs4V7Wq9smdoHrzYQA46nFfqCF8iWaz98rZJC56bst3kx' + const expectedHash = 'zdpuAmthfqpHRQjdSpKN5etr1GrreJb7QcU1Hshm6pERnzsxi' const payload = 'hello world' const entry = await create(testIdentity, 'A', payload) strictEqual(entry.hash, expectedHash) diff --git a/test/orbitdb-multiple-databases.test.js b/test/orbitdb-multiple-databases.test.js index e6e153c..2c349b7 100644 --- a/test/orbitdb-multiple-databases.test.js +++ b/test/orbitdb-multiple-databases.test.js @@ -12,7 +12,7 @@ const dbPath2 = './orbitdb/tests/multiple-databases/2' const databaseInterfaces = [ { - name: 'event-store', + name: 'events', open: async (orbitdb, address, options) => await orbitdb.open(address, options), write: async (db, index) => { await db.add('hello' + index) diff --git a/test/orbitdb-open.test.js b/test/orbitdb-open.test.js index 8e9f037..5d474f1 100644 --- a/test/orbitdb-open.test.js +++ b/test/orbitdb-open.test.js @@ -4,7 +4,7 @@ import fs from 'fs' import path from 'path' import * as IPFS from 'ipfs-core' import { OrbitDB, isValidAddress } from '../src/index.js' -import { KeyValuePersisted } from '../src/db/index.js' +import { KeyValueIndexed } from '../src/db/index.js' import config from './config.js' import connectPeers from './utils/connect-nodes.js' import waitFor from './utils/wait-for.js' @@ -105,7 +105,7 @@ describe('Open databases', function () { }) it('has a type that equals the database type', async () => { - strictEqual(db.type, 'eventstore') + strictEqual(db.type, 'events') }) it('has a put function', async () => { @@ -199,7 +199,7 @@ describe('Open databases', function () { it('returns all entries in the database', async () => { db = await orbitdb1.open('helloworld') - strictEqual(db.type, 'eventstore') + strictEqual(db.type, 'events') strictEqual(db.name, 'helloworld') const expected = [] @@ -250,7 +250,7 @@ describe('Open databases', function () { it('returns all entries in the database', async () => { db = await orbitdb2.open(address) - strictEqual(db.type, 'eventstore') + strictEqual(db.type, 'events') strictEqual(db.name, 'helloworld2') const expected = [] @@ -416,12 +416,12 @@ describe('Open databases', function () { deepStrictEqual(all, expected) }) - it('opens the database with a custom Store - KeyValuePersisted', async () => { + it('opens the database with a custom Store - KeyValueIndexed', async () => { if (db) { await db.close() } - db = await orbitdb1.open(address, { Store: KeyValuePersisted }) + db = await orbitdb1.open(address, { Store: KeyValueIndexed }) strictEqual(db.type, 'keyvalue') strictEqual(db.name, 'helloworld') @@ -470,7 +470,7 @@ describe('Open databases', function () { it('returns all entries in the database', async () => { db = await orbitdb1.open(address) - strictEqual(db.type, 'documentstore') + strictEqual(db.type, 'documents') strictEqual(db.name, 'helloworld') const expected = []