Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 2820b0d

Browse files
authored
deps: update interface-store to 5.x.x (#149)
1 parent ba79dca commit 2820b0d

File tree

7 files changed

+88
-80
lines changed

7 files changed

+88
-80
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
"dependencies": {
197197
"@libp2p/logger": "^2.0.0",
198198
"err-code": "^3.0.1",
199-
"interface-store": "^4.0.0",
199+
"interface-store": "^5.0.1",
200200
"it-all": "^2.0.0",
201201
"it-drain": "^2.0.0",
202202
"it-filter": "^2.0.0",
@@ -210,7 +210,7 @@
210210
},
211211
"devDependencies": {
212212
"aegir": "^38.1.7",
213-
"interface-datastore": "^8.0.0",
214-
"interface-datastore-tests": "^4.0.0"
213+
"interface-datastore": "^8.1.2",
214+
"interface-datastore-tests": "^5.0.0"
215215
}
216216
}

src/base.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,43 @@ import sort from 'it-sort'
22
import drain from 'it-drain'
33
import filter from 'it-filter'
44
import take from 'it-take'
5-
import type { Batch, Datastore, Key, KeyQuery, Options, Pair, Query } from 'interface-datastore'
6-
import type { AwaitIterable } from 'interface-store'
5+
import type { Batch, Datastore, Key, KeyQuery, Pair, Query } from 'interface-datastore'
6+
import type { AbortOptions, Await, AwaitIterable } from 'interface-store'
77

88
export class BaseDatastore implements Datastore {
9-
async open (): Promise<void> {
10-
11-
}
12-
13-
async close (): Promise<void> {
14-
9+
put (key: Key, val: Uint8Array, options?: AbortOptions): Await<Key> {
10+
return Promise.reject(new Error('.put is not implemented'))
1511
}
1612

17-
async put (key: Key, val: Uint8Array, options?: Options): Promise<void> {
18-
await Promise.reject(new Error('.put is not implemented'))
13+
get (key: Key, options?: AbortOptions): Await<Uint8Array> {
14+
return Promise.reject(new Error('.get is not implemented'))
1915
}
2016

21-
async get (key: Key, options?: Options): Promise<Uint8Array> {
22-
return await Promise.reject(new Error('.get is not implemented'))
17+
has (key: Key, options?: AbortOptions): Await<boolean> {
18+
return Promise.reject(new Error('.has is not implemented'))
2319
}
2420

25-
async has (key: Key, options?: Options): Promise<boolean> {
26-
return await Promise.reject(new Error('.has is not implemented'))
21+
delete (key: Key, options?: AbortOptions): Await<void> {
22+
return Promise.reject(new Error('.delete is not implemented'))
2723
}
2824

29-
async delete (key: Key, options?: Options): Promise<void> {
30-
await Promise.reject(new Error('.delete is not implemented'))
31-
}
32-
33-
async * putMany (source: AwaitIterable<Pair>, options: Options = {}): AsyncIterable<Pair> {
25+
async * putMany (source: AwaitIterable<Pair>, options: AbortOptions = {}): AwaitIterable<Key> {
3426
for await (const { key, value } of source) {
3527
await this.put(key, value, options)
36-
yield { key, value }
28+
yield key
3729
}
3830
}
3931

40-
async * getMany (source: AwaitIterable<Key>, options: Options = {}): AsyncIterable<Uint8Array> {
32+
async * getMany (source: AwaitIterable<Key>, options: AbortOptions = {}): AwaitIterable<Pair> {
4133
for await (const key of source) {
42-
yield this.get(key, options)
34+
yield {
35+
key,
36+
value: await this.get(key, options)
37+
}
4338
}
4439
}
4540

46-
async * deleteMany (source: AwaitIterable<Key>, options: Options = {}): AsyncIterable<Key> {
41+
async * deleteMany (source: AwaitIterable<Key>, options: AbortOptions = {}): AwaitIterable<Key> {
4742
for await (const key of source) {
4843
await this.delete(key, options)
4944
yield key
@@ -75,19 +70,19 @@ export class BaseDatastore implements Datastore {
7570
* Extending classes should override `query` or implement this method
7671
*/
7772
// eslint-disable-next-line require-yield
78-
async * _all (q: Query, options?: Options): AsyncIterable<Pair> {
73+
async * _all (q: Query, options?: AbortOptions): AwaitIterable<Pair> {
7974
throw new Error('._all is not implemented')
8075
}
8176

8277
/**
8378
* Extending classes should override `queryKeys` or implement this method
8479
*/
8580
// eslint-disable-next-line require-yield
86-
async * _allKeys (q: KeyQuery, options?: Options): AsyncIterable<Key> {
81+
async * _allKeys (q: KeyQuery, options?: AbortOptions): AwaitIterable<Key> {
8782
throw new Error('._allKeys is not implemented')
8883
}
8984

90-
query (q: Query, options?: Options): AsyncIterable<Pair> {
85+
query (q: Query, options?: AbortOptions): AwaitIterable<Pair> {
9186
let it = this._all(q, options)
9287

9388
if (q.prefix != null) {
@@ -116,7 +111,7 @@ export class BaseDatastore implements Datastore {
116111
return it
117112
}
118113

119-
queryKeys (q: KeyQuery, options?: Options): AsyncIterable<Key> {
114+
queryKeys (q: KeyQuery, options?: AbortOptions): AwaitIterable<Key> {
120115
let it = this._allKeys(q, options)
121116

122117
if (q.prefix != null) {

src/keytransform.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { BaseDatastore } from './base.js'
22
import map from 'it-map'
33
import { pipe } from 'it-pipe'
44
import type { KeyTransform } from './index.js'
5-
import type { Batch, Datastore, Key, KeyQuery, Options, Pair, Query } from 'interface-datastore'
6-
import type { AwaitIterable } from 'interface-store'
5+
import type { Batch, Datastore, Key, KeyQuery, Pair, Query } from 'interface-datastore'
6+
import type { AbortOptions, AwaitIterable } from 'interface-store'
77

88
/**
99
* A datastore shim, that wraps around a given datastore, changing
@@ -21,23 +21,25 @@ export class KeyTransformDatastore extends BaseDatastore {
2121
this.transform = transform
2222
}
2323

24-
async put (key: Key, val: Uint8Array, options?: Options): Promise<void> {
24+
async put (key: Key, val: Uint8Array, options?: AbortOptions): Promise<Key> {
2525
await this.child.put(this.transform.convert(key), val, options)
26+
27+
return key
2628
}
2729

28-
async get (key: Key, options?: Options): Promise<Uint8Array> {
30+
async get (key: Key, options?: AbortOptions): Promise<Uint8Array> {
2931
return await this.child.get(this.transform.convert(key), options)
3032
}
3133

32-
async has (key: Key, options?: Options): Promise<boolean> {
34+
async has (key: Key, options?: AbortOptions): Promise<boolean> {
3335
return await this.child.has(this.transform.convert(key), options)
3436
}
3537

36-
async delete (key: Key, options?: Options): Promise<void> {
38+
async delete (key: Key, options?: AbortOptions): Promise<void> {
3739
await this.child.delete(this.transform.convert(key), options)
3840
}
3941

40-
async * putMany (source: AwaitIterable<Pair>, options: Options = {}): AsyncIterable<Pair> {
42+
async * putMany (source: AwaitIterable<Pair>, options: AbortOptions = {}): AsyncIterable<Key> {
4143
const transform = this.transform
4244
const child = this.child
4345

@@ -53,15 +55,12 @@ export class KeyTransformDatastore extends BaseDatastore {
5355
yield * child.putMany(source, options)
5456
},
5557
async function * (source) {
56-
yield * map(source, ({ key, value }) => ({
57-
key: transform.invert(key),
58-
value
59-
}))
58+
yield * map(source, key => transform.invert(key))
6059
}
6160
)
6261
}
6362

64-
async * getMany (source: AwaitIterable<Key>, options: Options = {}): AsyncIterable<Uint8Array> {
63+
async * getMany (source: AwaitIterable<Key>, options: AbortOptions = {}): AsyncIterable<Pair> {
6564
const transform = this.transform
6665
const child = this.child
6766

@@ -72,11 +71,17 @@ export class KeyTransformDatastore extends BaseDatastore {
7271
},
7372
async function * (source) {
7473
yield * child.getMany(source, options)
74+
},
75+
async function * (source) {
76+
yield * map(source, ({ key, value }) => ({
77+
key: transform.invert(key),
78+
value
79+
}))
7580
}
7681
)
7782
}
7883

79-
async * deleteMany (source: AwaitIterable<Key>, options: Options = {}): AsyncIterable<Key> {
84+
async * deleteMany (source: AwaitIterable<Key>, options: AbortOptions = {}): AsyncIterable<Key> {
8085
const transform = this.transform
8186
const child = this.child
8287

@@ -109,7 +114,7 @@ export class KeyTransformDatastore extends BaseDatastore {
109114
}
110115
}
111116

112-
query (q: Query, options?: Options): AsyncIterable<Pair> {
117+
query (q: Query, options?: AbortOptions): AsyncIterable<Pair> {
113118
const query: Query = {
114119
...q
115120
}
@@ -143,7 +148,7 @@ export class KeyTransformDatastore extends BaseDatastore {
143148
})
144149
}
145150

146-
queryKeys (q: KeyQuery, options?: Options): AsyncIterable<Key> {
151+
queryKeys (q: KeyQuery, options?: AbortOptions): AsyncIterable<Key> {
147152
const query = {
148153
...q
149154
}

src/memory.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BaseDatastore } from './base.js'
22
import { Key } from 'interface-datastore/key'
33
import * as Errors from './errors.js'
44
import type { Pair } from 'interface-datastore'
5+
import type { Await, AwaitIterable } from 'interface-store'
56

67
export class MemoryDatastore extends BaseDatastore {
78
private readonly data: Map<string, Uint8Array>
@@ -12,11 +13,13 @@ export class MemoryDatastore extends BaseDatastore {
1213
this.data = new Map()
1314
}
1415

15-
async put (key: Key, val: Uint8Array): Promise<void> { // eslint-disable-line require-await
16+
put (key: Key, val: Uint8Array): Await<Key> { // eslint-disable-line require-await
1617
this.data.set(key.toString(), val)
18+
19+
return key
1720
}
1821

19-
async get (key: Key): Promise<Uint8Array> {
22+
get (key: Key): Await<Uint8Array> {
2023
const result = this.data.get(key.toString())
2124

2225
if (result == null) {
@@ -26,21 +29,21 @@ export class MemoryDatastore extends BaseDatastore {
2629
return result
2730
}
2831

29-
async has (key: Key): Promise<boolean> { // eslint-disable-line require-await
32+
has (key: Key): Await<boolean> { // eslint-disable-line require-await
3033
return this.data.has(key.toString())
3134
}
3235

33-
async delete (key: Key): Promise<void> { // eslint-disable-line require-await
36+
delete (key: Key): Await<void> { // eslint-disable-line require-await
3437
this.data.delete(key.toString())
3538
}
3639

37-
async * _all (): AsyncIterable<Pair> {
40+
* _all (): AwaitIterable<Pair> {
3841
for (const [key, value] of this.data.entries()) {
3942
yield { key: new Key(key), value }
4043
}
4144
}
4245

43-
async * _allKeys (): AsyncIterable<Key> {
46+
* _allKeys (): AwaitIterable<Key> {
4447
for (const key of this.data.keys()) {
4548
yield new Key(key)
4649
}

src/mount.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BaseDatastore } from './base.js'
55
import * as Errors from './errors.js'
66
import sort from 'it-sort'
77
import type { Batch, Datastore, Key, KeyQuery, Pair, Query } from 'interface-datastore'
8-
import type { Options } from 'interface-store'
8+
import type { AbortOptions } from 'interface-store'
99

1010
/**
1111
* A datastore that can combine multiple stores inside various
@@ -34,36 +34,38 @@ export class MountDatastore extends BaseDatastore {
3434
}
3535
}
3636

37-
async put (key: Key, value: Uint8Array, options?: Options): Promise<void> {
37+
async put (key: Key, value: Uint8Array, options?: AbortOptions): Promise<Key> {
3838
const match = this._lookup(key)
3939
if (match == null) {
4040
throw Errors.dbWriteFailedError(new Error('No datastore mounted for this key'))
4141
}
4242

4343
await match.datastore.put(key, value, options)
44+
45+
return key
4446
}
4547

4648
/**
4749
* @param {Key} key
4850
* @param {Options} [options]
4951
*/
50-
async get (key: Key, options: Options = {}): Promise<Uint8Array> {
52+
async get (key: Key, options: AbortOptions = {}): Promise<Uint8Array> {
5153
const match = this._lookup(key)
5254
if (match == null) {
5355
throw Errors.notFoundError(new Error('No datastore mounted for this key'))
5456
}
5557
return await match.datastore.get(key, options)
5658
}
5759

58-
async has (key: Key, options?: Options): Promise<boolean> {
60+
async has (key: Key, options?: AbortOptions): Promise<boolean> {
5961
const match = this._lookup(key)
6062
if (match == null) {
6163
return await Promise.resolve(false)
6264
}
6365
return await match.datastore.has(key, options)
6466
}
6567

66-
async delete (key: Key, options?: Options): Promise<void> {
68+
async delete (key: Key, options?: AbortOptions): Promise<void> {
6769
const match = this._lookup(key)
6870
if (match == null) {
6971
throw Errors.dbDeleteFailedError(new Error('No datastore mounted for this key'))
@@ -106,7 +108,7 @@ export class MountDatastore extends BaseDatastore {
106108
}
107109
}
108110

109-
query (q: Query, options?: Options): AsyncIterable<Pair> {
111+
query (q: Query, options?: AbortOptions): AsyncIterable<Pair> {
110112
const qs = this.mounts.map(m => {
111113
return m.datastore.query({
112114
prefix: q.prefix,
@@ -127,7 +129,7 @@ export class MountDatastore extends BaseDatastore {
127129
return it
128130
}
129131

130-
queryKeys (q: KeyQuery, options?: Options): AsyncIterable<Key> {
132+
queryKeys (q: KeyQuery, options?: AbortOptions): AsyncIterable<Key> {
131133
const qs = this.mounts.map(m => {
132134
return m.datastore.queryKeys({
133135
prefix: q.prefix,

0 commit comments

Comments
 (0)