All files / server index.js

91.67% Statements 33/36
75% Branches 6/8
62.5% Functions 5/8
91.18% Lines 31/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 841x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     39x   39x 39x 3042x     39x                           6x                             2x                 39x           39x       612x   3600x 576x        
import { expose } from 'postmsg-rpc'
import { pre } from 'prepost'
import createBitswap from './bitswap'
import createBlock from './block'
import createBootstrap from './bootstrap'
import createConfig from './config'
import createDag from './dag'
import createDht from './dht'
import createFiles from './files'
import createKey from './key'
import createLs from './ls'
import createName from './name'
import createObject from './object'
import createPin from './pin'
import createPing from './ping'
import createPubsub from './pubsub'
import createRepo from './repo'
import createStats from './stats'
import createSwarm from './swarm'
 
export default (getIpfs, opts) => {
  opts = opts || {}
 
  Eif (typeof opts.pre !== 'function') {
    const preObj = opts.pre || {}
    opts.pre = (fnName) => preObj[fnName]
  }
 
  const ipfs = {
    bitswap: createBitswap(getIpfs, opts),
    block: createBlock(getIpfs, opts),
    bootstrap: createBootstrap(getIpfs, opts),
    config: createConfig(getIpfs, opts),
    dag: createDag(getIpfs, opts),
    dht: createDht(getIpfs, opts),
    dns: expose('ipfs.dns', pre(
      opts.pre('dns'),
      (...args) => getIpfs().dns(...args)
    ), opts),
    files: createFiles(getIpfs, opts),
    id: expose('ipfs.id', pre(
      opts.pre('id'),
      () => getIpfs().id()
    ), opts),
    key: createKey(getIpfs, opts),
    name: createName(getIpfs, opts),
    object: createObject(getIpfs, opts),
    pin: createPin(getIpfs, opts),
    pubsub: createPubsub(getIpfs, opts),
    repo: createRepo(getIpfs, opts),
    resolve: expose('ipfs.resolve', pre(
      opts.pre('resolve'),
      (...args) => getIpfs().resolve(...args)
    ), opts),
    stats: createStats(getIpfs, opts),
    stop: expose('ipfs.stop', pre(
      opts.pre('stop'),
      () => getIpfs().stop()
    ), opts),
    swarm: createSwarm(getIpfs, opts),
    version: expose('ipfs.version', pre(
      opts.pre('version'),
      () => getIpfs().version()
    ), opts)
  }
 
  Object.assign(
    ipfs,
    createLs(getIpfs, opts),
    createPing(getIpfs, opts)
  )
 
  return ipfs
}
 
export function closeProxyServer (obj) {
  return Promise.all(
    Object.keys(obj).map((k) => {
      if (obj[k].close) return Promise.resolve(obj[k].close())
      return Promise.resolve(closeProxyServer(obj[k]))
    })
  )
}