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

deps: update interface-store to 5.x.x #74

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@
},
"dependencies": {
"err-code": "^3.0.1",
"interface-blockstore": "^5.0.0",
"interface-store": "^4.0.0",
"interface-blockstore": "^5.1.1",
"interface-store": "^5.0.1",
"multiformats": "^11.0.0"
},
"devDependencies": {
"aegir": "^38.1.7",
"interface-blockstore-tests": "^5.0.0"
"interface-blockstore-tests": "^6.0.0"
}
}
33 changes: 18 additions & 15 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
import type { Blockstore, Options, Pair } from 'interface-blockstore'
import type { Blockstore, Pair } from 'interface-blockstore'
import type { AbortOptions, Await, AwaitIterable } from 'interface-store'
import type { CID } from 'multiformats/cid'
import type { AwaitIterable } from 'interface-store'

export class BaseBlockstore implements Blockstore {
async has (key: CID, options?: Options): Promise<boolean> {
return await Promise.reject(new Error('.has is not implemented'))
has (key: CID, options?: AbortOptions): Await<boolean> {
return Promise.reject(new Error('.has is not implemented'))
}

async put (key: CID, val: Uint8Array, options?: Options): Promise<void> {
await Promise.reject(new Error('.put is not implemented'))
put (key: CID, val: Uint8Array, options?: AbortOptions): Await<CID> {
return Promise.reject(new Error('.put is not implemented'))
}

async * putMany (source: AwaitIterable<Pair>, options?: Options): AsyncIterable<Pair> {
async * putMany (source: AwaitIterable<Pair>, options?: AbortOptions): AwaitIterable<CID> {
for await (const { cid, block } of source) {
await this.put(cid, block, options)
yield { cid, block }
yield cid
}
}

async get (key: CID, options?: Options): Promise<Uint8Array> {
return await Promise.reject(new Error('.get is not implemented'))
get (key: CID, options?: AbortOptions): Await<Uint8Array> {
return Promise.reject(new Error('.get is not implemented'))
}

async * getMany (source: AwaitIterable<CID>, options?: Options): AsyncIterable<Uint8Array> {
async * getMany (source: AwaitIterable<CID>, options?: AbortOptions): AwaitIterable<Pair> {
for await (const key of source) {
yield this.get(key, options)
yield {
cid: key,
block: await this.get(key, options)
}
}
}

async delete (key: CID, options?: Options): Promise<void> {
async delete (key: CID, options?: AbortOptions): Promise<void> {
await Promise.reject(new Error('.delete is not implemented'))
}

async * deleteMany (source: AwaitIterable<CID>, options?: Options): AsyncIterable<CID> {
async * deleteMany (source: AwaitIterable<CID>, options?: AbortOptions): AwaitIterable<CID> {
for await (const key of source) {
await this.delete(key, options)
yield key
Expand All @@ -42,7 +45,7 @@ export class BaseBlockstore implements Blockstore {
/**
* Extending classes should override `query` or implement this method
*/
async * getAll (options?: Options): AwaitIterable<Pair> { // eslint-disable-line require-yield
async * getAll (options?: AbortOptions): AwaitIterable<Pair> { // eslint-disable-line require-yield
throw new Error('.getAll is not implemented')
}
}
10 changes: 6 additions & 4 deletions src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as raw from 'multiformats/codecs/raw'
import { CID } from 'multiformats/cid'
import * as Digest from 'multiformats/hashes/digest'
import * as Errors from './errors.js'
import type { AwaitIterable } from 'interface-store'
import type { Await, AwaitIterable } from 'interface-store'
import type { Pair } from 'interface-blockstore'

export class MemoryBlockstore extends BaseBlockstore {
Expand All @@ -16,11 +16,13 @@ export class MemoryBlockstore extends BaseBlockstore {
this.data = new Map()
}

async put (key: CID, val: Uint8Array): Promise<void> { // eslint-disable-line require-await
put (key: CID, val: Uint8Array): Await<CID> { // eslint-disable-line require-await
this.data.set(base32.encode(key.multihash.bytes), val)

return key
}

async get (key: CID): Promise<Uint8Array> {
get (key: CID): Await<Uint8Array> {
const buf = this.data.get(base32.encode(key.multihash.bytes))

if (buf == null) {
Expand All @@ -30,7 +32,7 @@ export class MemoryBlockstore extends BaseBlockstore {
return buf
}

async has (key: CID): Promise<boolean> {
has (key: CID): Await<boolean> {
return this.data.has(base32.encode(key.multihash.bytes))
}

Expand Down