From 3901e15260dd22045572bd0dcfd7731e65c7c93f Mon Sep 17 00:00:00 2001 From: haad Date: Wed, 20 Jan 2016 16:05:47 +0800 Subject: [PATCH] Move source files to src/. Update package.json. --- README.md | 13 +++++++++++++ examples/readMessages.js | 4 ++-- examples/writeMessages.js | 4 ++-- package.json | 16 ++++++++-------- BetterRequest.js => src/BetterRequest.js | 0 Encryption.js => src/Encryption.js | 0 HashCacheClient.js => src/HashCacheClient.js | 0 HashCacheItem.js => src/HashCacheItem.js | 0 ItemTypes.js => src/ItemTypes.js | 0 Keystore.js => src/Keystore.js | 0 MetaInfo.js => src/MetaInfo.js | 0 OrbitClient.js => src/OrbitClient.js | 4 ++-- Post.js => src/Post.js | 0 TODO.md.js => src/TODO.md.js | 0 Timer.js => src/Timer.js | 0 ipfs-api-promised.js => src/ipfs-api-promised.js | 0 ipfs-daemon.js => src/ipfs-daemon.js | 0 test/orbit-client-tests.js | 12 +++++++----- 18 files changed, 34 insertions(+), 19 deletions(-) rename BetterRequest.js => src/BetterRequest.js (100%) rename Encryption.js => src/Encryption.js (100%) rename HashCacheClient.js => src/HashCacheClient.js (100%) rename HashCacheItem.js => src/HashCacheItem.js (100%) rename ItemTypes.js => src/ItemTypes.js (100%) rename Keystore.js => src/Keystore.js (100%) rename MetaInfo.js => src/MetaInfo.js (100%) rename OrbitClient.js => src/OrbitClient.js (99%) rename Post.js => src/Post.js (100%) rename TODO.md.js => src/TODO.md.js (100%) rename Timer.js => src/Timer.js (100%) rename ipfs-api-promised.js => src/ipfs-api-promised.js (100%) rename ipfs-daemon.js => src/ipfs-daemon.js (100%) diff --git a/README.md b/README.md index 6573872..05034bf 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,19 @@ async(() => { })(); ``` +### Development +#### Run Tests +*Note! Before running tests, make sure orbit-server is running* + +``` +npm test +``` + +Keep tests running while development: +``` +mocha -w +``` + ### TODO - Tests for remove(), put() and get() - Local caching of messages diff --git a/examples/readMessages.js b/examples/readMessages.js index c63e244..f25ca19 100644 --- a/examples/readMessages.js +++ b/examples/readMessages.js @@ -1,8 +1,8 @@ 'use strict'; var async = require('asyncawait/async'); -var OrbitClient = require('../OrbitClient'); -var Timer = require('../Timer'); +var OrbitClient = require('../src/OrbitClient'); +var Timer = require('../src/Timer'); var host = 'localhost:3006'; var username = 'testrunner'; diff --git a/examples/writeMessages.js b/examples/writeMessages.js index c4cfdd5..639d52b 100644 --- a/examples/writeMessages.js +++ b/examples/writeMessages.js @@ -1,8 +1,8 @@ 'use strict'; var async = require('asyncawait/async'); -var OrbitClient = require('../OrbitClient'); -var Timer = require('../Timer'); +var OrbitClient = require('../src/OrbitClient'); +var Timer = require('../src/Timer'); var host = 'localhost:3006'; var username = 'testrunner'; diff --git a/package.json b/package.json index 4964123..f6ae844 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,13 @@ { "name": "orbit-client", - "version": "1.0.0", - "description": "A client module to communicate with an Orbit network", - "main": "OrbitClient.js", - "scripts": { - "test": "mocha" - }, + "version": "0.1.0", + "description": "Event Log and KeyValue Store on IPFS", "author": "Haad", - "license": "ISC", + "license": "MIT", "engines" : { "node" : "^4.x.x" - }, + }, + "main": "src/OrbitClient.js", "dependencies": { "asyncawait": "^1.0.1", "bluebird": "^3.1.1", @@ -20,5 +17,8 @@ }, "devDependencies": { "mocha": "^2.3.4" + }, + "scripts": { + "test": "mocha" } } diff --git a/BetterRequest.js b/src/BetterRequest.js similarity index 100% rename from BetterRequest.js rename to src/BetterRequest.js diff --git a/Encryption.js b/src/Encryption.js similarity index 100% rename from Encryption.js rename to src/Encryption.js diff --git a/HashCacheClient.js b/src/HashCacheClient.js similarity index 100% rename from HashCacheClient.js rename to src/HashCacheClient.js diff --git a/HashCacheItem.js b/src/HashCacheItem.js similarity index 100% rename from HashCacheItem.js rename to src/HashCacheItem.js diff --git a/ItemTypes.js b/src/ItemTypes.js similarity index 100% rename from ItemTypes.js rename to src/ItemTypes.js diff --git a/Keystore.js b/src/Keystore.js similarity index 100% rename from Keystore.js rename to src/Keystore.js diff --git a/MetaInfo.js b/src/MetaInfo.js similarity index 100% rename from MetaInfo.js rename to src/MetaInfo.js diff --git a/OrbitClient.js b/src/OrbitClient.js similarity index 99% rename from OrbitClient.js rename to src/OrbitClient.js index 9129314..3960009 100644 --- a/OrbitClient.js +++ b/src/OrbitClient.js @@ -48,7 +48,7 @@ class OrbitClient { [Symbol.iterator]() { return this; }, - next: () => { + next() { let item = { value: null, done: true }; if(currentIndex < messages.length) { item = { value: messages[currentIndex], done: false }; @@ -81,7 +81,7 @@ class OrbitClient { if(lt || lte) { startFromHash = lte ? lte : lt; } else { - var channel = await (this.client.linkedList(channel, password).head()) + var channel = await (this.client.linkedList(channel, password).head()); startFromHash = channel.head ? channel.head : null; } diff --git a/Post.js b/src/Post.js similarity index 100% rename from Post.js rename to src/Post.js diff --git a/TODO.md.js b/src/TODO.md.js similarity index 100% rename from TODO.md.js rename to src/TODO.md.js diff --git a/Timer.js b/src/Timer.js similarity index 100% rename from Timer.js rename to src/Timer.js diff --git a/ipfs-api-promised.js b/src/ipfs-api-promised.js similarity index 100% rename from ipfs-api-promised.js rename to src/ipfs-api-promised.js diff --git a/ipfs-daemon.js b/src/ipfs-daemon.js similarity index 100% rename from ipfs-daemon.js rename to src/ipfs-daemon.js diff --git a/test/orbit-client-tests.js b/test/orbit-client-tests.js index 84d6755..0bf5cab 100644 --- a/test/orbit-client-tests.js +++ b/test/orbit-client-tests.js @@ -3,8 +3,8 @@ var assert = require('assert'); var async = require('asyncawait/async'); var await = require('asyncawait/await'); -var encryption = require('../Encryption'); -var OrbitClient = require('../OrbitClient'); +var encryption = require('../src/Encryption'); +var OrbitClient = require('../src/OrbitClient'); // var mockServerAddresses = [ // "localhost", @@ -35,7 +35,7 @@ describe('Orbit Client', () => { let head = ''; let second = ''; let items = []; - let channel = 'abcde'; + let channel = 'abcdefgh'; before(function(done) { // logger.setLevel('ERROR'); @@ -58,7 +58,7 @@ describe('Orbit Client', () => { // } var start = () => new Promise(async((resolve, reject) => { orbit = OrbitClient.connect(host, username, password); - // orbit.channel(channel, 'hello').setMode({ mode: "-r" }) + orbit.channel(channel, '').delete(); resolve(); })); start().then(done); @@ -157,6 +157,7 @@ describe('Orbit Client', () => { describe('Insert', function() { it('adds an item to an empty channel', async((done) => { try { + orbit.channel(channel, '').delete(); head = orbit.channel(channel, '').add('hello'); assert.notEqual(head, null); assert.equal(head.startsWith('Qm'), true); @@ -169,6 +170,7 @@ describe('Orbit Client', () => { it('adds a new item to a channel with one item', async((done) => { try { + var v = orbit.channel(channel, '').iterator().collect(); second = orbit.channel(channel, '').add('hello'); assert.notEqual(second, null); assert.notEqual(second, head); @@ -526,7 +528,7 @@ describe('Orbit Client', () => { it('can\'t read with wrong password', async((done) => { try { - var modes = orbit.channel(channel, '').iterator(); + var modes = orbit.channel(channel, 'invalidpassword').iterator(); assert.equal(true, false); } catch(e) { assert.equal(e, 'Unauthorized');