Skip to content

Commit

Permalink
chore: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald M Zielaznicki committed May 22, 2023
1 parent 553e8a7 commit 57d4268
Show file tree
Hide file tree
Showing 50 changed files with 212 additions and 208 deletions.
6 changes: 3 additions & 3 deletions packages/blockstore-core/src/memory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BaseBlockstore } from './base.js'
import { base32 } from 'multiformats/bases/base32'
import * as raw from 'multiformats/codecs/raw'
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'
import * as Digest from 'multiformats/hashes/digest'
import { BaseBlockstore } from './base.js'
import * as Errors from './errors.js'
import type { Await, AwaitIterable } from 'interface-store'
import type { Pair } from 'interface-blockstore'
import type { Await, AwaitIterable } from 'interface-store'

export class MemoryBlockstore extends BaseBlockstore {
private readonly data: Map<string, Uint8Array>
Expand Down
8 changes: 4 additions & 4 deletions packages/blockstore-fs/benchmarks/encoding/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Bench } from 'tinybench'
import { CID } from 'multiformats/cid'
import { base8 } from 'multiformats/bases/base8'
import { base10 } from 'multiformats/bases/base10'
import { base16upper } from 'multiformats/bases/base16'
import { base256emoji } from 'multiformats/bases/base256emoji'
import { base32, base32upper, base32hexupper, base32z } from 'multiformats/bases/base32'
import { base36, base36upper } from 'multiformats/bases/base36'
import { base256emoji } from 'multiformats/bases/base256emoji'
import { base8 } from 'multiformats/bases/base8'
import { CID } from 'multiformats/cid'
import { Bench } from 'tinybench'

const RESULT_PRECISION = 2

Expand Down
10 changes: 5 additions & 5 deletions packages/blockstore-fs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import fs from 'node:fs/promises'
import glob from 'it-glob'
import path from 'node:path'
import { promisify } from 'node:util'
import {
Errors
} from 'blockstore-core'
import map from 'it-map'
import parallelBatch from 'it-parallel-batch'
// @ts-expect-error no types
import fwa from 'fast-write-atomic'
import type { CID } from 'multiformats/cid'
import glob from 'it-glob'
import map from 'it-map'
import parallelBatch from 'it-parallel-batch'
import { NextToLast, type ShardingStrategy } from './sharding.js'
import type { Blockstore, Pair } from 'interface-blockstore'
import type { AwaitIterable } from 'interface-store'
import { NextToLast, ShardingStrategy } from './sharding.js'
import type { CID } from 'multiformats/cid'

const writeAtomic = promisify(fwa)

Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-fs/src/sharding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import { CID } from 'multiformats/cid'
import { base32upper } from 'multiformats/bases/base32'
import { CID } from 'multiformats/cid'
import type { MultibaseCodec } from 'multiformats/bases/interface'

export interface ShardingStrategy {
Expand Down
10 changes: 5 additions & 5 deletions packages/blockstore-fs/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs/promises'
import { CID } from 'multiformats/cid'
import os from 'node:os'
import path from 'node:path'
import { expect } from 'aegir/chai'
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
import { base256emoji } from 'multiformats/bases/base256emoji'
import { CID } from 'multiformats/cid'
import { FsBlockstore } from '../src/index.js'
import { FlatDirectory, NextToLast } from '../src/sharding.js'
import { base256emoji } from 'multiformats/bases/base256emoji'

const utf8Encoder = new TextEncoder()

Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-fs/test/sharding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { base32upper } from 'multiformats/bases/base32'
import { CID } from 'multiformats/cid'
import { FlatDirectory, NextToLast } from '../src/sharding.js'
import { base32upper } from 'multiformats/bases/base32'

describe('flat', () => {
it('should encode', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/blockstore-idb/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { openDB, IDBPDatabase, deleteDB } from 'idb'
import {
BaseBlockstore,
Errors
} from 'blockstore-core'
import { CID } from 'multiformats/cid'
import type { MultibaseCodec } from 'multiformats/bases/interface'
import { openDB, type IDBPDatabase, deleteDB } from 'idb'
import { base32upper } from 'multiformats/bases/base32'
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'
import * as Digest from 'multiformats/hashes/digest'
import type { Pair } from 'interface-blockstore'
import type { AbortOptions, AwaitIterable } from 'interface-store'
import type { MultibaseCodec } from 'multiformats/bases/interface'

export interface IDBDatastoreInit {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/blockstore-idb/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-env mocha */

import { expect } from 'aegir/chai'
import { IDBBlockstore } from '../src/index.js'
import { CID } from 'multiformats/cid'
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
import { CID } from 'multiformats/cid'
import { IDBBlockstore } from '../src/index.js'

describe('IndexedDB Blockstore', function () {
describe('interface-blockstore (idb)', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/blockstore-level/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Pair } from 'interface-blockstore'
import { BaseBlockstore, Errors } from 'blockstore-core'
import { Level } from 'level'
import { CID } from 'multiformats/cid'
import type { DatabaseOptions, OpenOptions, IteratorOptions } from 'level'
import type { MultibaseCodec } from 'multiformats/bases/interface'
import { base32upper } from 'multiformats/bases/base32'
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'
import * as Digest from 'multiformats/hashes/digest'
import type { Pair } from 'interface-blockstore'
import type { AbortOptions, AwaitIterable } from 'interface-store'
import type { DatabaseOptions, OpenOptions, IteratorOptions } from 'level'
import type { MultibaseCodec } from 'multiformats/bases/interface'

export interface LevelBlockstoreInit extends DatabaseOptions<string, Uint8Array>, OpenOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LevelBlockstore } from '../../src/index.js'
import tempdir from 'ipfs-utils/src/temp-dir.js'
import { CID } from 'multiformats/cid'
import { LevelBlockstore } from '../../src/index.js'

async function testLevelIteratorDestroy (): Promise<void> {
const store = new LevelBlockstore(tempdir())
Expand Down
6 changes: 3 additions & 3 deletions packages/blockstore-level/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-env mocha */

import { expect } from 'aegir/chai'
import { MemoryLevel } from 'memory-level'
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
import tempdir from 'ipfs-utils/src/temp-dir.js'
import { Level } from 'level'
import { MemoryLevel } from 'memory-level'
import { LevelBlockstore } from '../src/index.js'
import tempdir from 'ipfs-utils/src/temp-dir.js'
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'

describe('LevelBlockstore', () => {
describe('initialization', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/blockstore-level/test/node.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-env mocha */

import { expect } from 'aegir/chai'
import path from 'path'
import childProcess from 'child_process'
import path from 'path'
import { expect } from 'aegir/chai'
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
import { LevelBlockstore } from '../src/index.js'
import tempdir from 'ipfs-utils/src/temp-dir.js'
import { LevelBlockstore } from '../src/index.js'

describe('LevelDatastore', () => {
describe('interface-blockstore (leveldown)', () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/blockstore-s3/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import type { Pair } from 'interface-blockstore'
import { BaseBlockstore } from 'blockstore-core/base'
import * as Errors from 'blockstore-core/errors'
import { fromString as unint8arrayFromString } from 'uint8arrays'
import toBuffer from 'it-to-buffer'
import type { S3 } from '@aws-sdk/client-s3'
import type { AbortOptions } from 'interface-store'
import {
PutObjectCommand,
CreateBucketCommand,
Expand All @@ -13,8 +6,15 @@ import {
DeleteObjectCommand,
ListObjectsV2Command
} from '@aws-sdk/client-s3'
import { BaseBlockstore } from 'blockstore-core/base'
import * as Errors from 'blockstore-core/errors'
import toBuffer from 'it-to-buffer'
import { fromString as unint8arrayFromString } from 'uint8arrays'
import { NextToLast, type ShardingStrategy } from './sharding.js'
import type { S3 } from '@aws-sdk/client-s3'
import type { Pair } from 'interface-blockstore'
import type { AbortOptions } from 'interface-store'
import type { CID } from 'multiformats/cid'
import { NextToLast, ShardingStrategy } from './sharding.js'

export interface S3BlockstoreInit {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/blockstore-s3/src/sharding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CID } from 'multiformats/cid'
import { base32upper } from 'multiformats/bases/base32'
import { CID } from 'multiformats/cid'
import type { MultibaseCodec } from 'multiformats/bases/interface'

export interface ShardingStrategy {
Expand Down
9 changes: 4 additions & 5 deletions packages/blockstore-s3/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-env mocha */

import { type CreateBucketCommand, type HeadObjectCommand, S3 } from '@aws-sdk/client-s3'
import { expect } from 'aegir/chai'
import sinon from 'sinon'
import { CreateBucketCommand, HeadObjectCommand, S3 } from '@aws-sdk/client-s3'
import defer from 'p-defer'
import { interfaceBlockstoreTests } from 'interface-blockstore-tests'
import { CID } from 'multiformats/cid'

import { s3Resolve, s3Reject, S3Error, s3Mock } from './utils/s3-mock.js'
import defer from 'p-defer'
import sinon from 'sinon'
import { S3Blockstore } from '../src/index.js'
import { s3Resolve, s3Reject, S3Error, s3Mock } from './utils/s3-mock.js'

const cid = CID.parse('QmeimKZyjcBnuXmAD9zMnSjM9JodTbgGT3gutofkTqz9rE')

Expand Down
4 changes: 2 additions & 2 deletions packages/blockstore-s3/test/utils/s3-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const s3Reject = <T> (err: T): any => {
*/
export function s3Mock (s3: S3): S3 {
const mocks: any = {}
const storage: Map<string, any> = new Map()
const storage = new Map<string, any>()

mocks.send = sinon.replace(s3, 'send', (command) => {
mocks.send = sinon.replace(s3, 'send', (command: Parameters<S3['send']>[0]) => {
const commandName = command.constructor.name
const input: any = command.input

Expand Down
10 changes: 8 additions & 2 deletions packages/datastore-core/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sort from 'it-sort'
import drain from 'it-drain'
import filter from 'it-filter'
import sort from 'it-sort'
import take from 'it-take'
import type { Batch, Datastore, Key, KeyQuery, Pair, Query } from 'interface-datastore'
import type { AbortOptions, Await, AwaitIterable } from 'interface-store'
Expand Down Expand Up @@ -50,16 +50,22 @@ export class BaseDatastore implements Datastore {
let dels: Key[] = []

return {
put (key, value) {
put (key: Key, value) {
puts.push({ key, value })
},

delete (key) {
dels.push(key)
},

commit: async (options) => {
// @see https://github.com/ipfs/js-stores/issues/221
// eslint-disable-next-line @typescript-eslint/await-thenable, @typescript-eslint/no-confusing-void-expression
await drain(this.putMany(puts, options))
puts = []

// @see https://github.com/ipfs/js-stores/issues/221
// eslint-disable-next-line @typescript-eslint/await-thenable, @typescript-eslint/no-confusing-void-expression
await drain(this.deleteMany(dels, options))
dels = []
}
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Key } from 'interface-datastore'

import * as Errors from './errors.js'
import * as shard from './shard.js'
import type { Key } from 'interface-datastore'

export { BaseDatastore } from './base.js'
export { MemoryDatastore } from './memory.js'
Expand Down
10 changes: 4 additions & 6 deletions packages/datastore-core/src/keytransform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseDatastore } from './base.js'
import map from 'it-map'
import { pipe } from 'it-pipe'
import { BaseDatastore } from './base.js'
import type { KeyTransform } from './index.js'
import type { Batch, Datastore, Key, KeyQuery, Pair, Query } from 'interface-datastore'
import type { AbortOptions, AwaitIterable } from 'interface-store'
Expand All @@ -22,17 +22,15 @@ export class KeyTransformDatastore extends BaseDatastore {
}

async put (key: Key, val: Uint8Array, options?: AbortOptions): Promise<Key> {
await this.child.put(this.transform.convert(key), val, options)

return key
return this.child.put(this.transform.convert(key), val, options)
}

async get (key: Key, options?: AbortOptions): Promise<Uint8Array> {
return await this.child.get(this.transform.convert(key), options)
return this.child.get(this.transform.convert(key), options)
}

async has (key: Key, options?: AbortOptions): Promise<boolean> {
return await this.child.has(this.transform.convert(key), options)
return this.child.has(this.transform.convert(key), options)
}

async delete (key: Key, options?: AbortOptions): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore-core/src/memory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseDatastore } from './base.js'
import { Key } from 'interface-datastore/key'
import { BaseDatastore } from './base.js'
import * as Errors from './errors.js'
import type { Pair } from 'interface-datastore'
import type { Await, AwaitIterable } from 'interface-store'
Expand Down
12 changes: 6 additions & 6 deletions packages/datastore-core/src/mount.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import filter from 'it-filter'
import take from 'it-take'
import merge from 'it-merge'
import sort from 'it-sort'
import take from 'it-take'
import { BaseDatastore } from './base.js'
import * as Errors from './errors.js'
import sort from 'it-sort'
import type { Batch, Datastore, Key, KeyQuery, Pair, Query } from 'interface-datastore'
import type { AbortOptions } from 'interface-store'

Expand Down Expand Up @@ -49,20 +49,20 @@ export class MountDatastore extends BaseDatastore {
* @param {Key} key
* @param {Options} [options]
*/
async get (key: Key, options: AbortOptions = {}): Promise<Uint8Array> {
async get (key: Key, options?: AbortOptions): Promise<Uint8Array> {
const match = this._lookup(key)
if (match == null) {
throw Errors.notFoundError(new Error('No datastore mounted for this key'))
}
return await match.datastore.get(key, options)
return match.datastore.get(key, options)
}

async has (key: Key, options?: AbortOptions): Promise<boolean> {
const match = this._lookup(key)
if (match == null) {
return await Promise.resolve(false)
return Promise.resolve(false)
}
return await match.datastore.has(key, options)
return match.datastore.has(key, options)
}

async delete (key: Key, options?: AbortOptions): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore-core/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Key } from 'interface-datastore'
import type { Datastore } from 'interface-datastore'
import { KeyTransformDatastore } from './keytransform.js'
import type { Datastore } from 'interface-datastore'

/**
* Wraps a given datastore into a keytransform which
Expand Down
6 changes: 2 additions & 4 deletions packages/datastore-core/src/shard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Datastore } from 'interface-datastore'
import { Key } from 'interface-datastore/key'
import type { Shard } from './index.js'
import type { Datastore } from 'interface-datastore'

export const PREFIX = '/repo/flatfs/shard/'
export const SHARDING_FN = 'SHARDING'
Expand Down Expand Up @@ -108,8 +108,6 @@ export function parseShardFun (str: string): Shard {

export const readShardFun = async (path: string | Uint8Array, store: Datastore): Promise<Shard> => {
const key = new Key(path).child(new Key(SHARDING_FN))
// @ts-expect-error
const get = typeof store.getRaw === 'function' ? store.getRaw.bind(store) : store.get.bind(store)
const res = await get(key)
const res = await store.get(key)
return parseShardFun(new TextDecoder().decode(res ?? '').trim())
}
Loading

0 comments on commit 57d4268

Please sign in to comment.