How to use the level function in level

To help you get started, we’ve selected a few level 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 ethereum-optimism / optimism / packages / data-transport-layer / src / services / main / service.ts View on Github external
protected async _init(): Promise {
    this.logger.info('Initializing L1 Data Transport Service...')

    this.state.db = level(this.options.dbPath)
    await this.state.db.open()

    this.state.l1TransportServer = new L1TransportServer({
      ...this.options,
      db: this.state.db,
    })

    // Optionally enable sync from L1.
    if (this.options.syncFromL1) {
      this.state.l1IngestionService = new L1IngestionService({
        ...this.options,
        db: this.state.db,
      })
    }

    // Optionally enable sync from L2.
github beakerbrowser / beaker / app / background-process / networks / dat.js View on Github external
export function setup () {
  // open databases
  dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
  mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
  db = level(dbPath)
  archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
  subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
  ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
  drive = hyperdrive(db)

  // watch archives for FS changes
  var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
  watcher.on('ready', () => { // wait till ready, otherwise we get an 'add' for each existing file
    watcher.on('add', onArchiveFSChange.bind(null, 'add', 'file'))
    watcher.on('addDir', onArchiveFSChange.bind(null, 'add', 'directory'))
    watcher.on('change', onArchiveFSChange.bind(null, 'change', 'file'))
    // watcher.on('unlink', onArchiveFSChange.bind(null, 'unlink', 'file')) TODO: dat doesnt support deletes yet
    // watcher.on('unlinkDir', onArchiveFSChange.bind(null, 'unlink', 'directory')) TODO: dat doesnt support deletes yet
  })
  app.once('will-quit', () => watcher.close())
github delvedor / LightFirewall / ipChecker.es6.js View on Github external
constructor(time = 1000 * 60 * 10, attempts = 4) {
    this.time = time; // time before timeout, default value 10 mins
    this.attempts = attempts; // max amount of attempts, default value is 4
    this.ipsTimeout = level('.ipchecker-ipstimeout');
    this.ipsAttempts = level('.ipchecker-ipsattempts');
  }
github voltairelabs / plasma / src / chain / index.js View on Github external
constructor(options = {}) {
    this.options = options
    this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
    this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
    this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)

    // transaction pool
    this.txPool = new TxPool(this.txPoolDb)

    // sync manager
    this.syncManager = new SyncManager(this, this.options.network)

    // create instance for web3
    this.web3 = new Web3(this.options.web3Provider)

    // create root chain contract
    this.parentContract = new this.web3.eth.Contract(
      RootChain.abi,
      this.options.rootChainContract
    )
github voltairelabs / plasma / src / chain / index.js View on Github external
constructor(options = {}) {
    this.options = options
    this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
    this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
    this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)

    // transaction pool
    this.txPool = new TxPool(this.txPoolDb)

    // sync manager
    this.syncManager = new SyncManager(this, this.options.network)

    // create instance for web3
    this.web3 = new Web3(this.options.web3Provider)

    // create root chain contract
    this.parentContract = new this.web3.eth.Contract(
      RootChain.abi,
      this.options.rootChainContract
    )
github voltairelabs / plasma / src / chain / index.js View on Github external
constructor(options = {}) {
    this.options = options
    this.blockDb = level(`${this.options.db}/block`, defaultDBOptions)
    this.detailsDb = level(`${this.options.db}/details`, defaultDBOptions)
    this.txPoolDb = level(`${this.options.db}/txPool`, defaultDBOptions)

    // transaction pool
    this.txPool = new TxPool(this.txPoolDb)

    // sync manager
    this.syncManager = new SyncManager(this, this.options.network)

    // create instance for web3
    this.web3 = new Web3(this.options.web3Provider)

    // create root chain contract
    this.parentContract = new this.web3.eth.Contract(
      RootChain.abi,
      this.options.rootChainContract
github zalando / zappr / server / persistence / database.js View on Github external
constructor() {
    // TODO: offer other solutions than LevelDB
    const name = config.get('LEVEL_DB')
    this.db = level(name, {valueEncoding: 'json'})
  }
github pandonetwork / pando / future / repository / src / fiber / index.ts View on Github external
return new Promise((resolve, reject) => {
        Level(location, options, function (err, dbs) {
            if (err) {
                reject(err)
            } else {

                resolve(dbs)
            }
        })
    })
}
github pandonetwork / pando / future / repository / src / fiber / factory.ts View on Github external
constructor(repository: Repository) {
        this.repository = repository
        this.db         = Level(npath.join(repository.paths.fibers, 'db'), { valueEncoding: 'json' })

    }
github graphsense / graphsense-dashboard / src / sw.js View on Github external
import Level from 'level'
import Logger from './logger.js'

const logger = Logger.create('Service Worker')
const db = Level('cache')

const myFetch = (request) => {
  logger.debug('fetching', request)
  if (!db.isOpen()) {
    logger.warn('db not open')
    return db.on('open').then(myFetch(request))
  }
  return db.get(request.url)
    .then((resp) => {
      logger.debug(`${request.url} found in cache`)
      let headers = new Headers()
      headers.append('Content-Type', 'application/json')
      return new Response(resp, {status: 200, statusText: 'OK', headers})
    }, (err) => {
      logger.debug(`${request.url} not found in cache, fetching it remotely`)
      return fetch(request)