Beispiel #1
0
  db.messagesByType = function (opts) {
    if(!opts)
      throw new Error('must provide {type: string} to messagesByType')
    if(isString(opts))
      opts = {type: opts}    
    
    opts = stdopts(opts)
    var _keys   = opts.keys
    var _values = opts.values

    ltgt.toLtgt(opts, opts, function (value) {
      return ['type', opts.type, value]
    }, LO, HI)

    opts.values = true
    return pull(
      pl.read(indexDB, opts),
      paramap(function (data, cb) {
        var id = _keys ? data.value : data
        db.get(id, function (err, msg) {
          var ts = opts.keys ? data.key[2] : undefined
          cb(null, msgFmt(_keys, _values, {key: id, ts: ts, value: msg}))
        })
      }),
      pull.filter()
    )
  }
Beispiel #2
0
 read: function (opts) {
   opts = ltgt.toLtgt(opts, opts, function (value, isUpper) {
     var bound = isUpper ? HI : LO
     return [path, value, bound]
   })
   return pull(
     pl.read(db.sublevel('idx'), opts),
     pull.map(function (e) {
       return e[2]
     })
   )
 },
Beispiel #3
0
    index.createUserStream = function (streamOpts) {
      const opts = u.options(streamOpts)
      // mutates opts
      ltgt.toLtgt(opts, opts, function (value) {
        return [opts.id, value]
      }, u.lo, u.hi)
      var keys = opts.keys !== false
      var values = opts.values !== false
      opts.keys = false
      opts.values = true

      return pull(index.read(opts), u.Format(keys, values, opts.private))
    }
  db.createUserStream = function (opts) {
    opts = stdopts(opts)
    ltgt.toLtgt(opts, opts, function (value) {
      return [opts.id, value]
    }, LO, HI)
    var _keys = opts.keys
    var _values = opts.values

    opts.keys = false
    opts.values = true
    return pull(
      pl.read(clockDB, opts),
      lookup(_keys, _values)
    )
  }
  db.createFeedStream = function (opts) {
    opts = stdopts(opts)
    ltgt.toLtgt(opts, opts, function (value) {
      return [value, LO]
    }, LO, HI)
    var _keys = opts.keys
    var _values = opts.values
    opts.keys = false
    opts.values = true

    return pull(
      pl.read(feedDB, opts),
      lookup(_keys, _values)
    )
  }
Beispiel #6
0
    iterator: function (_opts, cb) {
      var opts = clone(_opts || {})
      var prefix = _opts.prefix || []

      function encodeKey(key) {
        return encodePrefix(prefix, key, opts, {})
      }

      ltgt.toLtgt(_opts, opts, encodeKey, precodec.lowerBound, precodec.upperBound)

      // if these legacy values are in the options, remove them

      opts.prefix = null

      //************************************************
      //hard coded defaults, for now...
      //TODO: pull defaults and encoding out of levelup.
      opts.keyAsBuffer = opts.valueAsBuffer = false
      //************************************************


      //this is vital, otherwise limit: undefined will
      //create an empty stream.
      if ('number' !== typeof opts.limit)
        opts.limit = -1

      opts.keyAsBuffer = precodec.buffer
      opts.valueAsBuffer = codec.isValueAsBuffer(opts)

      function wrapIterator (iterator) {
        return {
          next: function (cb) {
            return iterator.next(cb)
          },
          end: function (cb) {
            iterator.end(cb)
          }
        }
      }

      if(ready)
        return wrapIterator((db.db || db).iterator(opts))
      else
        waiting.push(function () {
          cb(null, wrapIterator((db.db || db).iterator(opts)))
        })

    }
Beispiel #7
0
  emitter.query = function (opts) {
    var name   = opts && opts.name
    var period = opts && opts.period

    if(!name)
      throw new Error('must provide period')

    if(!~tp.periods.indexOf(period))
      throw new Error('period must be one of:' + JSON.stringify(tp.periods))

    function map (key) {
      return [name, period, toTimestamp(key)]
    }

    opts = ltgt.toLtgt(opts, opts, map, 0, MAX)

    return pl.read(db, opts)
  }
Beispiel #8
0
    index.messagesByType = function (opts) {
      if (!opts) { throw new Error('must provide {type: string} to messagesByType') }

      if (isString(opts)) { opts = { type: opts } }

      opts = u.options(opts)
      var keys = opts.keys !== false
      var values = opts.values !== false
      opts.values = true

      ltgt.toLtgt(opts, opts, function (value) {
        return ['type', opts.type, value]
      }, u.lo, u.hi)

      return pull(
        index.read(opts),
        Format(keys, values, opts.private)
      )
    }
Beispiel #9
0
  db.messagesByType = function (opts) {
    if(!opts)
      throw new Error('must provide {type: string} to messagesByType')
    if(isString(opts))
      opts = {type: opts}

    ltgt.toLtgt(opts, opts, function (value) {
      return ['type', opts.type, value]
    }, LO, HI)
    //default keys to false
    var keys = opts.keys = opts.keys === true
    return pull(
      pl.read(indexDB, opts),
      paramap(function (data, cb) {
        var id = keys ? data.value : data
        db.get(id, function (err, msg) {
          cb(null, keys ? {key: id, ts: data.key[2], value: msg} : msg)
        })
      }),
      pull.filter()
    )
  }