Skip to content

Commit a8ce3a6

Browse files
committed
Merge pull request #46 from noffle/coverage-and-readme
Code cleanup, better coverage, readme improvements
2 parents 17e38bc + 7544d2a commit a8ce3a6

File tree

4 files changed

+69
-66
lines changed

4 files changed

+69
-66
lines changed

README.md

+38-48
Original file line numberDiff line numberDiff line change
@@ -41,48 +41,20 @@ This is the implementation of the [IPFS repo spec](https://github.com/ipfs/specs
4141
└───────────┘ └───────────┘ └───────────┘ └───────────┘ └───────────┘ └───────────┘
4242
```
4343

44-
IPFS repo exposes a well defined interface by the Repo Spec. Each of the individual repos has an interface defined by [abstract-blob-store](https://github.com/maxogden/abstract-blob-store), this enables us to make IPFS repo portable (running on Node.js vs the browser) and accept different types of storage mechanisms for each repo (fs, levelDB, etc).
44+
This provides a well defined interface for creating and interacting with an IPFS
45+
Repo backed by a group of abstract backends for keys, configuration, logs, and
46+
more. Each of the individual repos has an interface defined by
47+
[abstract-blob-store](https://github.com/maxogden/abstract-blob-store): this
48+
enables us to make IPFS Repo portable (running on Node.js vs the browser) and
49+
accept different types of storage mechanisms for each repo (fs, levelDB, etc).
4550

4651
## Good to know (historical context)
4752

4853
- The datastore folder holds the legacy version of datastore, still built in levelDB, there is a current endeavour of pushing it to fs completely.
4954
- The blocks folder is the current version of datastore.
5055
- The keys repo doesn't exist yet, as the private key is simply stored inside config
5156

52-
# Installation
53-
54-
## npm
55-
56-
```sh
57-
> npm i ipfs-repo
58-
```
59-
60-
## Use in Node.js
61-
62-
```JavaScript
63-
var IPFSRepo = require('ipfs-repo')
64-
```
65-
66-
## Use in a browser with browserify, webpack or any other bundler
67-
68-
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
69-
70-
```JavaScript
71-
var IPFSRepo = require('ipfs-repo')
72-
```
73-
74-
## Use in a browser Using a script tag
75-
76-
Loading this module through a script tag will make the `Unixfs` obj available in the global namespace.
77-
78-
```html
79-
<script src="https://npmcdn.com/ipfs-repo/dist/index.min.js"></script>
80-
<!-- OR -->
81-
<script src="https://npmcdn.com/ipfs-repo/dist/index.js"></script>
82-
```
83-
84-
85-
# Usage
57+
# Example
8658

8759
```js
8860
var fsBlobStore = require('fs-blob-store') // an in-memory blob store
@@ -122,12 +94,6 @@ Valid keys for `opts` include:
12294

12395
If you use the former form, all of the sub-blob-stores will use the same store.
12496

125-
### repo.init(config, cb)
126-
127-
Initializes the IPFS repository at the repo's `path`. Currently this is a no-op.
128-
129-
Consumes a config object `config` *(TODO: specification?)* By default, init requires the repo not yet exist (by default). Calls the callback `cb(err)` on completion or error.
130-
13197
### repo.exists(cb)
13298

13399
Check if the repo you are going to access already exists. Calls the callback
@@ -158,18 +124,42 @@ Read and write buffers to/from the repo's block store.
158124

159125
**WIP**
160126

161-
## Install
127+
# Installation
162128

163-
Install via npm:
129+
## npm
164130

165-
```bash
166-
$ npm i ipfs-repo
131+
```sh
132+
> npm i ipfs-repo
133+
```
134+
135+
## Use in Node.js
136+
137+
```JavaScript
138+
var IPFSRepo = require('ipfs-repo')
139+
```
140+
141+
## Use in a browser with browserify, webpack or any other bundler
142+
143+
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
144+
145+
```JavaScript
146+
var IPFSRepo = require('ipfs-repo')
147+
```
148+
149+
## Use in a browser Using a script tag
150+
151+
Loading this module through a script tag will make the `Unixfs` obj available in the global namespace.
152+
153+
```html
154+
<script src="https://npmcdn.com/ipfs-repo/dist/index.min.js"></script>
155+
<!-- OR -->
156+
<script src="https://npmcdn.com/ipfs-repo/dist/index.js"></script>
167157
```
168158

169159
## Contribute
170160

171161
There are some ways you can make this module better:
172162

173-
- Consult our open issues and take on one of them
174-
- Make the tests better
175-
- Make the tests work in the Browser
163+
- Consult our [open issues](https://github.com/ipfs/js-ipfs-repo/issues) and take on one of them
164+
- Help our tests reach 100% coverage!
165+

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
],
3030
"homepage": "https://github.com/ipfs/js-ipfs-repo",
3131
"devDependencies": {
32+
"abstract-blob-store": "^3.2.0",
3233
"aegir": "^2.1.1",
3334
"async": "^1.5.2",
3435
"bl": "^1.1.2",

src/index.js

+3-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const stores = require('./stores')
44

55
function Repo (repoPath, options) {
6+
if (!(this instanceof Repo)) {
7+
return new Repo(repoPath, options)
8+
}
69
if (!options) { throw new Error('missing options param') }
710
if (!options.stores) { throw new Error('missing options.stores param') }
811

@@ -22,14 +25,6 @@ function Repo (repoPath, options) {
2225

2326
this.path = repoPath
2427

25-
this.init = (config, callback) => {
26-
this.exists((err, exists) => {
27-
if (err) { throw err }
28-
if (exists) { throw new Error('Repo already exists') }
29-
throw new Error('not implemented')
30-
})
31-
}
32-
3328
this.locks = stores
3429
.locks
3530
.setUp(repoPath, options.stores.locks)
@@ -59,16 +54,6 @@ function Repo (repoPath, options) {
5954
this.datastore = stores
6055
.datastore
6156
.setUp(repoPath, options.stores.datastore, this.locks)
62-
63-
// TODO: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642
64-
// this.datastoreLegacy = stores
65-
// .datastore
66-
// .setUp(repoPath, options.stores.datastore, this.locks)
67-
68-
// TODO: Currently this was also deprecated in go-ipfs
69-
// this.logs = stores
70-
// .logs
71-
// .setUp(repoPath, options.stores.logs, this.locks)
7257
}
7358

7459
exports = module.exports = Repo

test/repo-test.js

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
'use strict'
44

5+
const Repo = require('../src/index')
56
const expect = require('chai').expect
67
const base58 = require('bs58')
78
const bl = require('bl')
@@ -14,6 +15,32 @@ const fileAExt = fs.readFileSync(join(__dirname, 'test-repo/blocks/12207028/1220
1415

1516
module.exports = function (repo) {
1617
describe('IPFS Repo Tests', function () {
18+
it('can init repo /wo new', (done) => {
19+
var repo
20+
function run () {
21+
repo = Repo('foo', { stores: require('abstract-blob-store') })
22+
}
23+
expect(run).to.not.throw(Error)
24+
expect(repo).to.be.an.instanceof(Repo)
25+
done()
26+
})
27+
28+
it('bad repo init 1', (done) => {
29+
function run () {
30+
return new Repo()
31+
}
32+
expect(run).to.throw(Error)
33+
done()
34+
})
35+
36+
it('bad repo init 2', (done) => {
37+
function run () {
38+
return new Repo('', {})
39+
}
40+
expect(run).to.throw(Error)
41+
done()
42+
})
43+
1744
it('check if Repo exists', (done) => {
1845
repo.exists((err, exists) => {
1946
expect(err).to.not.exist

0 commit comments

Comments
 (0)