Skip to content

Commit e252c39

Browse files
committed
chore: split query methods
1 parent 0ec1c0b commit e252c39

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/blockstore.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,18 @@ function createBaseStore (store) {
4545
return store.open()
4646
},
4747

48-
// @ts-ignore TODO: ts does not think we will yield only CIDs or only Blocks
4948
async * query (query, options) {
5049
for await (const { key, value } of store.query(query, options)) {
51-
// TODO: we should make this a different method
52-
if (query.keysOnly) {
53-
yield keyToCid(key)
54-
continue
55-
}
56-
5750
yield new Block(value, keyToCid(key))
5851
}
5952
},
6053

54+
async * queryKeys (query, options) {
55+
for await (const key of store.queryKeys(query, options)) {
56+
yield keyToCid(key)
57+
}
58+
},
59+
6160
async get (cid, options) {
6261
const key = cidToKey(cid)
6362
const blockData = await store.get(key, options)

src/idstore.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ function createIdStore (store) {
3131
return store.open()
3232
},
3333

34-
// @ts-ignore TODO: ts does not think we will yield only CIDs or only Blocks
3534
query (query, options) {
3635
return store.query(query, options)
3736
},
3837

38+
queryKeys (query, options) {
39+
return store.queryKeys(query, options)
40+
},
41+
3942
async get (cid, options) {
4043
const extracted = extractContents(cid)
4144
if (extracted.isIdentity) {

src/types.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import type { Datastore, Options as DatastoreOptions, Query, Key } from 'interface-datastore'
2+
import type { Datastore, Options as DatastoreOptions, Query, KeyQuery, Key } from 'interface-datastore'
33
import type CID from 'cids'
44
import type Block from 'ipld-block'
55

@@ -65,7 +65,12 @@ export interface Blockstore {
6565
/**
6666
* Query the store
6767
*/
68-
query: ((query: Query & { keysOnly: true }, options?: DatastoreOptions) => AsyncIterable<CID>) & ((query: Query, options?: DatastoreOptions) => AsyncIterable<Block>)
68+
query: (Query, options?: DatastoreOptions) => AsyncIterable<Block>
69+
70+
/**
71+
* Query the store, returning only keys
72+
*/
73+
queryKeys: (query: KeyQuery, options?: DatastoreOptions) => AsyncIterable<CID>
6974

7075
/**
7176
* Get a single block by CID

0 commit comments

Comments
 (0)