Skip to content

Commit

Permalink
Fix FIXMEs. Thanks @ClickSimply (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Aug 19, 2019
1 parent 8ad5357 commit 222b005
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"brolog": "^1.2.6",
"cuid": "^2.1.1",
"rimraf": "^3.0.0",
"snap-db": "^1.1.2",
"snap-db": "^1.1.5",
"state-switch": "^0.6.2"
},
"devDependencies": {
Expand Down
37 changes: 10 additions & 27 deletions src/flash-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import {
} from './async-map'

export interface IteratorOptions<K> {
gt? : K
gte? : K
lt? : K
lte? : K
reverse? : boolean
gt? : K
gte? : K
lt? : K
lte? : K

offset? : number
limit? : number

keys? : boolean
values? : boolean
limit? : number

prefix? : K
reverse?: boolean
}

export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {
Expand Down Expand Up @@ -72,11 +73,6 @@ export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {
*/
public async set (key: K, value: V): Promise<void> {
log.verbose('FlashStore', 'set(%s, %s) value type: %s', key, value, typeof value)

// FIXME(huan): string for SnapDB only
if (typeof key !== 'string') {
throw new Error('only support string as key')
}
await this.snapDb.put(key, JSON.stringify(value))
}

Expand All @@ -91,10 +87,6 @@ export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {
public async get (key: K): Promise<V | undefined> {
log.verbose('FlashStore', 'get(%s)', key)
try {
// FIXME(huan): string for SnapDB only
if (typeof key !== 'string') {
throw new Error('only support string as key')
}
const val = await this.snapDb.get(key)
return val && JSON.parse(val)
} catch (e) {
Expand All @@ -116,10 +108,6 @@ export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {
*/
public async delete (key: K): Promise<void> {
log.verbose('FlashStore', 'delete(%s)', key)
// FIXME(huan): string for SnapDB only
if (typeof key !== 'string') {
throw new Error('only support string as key')
}
await this.snapDb.delete(key)
}

Expand Down Expand Up @@ -194,12 +182,8 @@ export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {
return this.snapDb.getCount()
}

/**
* FIXME(huan): use better way to do this
*/
public async has (key: K): Promise<boolean> {
const val = await this.get(key)
return !!val
return this.snapDb.exists(key)
}

/**
Expand All @@ -220,8 +204,7 @@ export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {

for await (const [key, val] of iterator) {
const valObj = val === undefined ? undefined : JSON.parse(val)
// FIXME(huan): key has to be string for SnapDB
yield [key as any, valObj]
yield [key, valObj]
}
}

Expand Down

0 comments on commit 222b005

Please sign in to comment.