Skip to content

Commit

Permalink
fix: reduce bundle size (#186)
Browse files Browse the repository at this point in the history
* fix: reduce bundle size

* chore: update deps and fix tests

* chore: change safe-buffer to buffer

* fix: fix config get callbacks
  • Loading branch information
hugomrdias authored and jacobheun committed Mar 15, 2019
1 parent ca31174 commit 0aa9d77
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 50 deletions.
30 changes: 0 additions & 30 deletions .npmignore

This file was deleted.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"npm": ">=3.0.0"
},
"devDependencies": {
"aegir": "^18.1.0",
"aegir": "^18.2.1",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"lodash": "^4.17.11",
Expand All @@ -55,18 +55,18 @@
"dependencies": {
"async": "^2.6.2",
"base32.js": "~0.1.0",
"bignumber.js": "^8.0.2",
"cids": "~0.5.7",
"bignumber.js": "^8.1.1",
"buffer": "^5.2.1",
"cids": "~0.5.8",
"datastore-core": "~0.6.0",
"datastore-fs": "~0.8.0",
"datastore-level": "~0.10.0",
"debug": "^4.1.1",
"debug": "^4.1.0",
"dlv": "^1.1.2",
"interface-datastore": "~0.6.0",
"ipfs-block": "~0.8.0",
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
"lodash.set": "^4.3.2",
"multiaddr": "^6.0.4",
"just-safe-set": "^2.1.0",
"multiaddr": "^6.0.6",
"proper-lockfile": "^4.0.0",
"pull-stream": "^3.6.9",
"sort-keys": "^2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions src/blockstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Block = require('ipfs-block')
const setImmediate = require('async/setImmediate')
const reject = require('async/reject')
const CID = require('cids')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const collect = require('pull-stream/sinks/collect')

/**
* Transform a raw buffer to a base32 encoded key.
Expand Down Expand Up @@ -60,7 +61,7 @@ function createBaseStore (store) {
query (query, callback) {
pull(
store.query(query),
pull.collect(callback)
collect(callback)
)
},
/**
Expand Down
28 changes: 21 additions & 7 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const Key = require('interface-datastore').Key
const queue = require('async/queue')
const waterfall = require('async/waterfall')
const _get = require('lodash.get')
const _set = require('lodash.set')
const _has = require('lodash.has')
const _get = require('dlv')
const _set = require('just-safe-set')
const Buffer = require('buffer').Buffer

const configKey = new Key('config')

Expand Down Expand Up @@ -37,10 +37,21 @@ module.exports = (store) => {
} catch (err) {
return callback(err)
}
if (key !== undefined && !_has(config, key)) {
return callback(new Error('Key ' + key + ' does not exist in config'))

if (typeof key === 'undefined') {
return callback(null, config)
}

if (typeof key !== 'string') {
return callback(new Error('Key ' + key + ' must be a string.'))
}
const value = key !== undefined ? _get(config, key) : config

const value = _get(config, key, null)

if (value === null) {
return callback(new Error('Key ' + key + ' does not exist in config.'))
}

callback(null, value)
})
},
Expand Down Expand Up @@ -91,7 +102,10 @@ module.exports = (store) => {
waterfall(
[
(cb) => configStore.get(cb),
(config, cb) => cb(null, _set(config, key, value)),
(config, cb) => {
_set(config, key, value)
cb(null, config)
},
_saveAll
],
callback)
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const waterfall = require('async/waterfall')
const series = require('async/series')
const parallel = require('async/parallel')
const each = require('async/each')
const _get = require('lodash.get')
const _get = require('dlv')
const assert = require('assert')
const path = require('path')
const debug = require('debug')
const Big = require('bignumber.js')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const reduce = require('pull-stream/sinks/reduce')

const backends = require('./backends')
const version = require('./version')
Expand Down Expand Up @@ -328,7 +329,7 @@ class IpfsRepo {
function getSize (queryFn, callback) {
pull(
queryFn.query({}),
pull.reduce((sum, block) => {
reduce((sum, block) => {
return sum
.plus(block.value.byteLength)
.plus(block.key._buf.byteLength)
Expand Down
9 changes: 9 additions & 0 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ module.exports = (repo) => {
})
})

it('get config key should fail with non string key', (done) => {
repo.config.get(1111, (err, value) => {
expect(err).to.exist()
console.log(value)

done()
})
})

it('set config key', (done) => {
series([
(cb) => repo.config.set('c.x', 'd', cb),
Expand Down

0 comments on commit 0aa9d77

Please sign in to comment.