1.2.0 • Published 5 years ago

easier-abstract-leveldown v1.2.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

easier-abstract-leveldown

A convenient wrapper of Abstract LevelDOWN for those who like TypeScript / ESnext features including async/await/generators.

Breaking Changes

^1.1.0:

  • expose now takes a factory function
    • Cls -> () => new Cls()

Major additions

  • ^1.2.0: LevelUpEasier lets you treat a LevelUp as an EasierLevelDOWN
  • ^1.1.0: LevelDOWNEasier lets you treat a LevelDOWN as an EasierLevelDOWN

Discussion

Things are made as straightforward as possible, anything non-integral can be ommitted and will be taken care of.

  • batch operations automatically get mapped to just calling each operation in a loop
    • you can also handle batch operations if needed
  • iterators are tested, in the worst case you can just yield everything
    • options are provided in the cleanest form { lt, gt, lte, gte, reverse, limit }
  • In general buffers and strings are taken care of, use whatever internal representation you want and if their conversion to StringOrBuffer is non-trivial, you can set up encode/decode key/val functions.
  • easier-derived leveldowns pass the same traditional leveldown tests
  • All methods expect standard promises to enable async/await features
  • Support treating LevelDOWN as event emitter
  • Support treating any current Abstract LevelDOWN provider as an EasierLevelDOWN!

Example

This is how easy it is to make a fully featured memdown. It could be more efficient, or not!

import expose, { EasierLevelDOWN } from 'easier-abstract-leveldown'

class MyLevelDOWN implements EasierLevelDOWN<string, string> {
  _store: {[key: string]: string}

  async open() {
    this._store = {}
  }

  async get(k) {
    const v = this._store[k]
    if (v === undefined)
      throw new Error('NotFound')
    return v
  }

  async put(k: string, v: string) {
    this._store[k] = v
  }

  async del(k) {
    delete this._store[k]
  }

  async *iterator(opts) {
    const keys = Object.keys(this._store).sort()
    if (opts.reverse) keys.reverse()

    for (const k of keys) {
      yield {
        key: k,
        value: this._store[k]
      }
    }
  }
}

export default expose(() => new MyLevelDOWN())
1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago