How to use the merge-options.call function in merge-options

To help you get started, we’ve selected a few merge-options examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-client / embedded-chromesockets.js View on Github external
async function buildConfig (opts) {
  const defaultOpts = JSON.parse(optionDefaults.ipfsNodeConfig)
  defaultOpts.libp2p = {
    config: {
      dht: {
        // TODO: check if below is needed after js-ipfs is released with DHT disabled
        enabled: false
      }
    }
  }
  const userOpts = JSON.parse(opts.ipfsNodeConfig)
  const ipfsNodeConfig = mergeOptions.call({ concatArrays: true }, defaultOpts, userOpts, { start: false })

  // Detect when API or Gateway port is not available (taken by something else)
  // We find the next free port and update configuration to use it instead
  const multiaddr2port = (ma) => parseInt(new URL(multiaddr2httpUrl(ma)).port, 10)
  const gatewayPort = multiaddr2port(ipfsNodeConfig.config.Addresses.Gateway)
  const apiPort = multiaddr2port(ipfsNodeConfig.config.Addresses.API)
  log(`checking if ports are available: api: ${apiPort}, gateway: ${gatewayPort}`)
  const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
  const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })
  if (gatewayPort !== freeGatewayPort || apiPort !== freeApiPort) {
    log(`updating config to available ports: api: ${freeApiPort}, gateway: ${freeGatewayPort}`)
    const addrs = ipfsNodeConfig.config.Addresses
    addrs.Gateway = addrs.Gateway.replace(gatewayPort.toString(), freeGatewayPort.toString())
    addrs.API = addrs.API.replace(apiPort.toString(), freeApiPort.toString())
  }
github ipfs / js-ipfs / src / core / runtime / ipld-browser.js View on Github external
module.exports = (blockService, options) => {
  options = options || {}

  return mergeOptions.call(
    // ensure we have the defaults formats even if the user overrides `formats: []`
    { concatArrays: true },
    {
      blockService: blockService,
      formats: [ipldDagCbor, ipldDagPb, ipldRaw]
    }, options)
}
github ipfs / js-ipfs / src / core / runtime / ipld-browser-all.js View on Github external
module.exports = (blockService, options) => {
  options = options || {}

  return mergeOptions.call(
    // ensure we have the defaults formats even if the user overrides `formats: []`
    { concatArrays: true },
    {
      blockService: blockService,
      formats: [
        require('ipld-dag-cbor'),
        require('ipld-dag-pb'),
        require('ipld-raw'),
        require('ipld-bitcoin'),
        require('ipld-ethereum').ethAccountSnapshot,
        require('ipld-ethereum').ethBlock,
        require('ipld-ethereum').ethBlockList,
        require('ipld-ethereum').ethStateTrie,
        require('ipld-ethereum').ethStorageTrie,
        require('ipld-ethereum').ethTx,
        require('ipld-ethereum').ethTxTrie,
github ipfs / js-ipfs / src / core / runtime / ipld-nodejs.js View on Github external
module.exports = (blockService, options, log) => {
  options = options || {}

  return mergeOptions.call(
    // ensure we have the defaults formats even if the user overrides `formats: []`
    { concatArrays: true },
    {
      blockService: blockService,
      loadFormat: (codec) => {
        log('Loading IPLD format', codec)
        if (IpldFormats[codec]) {
          return IpldFormats[codec]
        } else {
          throw new Error(`Missing IPLD format "${codec}"`)
        }
      }
    }, options)
}
github teppeis / duck / src / batch.ts View on Github external
function getBatchOptions(config: DuckConfig): AwsOptions | LocalOptions {
  const { batchOptions = {} } = config;
  return mergeOptions.call({ concatArrays: true }, defaultBatchOptions(config), batchOptions);
}
github libp2p / js-libp2p / src / connection-manager / index.js View on Github external
constructor (libp2p, options) {
    this._libp2p = libp2p
    this._registrar = libp2p.registrar
    this._peerId = libp2p.peerInfo.id.toString()
    this._options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, options)
    assert(
      this._options.maxConnections > this._options.minConnections,
      'Connection Manager maxConnections must be greater than minConnections'
    )

    debug('options: %j', this._options)

    this._metrics = libp2p.metrics

    this._peerValues = new Map()
    this._connections = new Map()
    this._timer = null
    this._checkMetrics = this._checkMetrics.bind(this)
  }

merge-options

Merge Option Objects

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis