From 72bbb2d82be9d8550023900375e70eab351717c2 Mon Sep 17 00:00:00 2001 From: haad Date: Thu, 10 Mar 2016 09:30:57 +0100 Subject: [PATCH] Move OpTypes to Operation. Rename Operation to DBOperation in OrbitDB. --- src/OrbitDB.js | 13 ++++++------- src/db/Operation.js | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/OrbitDB.js b/src/OrbitDB.js index d284c97..fdf4e48 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -5,8 +5,7 @@ const EventEmitter = require('events').EventEmitter; const async = require('asyncawait/async'); const await = require('asyncawait/await'); const OrbitList = require('./list/OrbitList'); -const Operation = require('./db/Operation'); -const OpTypes = require('./db/OpTypes'); // TODO: move to Operation.Types +const DBOperation = require('./db/Operation'); const Post = require('./post/Post'); class OrbitDB { @@ -76,18 +75,18 @@ class OrbitDB { // Handle everything else as a string post = await(Post.create(this._ipfs, Post.Types.Message, data)); } - return await(this._write(channel, password, OpTypes.Add, post.Hash, post.Hash)); + return await(this._write(channel, password, DBOperation.Types.Add, post.Hash, post.Hash)); } // Sets a key-value pair put(channel, password, key, data) { const post = await(Post.create(this._ipfs, Post.Types.Message, data)); - return await(this._write(channel, password, OpTypes.Put, key, post.Hash)); + return await(this._write(channel, password, DBOperation.Types.Put, key, post.Hash)); } // Deletes an event based on hash (of the operation) del(channel, password, hash) { - return await(this._write(channel, password, OpTypes.Delete, hash, null)); + return await(this._write(channel, password, DBOperation.Types.Delete, hash, null)); } deleteChannel(channel, password) { @@ -104,7 +103,7 @@ class OrbitDB { const _createLWWSet = (item) => { const wasHandled = Lazy(handled).indexOf(item.key) > -1; if(!wasHandled) handled.push(item.key); - if(OpTypes.isInsert(item.op) && !wasHandled) return item; + if(DBOperation.Types.isInsert(item.op) && !wasHandled) return item; return null; }; @@ -136,7 +135,7 @@ class OrbitDB { // Write an op to the db _write(channel, password, operation, key, value) { - const hash = await(Operation.create(this._ipfs, this._logs[channel], this.user, operation, key, value)); + const hash = await(DBOperation.create(this._ipfs, this._logs[channel], this.user, operation, key, value)); this.events[channel].emit('write', channel, hash); return key; } diff --git a/src/db/Operation.js b/src/db/Operation.js index e35365f..bbcbefb 100644 --- a/src/db/Operation.js +++ b/src/db/Operation.js @@ -2,7 +2,7 @@ const async = require('asyncawait/async'); const await = require('asyncawait/await'); -const ipfsAPI = require('orbit-common/lib/ipfs-api-promised'); +const OpTypes = require('./OpTypes'); const OrbitDBItem = require('../post/OrbitDBItem'); const Post = require('../post/Post'); @@ -34,6 +34,10 @@ class Operation { }) return await(createOperationAsync()); } + + static get Types() { + return OpTypes; + } } module.exports = Operation;