Skip to content

Commit

Permalink
Replace leveldown to nosql-leveldb (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jun 23, 2018
1 parent ccaa080 commit 7af5fa6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
"brolog": "^1.2.6",
"cuid": "^2.1.1",
"encoding-down": "^2.3.1",
"leveldown": "^4.0.1",
"levelup": "github:zixia/levelup",
"nosql-leveldb": "^3.0.0",
"rimraf": "^2.6.2",
"state-switch": "^0.4.5"
},
"devDependencies": {
"@types/app-root-path": "^1.2.4",
"@types/blue-tape": "^0.1.31",
"@types/leveldown": "^1.7.0",
"@types/node": "^8.0.30",
"@types/rimraf": "^2.0.2",
"@types/semver": "^5.5.0",
Expand Down
58 changes: 29 additions & 29 deletions src/flash-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs'
import os from 'os'
import path from 'path'

import rimraf from 'rimraf'
// import rimraf from 'rimraf'

// tslint:disable:no-shadowed-variable
import test from 'blue-tape'
Expand Down Expand Up @@ -152,34 +152,34 @@ test('async values()', async t => {
}
})

test('deferred-leveldown json bug(fixed on version 2.0.2', async t => {
const encoding = (await import('encoding-down')).default
const leveldown = (await import('leveldown')).default
const levelup = (await import('levelup')).default

const tmpDir = fs.mkdtempSync(
path.join(
os.tmpdir(),
path.sep,
'flash-store-',
),
)

const encoded = encoding(leveldown(tmpDir) as any, {
valueEncoding: 'json',
})
const levelDb = levelup(encoded)

const EXPECTED_OBJ = {a: 1}
await levelDb.put('test', EXPECTED_OBJ)
const value = await levelDb.get('test')

t.equal(typeof value, 'object', 'value type should be object')
t.deepEqual(value, EXPECTED_OBJ, 'should get back the original object')

// `rm -fr tmpDir`
await new Promise(r => rimraf(tmpDir, r))
})
// test('deferred-leveldown json bug(fixed on version 2.0.2', async t => {
// const encoding = (await import('encoding-down')).default
// const leveldown = (await import('leveldown')).default
// const levelup = (await import('levelup')).default

// const tmpDir = fs.mkdtempSync(
// path.join(
// os.tmpdir(),
// path.sep,
// 'flash-store-',
// ),
// )

// const encoded = encoding(leveldown(tmpDir) as any, {
// valueEncoding: 'json',
// })
// const levelDb = levelup(encoded)

// const EXPECTED_OBJ = {a: 1}
// await levelDb.put('test', EXPECTED_OBJ)
// const value = await levelDb.get('test')

// t.equal(typeof value, 'object', 'value type should be object')
// t.deepEqual(value, EXPECTED_OBJ, 'should get back the original object')

// // `rm -fr tmpDir`
// await new Promise(r => rimraf(tmpDir, r))
// })

async function* storeFixture() {
const tmpDir = fs.mkdtempSync(
Expand Down
7 changes: 4 additions & 3 deletions src/flash-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {

import * as rimrafProxy from 'rimraf'
import * as encodingProxy from 'encoding-down'
import * as leveldownProxy from 'leveldown'
import LevelDb from 'nosql-leveldb'
import * as levelupProxy from 'levelup'

// https://github.com/rollup/rollup/issues/1267#issuecomment-296395734
const rimraf = (<any>rimrafProxy).default || rimrafProxy
const encoding = (<any>encodingProxy).default || encodingProxy
const leveldown = (<any>leveldownProxy).default || leveldownProxy
// const leveldown = (<any>leveldownProxy).default || leveldownProxy
const levelup = (<any>levelupProxy).default || levelupProxy

import {
Expand Down Expand Up @@ -54,7 +54,8 @@ export class FlashStore<K = any, V = any> implements AsyncMap<K, V> {

// https://twitter.com/juliangruber/status/908688876381892608
const encoded = encoding(
leveldown(workdir),
// leveldown(workdir),
LevelDb(workdir),
{
// FIXME: issue #2
valueEncoding: 'json',
Expand Down
2 changes: 2 additions & 0 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ declare module '*/package.json' {
export const version: string
// export default version
}

declare module 'nosql-leveldb'

0 comments on commit 7af5fa6

Please sign in to comment.