From 770d0cc04705e58208eb7a1b79caeb6a4ff346fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 May 2023 15:14:02 +0000 Subject: [PATCH 1/3] deps(dev): bump aegir from 38.1.8 to 39.0.6 Bumps [aegir](https://github.com/ipfs/aegir) from 38.1.8 to 39.0.6. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v38.1.8...v39.0.6) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- packages/ipfs-unixfs-exporter/package.json | 2 +- packages/ipfs-unixfs-importer/package.json | 2 +- packages/ipfs-unixfs/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 831f8c7a..7823f27a 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "release": "npm run docs:no-publish && aegir run release && npm run docs" }, "devDependencies": { - "aegir": "^38.1.2" + "aegir": "^39.0.6" }, "workspaces": [ "packages/*" diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index ca49cdf7..77f1097d 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -155,7 +155,7 @@ }, "devDependencies": { "@types/sinon": "^10.0.0", - "aegir": "^38.1.2", + "aegir": "^39.0.6", "blockstore-core": "^4.0.1", "delay": "^5.0.0", "ipfs-unixfs-importer": "^15.0.0", diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index a4165d49..6a2734f3 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -177,7 +177,7 @@ "uint8arrays": "^4.0.2" }, "devDependencies": { - "aegir": "^38.1.2", + "aegir": "^39.0.6", "blockstore-core": "^4.0.1", "it-buffer-stream": "^3.0.0", "it-drain": "^3.0.2", diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index a5f1d8ef..067c743d 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -144,7 +144,7 @@ "uint8arraylist": "^2.4.3" }, "devDependencies": { - "aegir": "^38.1.2", + "aegir": "^39.0.6", "protons": "^7.0.2", "uint8arrays": "^4.0.2" }, From 079af21450158946128217f7e8855b40ebe77e79 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 11 May 2023 16:59:13 +0100 Subject: [PATCH 2/3] chore: fix linting --- packages/ipfs-unixfs-exporter/src/index.ts | 6 +-- .../src/resolvers/dag-cbor.ts | 4 +- .../src/resolvers/identity.ts | 4 +- .../src/resolvers/index.ts | 11 +++-- .../ipfs-unixfs-exporter/src/resolvers/raw.ts | 4 +- .../resolvers/unixfs-v1/content/directory.ts | 6 +-- .../src/resolvers/unixfs-v1/content/file.ts | 16 +++---- .../content/hamt-sharded-directory.ts | 6 +-- .../src/resolvers/unixfs-v1/content/raw.ts | 2 +- .../src/resolvers/unixfs-v1/index.ts | 6 +-- .../src/utils/find-cid-in-shard.ts | 6 +-- .../test/exporter-esoteric.spec.ts | 14 +++--- .../test/exporter-sharded.spec.ts | 18 ++++---- .../test/exporter-subtree.spec.ts | 6 +-- .../test/exporter.spec.ts | 40 ++++++++--------- .../test/import-export-dir-sharding.spec.ts | 6 +-- .../test/import-export-nested-dir.spec.ts | 6 +-- .../test/import-export.spec.ts | 24 +++++----- .../test/importer.spec.ts | 44 +++++++++++-------- .../ipfs-unixfs-importer/src/chunker/rabin.ts | 6 +-- .../src/dag-builder/buffer-importer.ts | 6 +-- .../src/dag-builder/dir.ts | 2 +- .../src/dag-builder/file.ts | 8 ++-- .../src/dag-builder/index.ts | 12 ++--- packages/ipfs-unixfs-importer/src/dir-flat.ts | 12 ++--- .../ipfs-unixfs-importer/src/dir-sharded.ts | 12 ++--- packages/ipfs-unixfs-importer/src/dir.ts | 4 +- .../ipfs-unixfs-importer/src/flat-to-shard.ts | 7 ++- packages/ipfs-unixfs-importer/src/index.ts | 26 +++++------ .../src/layout/balanced.ts | 4 +- .../ipfs-unixfs-importer/src/layout/flat.ts | 2 +- .../src/layout/trickle.ts | 20 ++++----- .../ipfs-unixfs-importer/src/tree-builder.ts | 2 +- .../ipfs-unixfs-importer/src/utils/persist.ts | 4 +- .../test/builder-balanced.spec.ts | 8 ++-- .../test/builder-flat.spec.ts | 4 +- .../test/builder-trickle-dag.spec.ts | 16 +++---- .../test/chunker-custom.spec.ts | 10 ++--- .../test/chunker-fixed-size.spec.ts | 4 +- .../test/chunker-rabin.spec.ts | 6 +-- .../test/hash-parity-with-go-ipfs.spec.ts | 8 ++-- .../ipfs-unixfs/test/unixfs-format.spec.ts | 3 +- 42 files changed, 209 insertions(+), 206 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/src/index.ts b/packages/ipfs-unixfs-exporter/src/index.ts index c9ed8fcb..e0293c53 100644 --- a/packages/ipfs-unixfs-exporter/src/index.ts +++ b/packages/ipfs-unixfs-exporter/src/index.ts @@ -1,11 +1,11 @@ import errCode from 'err-code' +import last from 'it-last' import { CID } from 'multiformats/cid' import resolve from './resolvers/index.js' -import last from 'it-last' -import type { UnixFS } from 'ipfs-unixfs' import type { PBNode } from '@ipld/dag-pb' -import type { Blockstore } from 'interface-blockstore' import type { Bucket } from 'hamt-sharding' +import type { Blockstore } from 'interface-blockstore' +import type { UnixFS } from 'ipfs-unixfs' import type { ProgressOptions, ProgressEvent } from 'progress-events' export interface ExportProgress { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts b/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts index 8531e2df..a653a1ad 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts @@ -1,6 +1,6 @@ -import { CID } from 'multiformats/cid' -import errCode from 'err-code' import * as dagCbor from '@ipld/dag-cbor' +import errCode from 'err-code' +import { CID } from 'multiformats/cid' import type { Resolver } from '../index.js' const resolve: Resolver = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/identity.ts b/packages/ipfs-unixfs-exporter/src/resolvers/identity.ts index 31de81e6..861e6dc7 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/identity.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/identity.ts @@ -1,9 +1,9 @@ import errCode from 'err-code' +import * as mh from 'multiformats/hashes/digest' +import { CustomProgressEvent } from 'progress-events' import extractDataFromBlock from '../utils/extract-data-from-block.js' import validateOffsetAndLength from '../utils/validate-offset-and-length.js' -import * as mh from 'multiformats/hashes/digest' import type { ExporterOptions, Resolver, ExportProgress } from '../index.js' -import { CustomProgressEvent } from 'progress-events' const rawContent = (node: Uint8Array): ((options?: ExporterOptions) => AsyncGenerator) => { async function * contentGenerator (options: ExporterOptions = {}): AsyncGenerator { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/index.ts b/packages/ipfs-unixfs-exporter/src/resolvers/index.ts index fbd5dbbb..4f3279cd 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/index.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/index.ts @@ -1,14 +1,13 @@ -import errCode from 'err-code' -import * as dagPb from '@ipld/dag-pb' import * as dagCbor from '@ipld/dag-cbor' +import * as dagPb from '@ipld/dag-pb' +import errCode from 'err-code' import * as raw from 'multiformats/codecs/raw' import { identity } from 'multiformats/hashes/identity' - -import dagPbResolver from './unixfs-v1/index.js' -import rawResolver from './raw.js' import dagCborResolver from './dag-cbor.js' import identifyResolver from './identity.js' +import rawResolver from './raw.js' +import dagPbResolver from './unixfs-v1/index.js' import type { Resolve, Resolver } from '../index.js' const resolvers: Record = { @@ -25,7 +24,7 @@ const resolve: Resolve = async (cid, name, path, toResolve, depth, blockstore, o throw errCode(new Error(`No resolver for code ${cid.code}`), 'ERR_NO_RESOLVER') } - return await resolver(cid, name, path, toResolve, resolve, depth, blockstore, options) + return resolver(cid, name, path, toResolve, resolve, depth, blockstore, options) } export default resolve diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/raw.ts b/packages/ipfs-unixfs-exporter/src/resolvers/raw.ts index d90cc026..7b5d2429 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/raw.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/raw.ts @@ -1,8 +1,8 @@ import errCode from 'err-code' -import type { ExporterOptions, Resolver, ExportProgress } from '../index.js' +import { CustomProgressEvent } from 'progress-events' import extractDataFromBlock from '../utils/extract-data-from-block.js' import validateOffsetAndLength from '../utils/validate-offset-and-length.js' -import { CustomProgressEvent } from 'progress-events' +import type { ExporterOptions, Resolver, ExportProgress } from '../index.js' const rawContent = (node: Uint8Array): ((options?: ExporterOptions) => AsyncGenerator) => { async function * contentGenerator (options: ExporterOptions = {}): AsyncGenerator { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts index 8db82377..bfa1d61d 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts @@ -1,9 +1,9 @@ +import filter from 'it-filter' +import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' -import map from 'it-map' -import filter from 'it-filter' -import type { ExporterOptions, ExportWalk, UnixfsV1DirectoryContent, UnixfsV1Resolver } from '../../../index.js' import { CustomProgressEvent } from 'progress-events' +import type { ExporterOptions, ExportWalk, UnixfsV1DirectoryContent, UnixfsV1Resolver } from '../../../index.js' const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { async function * yieldDirectoryContent (options: ExporterOptions = {}): UnixfsV1DirectoryContent { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts index 07947804..1da18056 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts @@ -1,16 +1,16 @@ -import extractDataFromBlock from '../../../utils/extract-data-from-block.js' -import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js' -import { UnixFS } from 'ipfs-unixfs' -import errCode from 'err-code' import * as dagPb from '@ipld/dag-pb' -import * as raw from 'multiformats/codecs/raw' -import { Pushable, pushable } from 'it-pushable' +import errCode from 'err-code' +import { UnixFS } from 'ipfs-unixfs' +import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' -import map from 'it-map' +import { type Pushable, pushable } from 'it-pushable' +import * as raw from 'multiformats/codecs/raw' import PQueue from 'p-queue' -import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver, ReadableStorage, ExportProgress, ExportWalk } from '../../../index.js' import { CustomProgressEvent } from 'progress-events' +import extractDataFromBlock from '../../../utils/extract-data-from-block.js' +import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js' +import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver, ReadableStorage, ExportProgress, ExportWalk } from '../../../index.js' async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8Array, queue: Pushable, streamPosition: bigint, start: bigint, end: bigint, options: ExporterOptions): Promise { // a `raw` node diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts index ec070b6c..2f2126ce 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts @@ -1,9 +1,9 @@ +import { decode, type PBNode } from '@ipld/dag-pb' +import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' -import map from 'it-map' -import { decode, PBNode } from '@ipld/dag-pb' -import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk } from '../../../index.js' import { CustomProgressEvent } from 'progress-events' +import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk } from '../../../index.js' const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { function yieldHamtDirectoryContent (options: ExporterOptions = {}): UnixfsV1DirectoryContent { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts index 74a2ba30..73a0b71b 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts @@ -1,7 +1,7 @@ import { CustomProgressEvent } from 'progress-events' -import type { ExporterOptions, ExportProgress, ExportWalk, UnixfsV1Resolver } from '../../../index.js' import extractDataFromBlock from '../../../utils/extract-data-from-block.js' import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js' +import type { ExporterOptions, ExportProgress, ExportWalk, UnixfsV1Resolver } from '../../../index.js' const rawContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { function * yieldRawContent (options: ExporterOptions = {}): Generator { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts index 127694be..148ac81f 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts @@ -1,12 +1,12 @@ +import { decode, type PBNode } from '@ipld/dag-pb' import errCode from 'err-code' import { UnixFS } from 'ipfs-unixfs' import findShardCid from '../../utils/find-cid-in-shard.js' -import { decode, PBNode } from '@ipld/dag-pb' -import contentFile from './content/file.js' import contentDirectory from './content/directory.js' +import contentFile from './content/file.js' import contentHamtShardedDirectory from './content/hamt-sharded-directory.js' -import type { CID } from 'multiformats/cid' import type { Resolver, UnixfsV1Resolver } from '../../index.js' +import type { CID } from 'multiformats/cid' const findLinkCid = (node: PBNode, name: string): CID | undefined => { const link = node.Links.find(link => link.Name === name) diff --git a/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts b/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts index b029ad2a..3b257320 100644 --- a/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +++ b/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts @@ -1,7 +1,7 @@ -import { Bucket, BucketPosition, createHAMT } from 'hamt-sharding' -import { decode, PBLink, PBNode } from '@ipld/dag-pb' +import { decode, type PBLink, type PBNode } from '@ipld/dag-pb' import { murmur3128 } from '@multiformats/murmur3' +import { Bucket, type BucketPosition, createHAMT } from 'hamt-sharding' import type { ExporterOptions, ShardTraversalContext, ReadableStorage } from '../index.js' import type { CID } from 'multiformats/cid' @@ -120,7 +120,7 @@ const findShardCid = async (node: PBNode, name: string, blockstore: ReadableStor const block = await blockstore.get(link.Hash, options) node = decode(block) - return await findShardCid(node, name, blockstore, context, options) + return findShardCid(node, name, blockstore, context, options) } export default findShardCid diff --git a/packages/ipfs-unixfs-exporter/test/exporter-esoteric.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter-esoteric.spec.ts index a99de23d..2653c5cf 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-esoteric.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter-esoteric.spec.ts @@ -1,18 +1,18 @@ /* eslint-env mocha */ +import * as dagPb from '@ipld/dag-pb' import { expect } from 'aegir/chai' -import all from 'it-all' import { MemoryBlockstore } from 'blockstore-core' -import { concat, concat as uint8ArrayConcat } from 'uint8arrays/concat' -import { exporter } from './../src/index.js' +import { UnixFS } from 'ipfs-unixfs' import randomBytes from 'iso-random-stream/src/random.js' -import { sha256 } from 'multiformats/hashes/sha2' +import all from 'it-all' import { CID } from 'multiformats/cid' import * as raw from 'multiformats/codecs/raw' -import { UnixFS } from 'ipfs-unixfs' -import * as dagPb from '@ipld/dag-pb' -import type { Blockstore } from 'interface-blockstore' +import { sha256 } from 'multiformats/hashes/sha2' +import { concat, concat as uint8ArrayConcat } from 'uint8arrays/concat' import { isNode } from 'wherearewe' +import { exporter } from './../src/index.js' +import type { Blockstore } from 'interface-blockstore' describe('exporter esoteric DAGs', () => { let block: Blockstore diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts index f473849f..7d1b1be6 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts @@ -1,18 +1,18 @@ /* eslint-env mocha */ +import * as dagPb from '@ipld/dag-pb' import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' import { UnixFS } from 'ipfs-unixfs' +import { importer } from 'ipfs-unixfs-importer' import all from 'it-all' -import last from 'it-last' import randomBytes from 'it-buffer-stream' -import { exporter, walkPath } from '../src/index.js' -import { importer } from 'ipfs-unixfs-importer' -import * as dagPb from '@ipld/dag-pb' -import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import asAsyncIterable from './helpers/as-async-iterable.js' +import last from 'it-last' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { MemoryBlockstore } from 'blockstore-core' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { exporter, walkPath } from '../src/index.js' +import asAsyncIterable from './helpers/as-async-iterable.js' const SHARD_SPLIT_THRESHOLD = 10 @@ -22,7 +22,7 @@ describe('exporter sharded', function () { const block = new MemoryBlockstore() const createShard = async (numFiles: number): Promise => { - return await createShardWithFileNames(numFiles, (index) => `file-${index}`) + return createShardWithFileNames(numFiles, (index) => `file-${index}`) } const createShardWithFileNames = async (numFiles: number, fileName: (index: number) => string): Promise => { @@ -31,7 +31,7 @@ describe('exporter sharded', function () { content: asAsyncIterable(Uint8Array.from([0, 1, 2, 3, 4, index])) })) - return await createShardWithFiles(files) + return createShardWithFiles(files) } const createShardWithFiles = async (files: Array<{ path: string, content: AsyncIterable }>): Promise => { diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.ts index 5958d2e6..41a456fa 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.ts @@ -1,14 +1,14 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' import { importer } from 'ipfs-unixfs-importer' import all from 'it-all' -import last from 'it-last' -import { MemoryBlockstore } from 'blockstore-core' import randomBytes from 'it-buffer-stream' +import last from 'it-last' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import asAsyncIterable from './helpers/as-async-iterable.js' import { exporter, walkPath } from './../src/index.js' +import asAsyncIterable from './helpers/as-async-iterable.js' const ONE_MEG = Math.pow(1024, 2) diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter.spec.ts index 367611aa..af28be2e 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.ts @@ -1,33 +1,33 @@ /* eslint-env mocha */ +import * as dagCbor from '@ipld/dag-cbor' +import * as dagPb from '@ipld/dag-pb' import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' +import delay from 'delay' import { UnixFS } from 'ipfs-unixfs' -import { CID } from 'multiformats/cid' -import * as dagPb from '@ipld/dag-pb' -import * as dagCbor from '@ipld/dag-cbor' -import { sha256 } from 'multiformats/hashes/sha2' -import { identity } from 'multiformats/hashes/identity' -import * as raw from 'multiformats/codecs/raw' -import { exporter, recursive } from '../src/index.js' import { importer } from 'ipfs-unixfs-importer' +import { fixedSize } from 'ipfs-unixfs-importer/chunker' +import { balanced, type FileLayout, flat, trickle } from 'ipfs-unixfs-importer/layout' import all from 'it-all' -import last from 'it-last' -import first from 'it-first' import randomBytes from 'it-buffer-stream' -import { MemoryBlockstore } from 'blockstore-core' +import first from 'it-first' +import last from 'it-last' +import toBuffer from 'it-to-buffer' +import { CID } from 'multiformats/cid' +import * as raw from 'multiformats/codecs/raw' +import { identity } from 'multiformats/hashes/identity' +import { sha256 } from 'multiformats/hashes/sha2' +import { Readable } from 'readable-stream' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { isNode } from 'wherearewe' +import { exporter, recursive } from '../src/index.js' import asAsyncIterable from './helpers/as-async-iterable.js' -import delay from 'delay' import type { PBNode } from '@ipld/dag-pb' import type { Blockstore } from 'interface-blockstore' -import { balanced, FileLayout, flat, trickle } from 'ipfs-unixfs-importer/layout' import type { Chunker } from 'ipfs-unixfs-importer/chunker' -import { fixedSize } from 'ipfs-unixfs-importer/chunker' -import toBuffer from 'it-to-buffer' -import { Readable } from 'readable-stream' -import { isNode } from 'wherearewe' const ONE_MEG = Math.pow(1024, 2) @@ -336,7 +336,7 @@ describe('exporter', () => { async get (cid: CID) { await delay(Math.random() * 10) - return await block.get(cid) + return block.get(cid) } } @@ -1005,7 +1005,7 @@ describe('exporter', () => { throw new Error('Unexpected type') } - return await expect(first(exported.content())).to.eventually.deep.equal(node) + return expect(first(exported.content())).to.eventually.deep.equal(node) }) it('errors when exporting a node with no resolver', async () => { @@ -1219,7 +1219,7 @@ describe('exporter', () => { const customBlock = { get: async (cid: CID, options: { signal: AbortSignal }) => { // promise will never resolve, so reject it when the abort signal is sent - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { options.signal.addEventListener('abort', () => { reject(new Error(message)) }) @@ -1275,7 +1275,7 @@ describe('exporter', () => { const contentIterator = file.content() const readableStreamToBytes = async (readableStream: Readable): Promise => { - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { const chunks: any[] = [] readableStream.on('data', chunk => { chunks.push(chunk) diff --git a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.ts b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.ts index 8ea7ec40..2f4d5451 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.ts @@ -1,14 +1,14 @@ /* eslint-env mocha */ -import { importer } from 'ipfs-unixfs-importer' -import { exporter, UnixFSDirectory, UnixFSEntry } from '../src/index.js' import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' +import { importer } from 'ipfs-unixfs-importer' import all from 'it-all' import last from 'it-last' -import { MemoryBlockstore } from 'blockstore-core' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { exporter, type UnixFSDirectory, type UnixFSEntry } from '../src/index.js' import asAsyncIterable from './helpers/as-async-iterable.js' import type { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.ts b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.ts index 919fd04d..e1ef084a 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.ts @@ -1,13 +1,13 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import all from 'it-all' -import { importer } from 'ipfs-unixfs-importer' -import { exporter, UnixFSEntry } from '../src/index.js' import { MemoryBlockstore } from 'blockstore-core' +import { importer } from 'ipfs-unixfs-importer' +import all from 'it-all' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { exporter, type UnixFSEntry } from '../src/index.js' import asAsyncIterable from './helpers/as-async-iterable.js' import type { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-exporter/test/import-export.spec.ts b/packages/ipfs-unixfs-exporter/test/import-export.spec.ts index 8e400375..de7e6479 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/import-export.spec.ts @@ -4,32 +4,32 @@ import { expect } from 'aegir/chai' import loadFixture from 'aegir/fixtures' import { MemoryBlockstore } from 'blockstore-core' -import asAsyncIterable from './helpers/as-async-iterable.js' -import { importer } from 'ipfs-unixfs-importer' +import { importer, type ImporterOptions } from 'ipfs-unixfs-importer' +import { flat, balanced, trickle, type FileLayout } from 'ipfs-unixfs-importer/layout' import { exporter } from '../src/index.js' +import asAsyncIterable from './helpers/as-async-iterable.js' const bigFile = loadFixture(('test') + '/fixtures/1.2MiB.txt') -const strategies = [ - 'flat', - 'balanced', - 'trickle' -] +const layouts: Record = { + flat: flat(), + balanced: balanced(), + trickle: trickle() +} describe('import and export', function () { this.timeout(30 * 1000) - strategies.forEach((strategy) => { - const importerOptions = { strategy } + Object.entries(layouts).forEach(([name, layout]) => { + const importerOptions: ImporterOptions = { layout } - describe('using builder: ' + strategy, () => { + describe('using builder: ' + name, () => { const block = new MemoryBlockstore() it('imports and exports', async () => { - const path = `${strategy}-big.dat` + const path = `${name}-big.dat` const values = [{ path, content: asAsyncIterable(bigFile) }] - // @ts-expect-error for await (const file of importer(values, block, importerOptions)) { expect(file.path).to.equal(path) diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.ts b/packages/ipfs-unixfs-exporter/test/importer.spec.ts index 4043072c..8a354159 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.ts @@ -1,26 +1,26 @@ /* eslint-env mocha */ -import { importer, ImporterOptions } from 'ipfs-unixfs-importer' -import { exporter, recursive } from '../src/index.js' -import extend from 'merge-options' +import { decode } from '@ipld/dag-pb' import { expect } from 'aegir/chai' -import sinon from 'sinon' -import { Mtime, UnixFS } from 'ipfs-unixfs' -import collectLeafCids from './helpers/collect-leaf-cids.js' import loadFixture from 'aegir/fixtures' +import { MemoryBlockstore } from 'blockstore-core' +import { type Mtime, UnixFS } from 'ipfs-unixfs' +import { importer, type ImporterOptions } from 'ipfs-unixfs-importer' +import { fixedSize } from 'ipfs-unixfs-importer/chunker' +import { balanced, type FileLayout, flat, trickle } from 'ipfs-unixfs-importer/layout' import all from 'it-all' import first from 'it-first' -import { MemoryBlockstore } from 'blockstore-core' +import last from 'it-last' +import extend from 'merge-options' +import { base58btc } from 'multiformats/bases/base58' +import { CID } from 'multiformats/cid' +import sinon from 'sinon' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { exporter, recursive } from '../src/index.js' import asAsyncIterable from './helpers/as-async-iterable.js' -import last from 'it-last' -import { CID } from 'multiformats/cid' -import { base58btc } from 'multiformats/bases/base58' -import { decode } from '@ipld/dag-pb' +import collectLeafCids from './helpers/collect-leaf-cids.js' import type { Blockstore } from 'interface-blockstore' -import { balanced, FileLayout, flat, trickle } from 'ipfs-unixfs-importer/layout' -import { fixedSize } from 'ipfs-unixfs-importer/chunker' const bigFile = loadFixture('test/fixtures/1.2MiB.txt') const smallFile = loadFixture('test/fixtures/200Bytes.txt') @@ -44,7 +44,14 @@ function dateToTimespec (date: Date): Mtime { } } -const baseFiles = { +interface File { + cid: string + size: bigint + type: string + path: string +} + +const baseFiles: Record = { '200Bytes.txt': { cid: 'QmQmZQxSKQppbsWfVzBvg59Cn3DKtsNVQ94bjAxg2h3Lb8', size: 200n, @@ -65,7 +72,7 @@ const baseFiles = { } } -const strategyBaseFiles = { +const strategyBaseFiles: Record> = { flat: baseFiles, balanced: extend({}, baseFiles, { '1.2MiB.txt': { @@ -93,7 +100,7 @@ const strategies: Array<'flat' | 'balanced' | 'trickle'> = [ 'trickle' ] -const strategyOverrides = { +const strategyOverrides: Record> = { balanced: { 'foo-big': { cid: 'QmaFgyFJUP4fxFySJCddg2Pj6rpwSywopWk87VEVv52RSj', @@ -203,7 +210,7 @@ const checkLeafNodeTypes = async (blockstore: Blockstore, options: Partial await blockstore.get(link.Hash)) + node.Links.map(async link => blockstore.get(link.Hash)) ) linkedBlocks.forEach(bytes => { @@ -305,7 +312,6 @@ strategies.forEach((strategy) => { cid: 'QmVfHowk2oKuWFyVwSRt8H1dQ3v272jyWSwhfQnTtWNmfw', size: 200n }) - // @ts-expect-error }, strategyOverrides[strategy]) const expected = extend({}, defaultResults) @@ -1070,7 +1076,7 @@ describe('configuration', () => { /** @type {import('ipfs-unixfs-importer').DAGBuilder} */ dagBuilder: async function * (source, block) { // eslint-disable-line require-await yield async function () { - return await Promise.resolve({ + return Promise.resolve({ cid, path: 'path', unixfs, diff --git a/packages/ipfs-unixfs-importer/src/chunker/rabin.ts b/packages/ipfs-unixfs-importer/src/chunker/rabin.ts index 110185e7..2f0567c6 100644 --- a/packages/ipfs-unixfs-importer/src/chunker/rabin.ts +++ b/packages/ipfs-unixfs-importer/src/chunker/rabin.ts @@ -1,7 +1,7 @@ -import { Uint8ArrayList } from 'uint8arraylist' -// @ts-expect-error -import { create } from 'rabin-wasm' import errcode from 'err-code' +// @ts-expect-error no types +import { create } from 'rabin-wasm' +import { Uint8ArrayList } from 'uint8arraylist' import type { Chunker } from './index.js' const DEFAULT_MIN_CHUNK_SIZE = 262144 diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/buffer-importer.ts b/packages/ipfs-unixfs-importer/src/dag-builder/buffer-importer.ts index 66c8e9db..c52b7285 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/buffer-importer.ts +++ b/packages/ipfs-unixfs-importer/src/dag-builder/buffer-importer.ts @@ -1,10 +1,10 @@ -import { UnixFS } from 'ipfs-unixfs' -import { persist, PersistOptions } from '../utils/persist.js' import * as dagPb from '@ipld/dag-pb' +import { UnixFS } from 'ipfs-unixfs' import * as raw from 'multiformats/codecs/raw' +import { CustomProgressEvent } from 'progress-events' +import { persist, type PersistOptions } from '../utils/persist.js' import type { BufferImporter } from '../index.js' import type { CID, Version } from 'multiformats/cid' -import { CustomProgressEvent } from 'progress-events' import type { ProgressOptions, ProgressEvent } from 'progress-events' /** diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/dir.ts b/packages/ipfs-unixfs-importer/src/dag-builder/dir.ts index c86f4a5f..a29675f6 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/dir.ts +++ b/packages/ipfs-unixfs-importer/src/dag-builder/dir.ts @@ -1,6 +1,6 @@ +import { encode, prepare } from '@ipld/dag-pb' import { UnixFS } from 'ipfs-unixfs' import { persist } from '../utils/persist.js' -import { encode, prepare } from '@ipld/dag-pb' import type { Directory, InProgressImportResult, WritableStorage } from '../index.js' import type { Version } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file.ts b/packages/ipfs-unixfs-importer/src/dag-builder/file.ts index 27a59b64..41d94ca0 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file.ts +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file.ts @@ -1,12 +1,12 @@ +import { encode, type PBLink, type PBNode, prepare } from '@ipld/dag-pb' import { UnixFS } from 'ipfs-unixfs' -import { persist } from '../utils/persist.js' -import { encode, PBLink, PBNode, prepare } from '@ipld/dag-pb' import parallelBatch from 'it-parallel-batch' import * as rawCodec from 'multiformats/codecs/raw' +import { CustomProgressEvent } from 'progress-events' +import { persist } from '../utils/persist.js' import type { BufferImporter, File, InProgressImportResult, WritableStorage, SingleBlockImportResult, ImporterProgressEvents } from '../index.js' import type { FileLayout, Reducer } from '../layout/index.js' import type { CID, Version } from 'multiformats/cid' -import { CustomProgressEvent } from 'progress-events' import type { ProgressOptions, ProgressEvent } from 'progress-events' interface BuildFileBatchOptions { @@ -193,5 +193,5 @@ export interface FileBuilderOptions extends BuildFileBatchOptions, ReduceOptions } export const fileBuilder = async (file: File, block: WritableStorage, options: FileBuilderOptions): Promise => { - return await options.layout(buildFileBatch(file, block, options), reduce(file, block, options)) + return options.layout(buildFileBatch(file, block, options), reduce(file, block, options)) } diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/index.ts b/packages/ipfs-unixfs-importer/src/dag-builder/index.ts index 294f3b1f..1559b86a 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/index.ts +++ b/packages/ipfs-unixfs-importer/src/dag-builder/index.ts @@ -1,11 +1,11 @@ -import { dirBuilder, DirBuilderOptions } from './dir.js' -import { fileBuilder, FileBuilderOptions } from './file.js' import errCode from 'err-code' -import type { Directory, File, FileCandidate, ImportCandidate, ImporterProgressEvents, InProgressImportResult, WritableStorage } from '../index.js' +import { CustomProgressEvent } from 'progress-events' +import { dirBuilder, type DirBuilderOptions } from './dir.js' +import { fileBuilder, type FileBuilderOptions } from './file.js' import type { ChunkValidator } from './validate-chunks.js' import type { Chunker } from '../chunker/index.js' +import type { Directory, File, FileCandidate, ImportCandidate, ImporterProgressEvents, InProgressImportResult, WritableStorage } from '../index.js' import type { ProgressEvent, ProgressOptions } from 'progress-events' -import { CustomProgressEvent } from 'progress-events' /** * Passed to the onProgress callback while importing files @@ -107,7 +107,7 @@ export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder { originalPath } - yield async () => await fileBuilder(file, blockstore, options) + yield async () => fileBuilder(file, blockstore, options) } else if (entry.path != null) { const dir: Directory = { path: entry.path, @@ -116,7 +116,7 @@ export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder { originalPath } - yield async () => await dirBuilder(dir, blockstore, options) + yield async () => dirBuilder(dir, blockstore, options) } else { throw new Error('Import candidate must have content or path or both') } diff --git a/packages/ipfs-unixfs-importer/src/dir-flat.ts b/packages/ipfs-unixfs-importer/src/dir-flat.ts index 7d62a926..8783b8c2 100644 --- a/packages/ipfs-unixfs-importer/src/dir-flat.ts +++ b/packages/ipfs-unixfs-importer/src/dir-flat.ts @@ -1,10 +1,10 @@ -import { encode, PBNode, prepare } from '@ipld/dag-pb' -import type { Blockstore } from 'interface-blockstore' +import { encode, type PBNode, prepare } from '@ipld/dag-pb' import { UnixFS } from 'ipfs-unixfs' -import type { CID } from 'multiformats/cid' -import { Dir, CID_V0, CID_V1, DirProps } from './dir.js' +import { Dir, CID_V0, CID_V1, type DirProps } from './dir.js' +import { persist, type PersistOptions } from './utils/persist.js' import type { ImportResult, InProgressImportResult } from './index.js' -import { persist, PersistOptions } from './utils/persist.js' +import type { Blockstore } from 'interface-blockstore' +import type { CID } from 'multiformats/cid' export class DirFlat extends Dir { private readonly _children: Map @@ -24,7 +24,7 @@ export class DirFlat extends Dir { } async get (name: string): Promise { - return await Promise.resolve(this._children.get(name)) + return Promise.resolve(this._children.get(name)) } childCount (): number { diff --git a/packages/ipfs-unixfs-importer/src/dir-sharded.ts b/packages/ipfs-unixfs-importer/src/dir-sharded.ts index 24468629..c30fbfbb 100644 --- a/packages/ipfs-unixfs-importer/src/dir-sharded.ts +++ b/packages/ipfs-unixfs-importer/src/dir-sharded.ts @@ -1,9 +1,9 @@ -import { encode, PBLink, prepare } from '@ipld/dag-pb' -import { UnixFS } from 'ipfs-unixfs' -import { Dir, CID_V0, CID_V1, DirProps } from './dir.js' -import { persist, PersistOptions } from './utils/persist.js' -import { createHAMT, Bucket, BucketChild } from 'hamt-sharding' +import { encode, type PBLink, prepare } from '@ipld/dag-pb' import { murmur3128 } from '@multiformats/murmur3' +import { createHAMT, Bucket, type BucketChild } from 'hamt-sharding' +import { UnixFS } from 'ipfs-unixfs' +import { Dir, CID_V0, CID_V1, type DirProps } from './dir.js' +import { persist, type PersistOptions } from './utils/persist.js' import type { ImportResult, InProgressImportResult } from './index.js' import type { Blockstore } from 'interface-blockstore' @@ -40,7 +40,7 @@ class DirSharded extends Dir { } async get (name: string): Promise { - return await this._bucket.get(name) + return this._bucket.get(name) } childCount (): number { diff --git a/packages/ipfs-unixfs-importer/src/dir.ts b/packages/ipfs-unixfs-importer/src/dir.ts index 952541c8..3e1b2a4c 100644 --- a/packages/ipfs-unixfs-importer/src/dir.ts +++ b/packages/ipfs-unixfs-importer/src/dir.ts @@ -1,7 +1,7 @@ -import type { WritableStorage, ImportResult, InProgressImportResult } from './index.js' -import type { Mtime, UnixFS } from 'ipfs-unixfs' import { CID } from 'multiformats/cid' +import type { WritableStorage, ImportResult, InProgressImportResult } from './index.js' import type { PersistOptions } from './utils/persist.js' +import type { Mtime, UnixFS } from 'ipfs-unixfs' export interface DirProps { root: boolean diff --git a/packages/ipfs-unixfs-importer/src/flat-to-shard.ts b/packages/ipfs-unixfs-importer/src/flat-to-shard.ts index 5059d014..a5b4d419 100644 --- a/packages/ipfs-unixfs-importer/src/flat-to-shard.ts +++ b/packages/ipfs-unixfs-importer/src/flat-to-shard.ts @@ -1,10 +1,10 @@ -import DirSharded from './dir-sharded.js' import { DirFlat } from './dir-flat.js' +import DirSharded from './dir-sharded.js' import type { Dir } from './dir.js' import type { PersistOptions } from './utils/persist.js' export async function flatToShard (child: Dir | null, dir: Dir, threshold: number, options: PersistOptions): Promise { - let newDir = dir + let newDir = dir as DirSharded if (dir instanceof DirFlat && dir.estimateNodeSize() > threshold) { newDir = await convertToShard(dir, options) @@ -25,10 +25,9 @@ export async function flatToShard (child: Dir | null, dir: Dir, threshold: numbe await parent.put(newDir.parentKey, newDir) } - return await flatToShard(newDir, parent, threshold, options) + return flatToShard(newDir, parent, threshold, options) } - // @ts-expect-error return newDir } diff --git a/packages/ipfs-unixfs-importer/src/index.ts b/packages/ipfs-unixfs-importer/src/index.ts index 7c73743b..fbd69b1b 100644 --- a/packages/ipfs-unixfs-importer/src/index.ts +++ b/packages/ipfs-unixfs-importer/src/index.ts @@ -1,19 +1,19 @@ +import errcode from 'err-code' +import first from 'it-first' import parallelBatch from 'it-parallel-batch' -import { DAGBuilder, DagBuilderProgressEvents, defaultDagBuilder } from './dag-builder/index.js' -import { defaultTreeBuilder } from './tree-builder.js' -import type { UnixFS, Mtime } from 'ipfs-unixfs' -import type { CID, Version as CIDVersion } from 'multiformats/cid' -import type { Blockstore } from 'interface-blockstore' -import { ChunkValidator, defaultChunkValidator } from './dag-builder/validate-chunks.js' import { fixedSize } from './chunker/fixed-size.js' +import { type BufferImportProgressEvents, defaultBufferImporter } from './dag-builder/buffer-importer.js' +import { type DAGBuilder, type DagBuilderProgressEvents, defaultDagBuilder } from './dag-builder/index.js' +import { type ChunkValidator, defaultChunkValidator } from './dag-builder/validate-chunks.js' +import { balanced, type FileLayout } from './layout/index.js' +import { defaultTreeBuilder } from './tree-builder.js' import type { Chunker } from './chunker/index.js' -import { balanced, FileLayout } from './layout/index.js' -import { BufferImportProgressEvents, defaultBufferImporter } from './dag-builder/buffer-importer.js' -import first from 'it-first' -import errcode from 'err-code' +import type { ReducerProgressEvents } from './dag-builder/file.js' +import type { Blockstore } from 'interface-blockstore' import type { AwaitIterable } from 'interface-store' +import type { UnixFS, Mtime } from 'ipfs-unixfs' +import type { CID, Version as CIDVersion } from 'multiformats/cid' import type { ProgressOptions } from 'progress-events' -import type { ReducerProgressEvents } from './dag-builder/file.js' export type ByteStream = AwaitIterable export type ImportContent = ByteStream | Uint8Array @@ -365,7 +365,7 @@ export async function importDirectory (content: DirectoryCandidate, blockstore: * ``` */ export async function importBytes (buf: ImportContent, blockstore: WritableStorage, options: ImporterOptions = {}): Promise { - return await importFile({ + return importFile({ content: buf }, blockstore, options) } @@ -392,7 +392,7 @@ export async function importBytes (buf: ImportContent, blockstore: WritableStora * ``` */ export async function importByteStream (bufs: ByteStream, blockstore: WritableStorage, options: ImporterOptions = {}): Promise { - return await importFile({ + return importFile({ content: bufs }, blockstore, options) } diff --git a/packages/ipfs-unixfs-importer/src/layout/balanced.ts b/packages/ipfs-unixfs-importer/src/layout/balanced.ts index 30194f7c..944538a5 100644 --- a/packages/ipfs-unixfs-importer/src/layout/balanced.ts +++ b/packages/ipfs-unixfs-importer/src/layout/balanced.ts @@ -1,6 +1,6 @@ import batch from 'it-batch' -import type { InProgressImportResult } from '../index.js' import type { FileLayout } from './index.js' +import type { InProgressImportResult } from '../index.js' const DEFAULT_MAX_CHILDREN_PER_NODE = 174 @@ -19,7 +19,7 @@ export function balanced (options?: BalancedOptions): FileLayout { } if (roots.length > 1) { - return await balancedLayout(roots, reduce) + return balancedLayout(roots, reduce) } return roots[0] diff --git a/packages/ipfs-unixfs-importer/src/layout/flat.ts b/packages/ipfs-unixfs-importer/src/layout/flat.ts index f75b44f7..9d60a565 100644 --- a/packages/ipfs-unixfs-importer/src/layout/flat.ts +++ b/packages/ipfs-unixfs-importer/src/layout/flat.ts @@ -4,6 +4,6 @@ import type { InProgressImportResult } from '../index.js' export function flat (): FileLayout { return async function flatLayout (source, reduce): Promise { - return await reduce(await all(source)) + return reduce(await all(source)) } } diff --git a/packages/ipfs-unixfs-importer/src/layout/trickle.ts b/packages/ipfs-unixfs-importer/src/layout/trickle.ts index c0cc194a..490d35da 100644 --- a/packages/ipfs-unixfs-importer/src/layout/trickle.ts +++ b/packages/ipfs-unixfs-importer/src/layout/trickle.ts @@ -1,8 +1,8 @@ -import type { UnixFS } from 'ipfs-unixfs' import batch from 'it-batch' -import type { CID } from 'multiformats/cid' import type { InProgressImportResult } from '../index.js' import type { FileLayout, Reducer } from '../layout/index.js' +import type { UnixFS } from 'ipfs-unixfs' +import type { CID } from 'multiformats/cid' const DEFAULT_LAYER_REPEAT = 4 const DEFAULT_MAX_CHILDREN_PER_NODE = 174 @@ -59,7 +59,7 @@ export function trickle (options?: TrickleOptions): FileLayout { root.addChild(await subTree.reduce(reduce)) } - return await root.reduce(reduce) + return root.reduce(reduce) } } @@ -122,7 +122,7 @@ class SubTree { maxChildren: Math.floor(parent.children.length / this.layerRepeat) * this.layerRepeat } - // @ts-expect-error + // @ts-expect-error nextNode is different type parent.children.push(nextNode) this.currentDepth = nextNode.depth @@ -134,7 +134,7 @@ class SubTree { } async reduce (reduce: Reducer): Promise { - return await this._reduce(this.root, reduce) + return this._reduce(this.root, reduce) } async _reduce (node: TrickleDagNode, reduce: Reducer): Promise { @@ -143,14 +143,14 @@ class SubTree { if (node.children.length > 0) { children = await Promise.all( node.children - // @ts-expect-error + // @ts-expect-error data is not present on type .filter(child => child.data) - // @ts-expect-error - .map(async child => await this._reduce(child, reduce)) + // @ts-expect-error child is wrong type + .map(async child => this._reduce(child, reduce)) ) } - return await reduce((node.data ?? []).concat(children)) + return reduce((node.data ?? []).concat(children)) } _findParent (node: TrickleDagNode, depth: number): TrickleDagNode | undefined { @@ -182,6 +182,6 @@ class Root extends SubTree { } async reduce (reduce: Reducer): Promise { - return await reduce((this.root.data ?? []).concat(this.root.children)) + return reduce((this.root.data ?? []).concat(this.root.children)) } } diff --git a/packages/ipfs-unixfs-importer/src/tree-builder.ts b/packages/ipfs-unixfs-importer/src/tree-builder.ts index 05ee3906..1c2e457d 100644 --- a/packages/ipfs-unixfs-importer/src/tree-builder.ts +++ b/packages/ipfs-unixfs-importer/src/tree-builder.ts @@ -1,6 +1,6 @@ import { DirFlat } from './dir-flat.js' -import { flatToShard } from './flat-to-shard.js' import { Dir } from './dir.js' +import { flatToShard } from './flat-to-shard.js' import { toPathComponents } from './utils/to-path-components.js' import type { ImportResult, InProgressImportResult, TreeBuilder, WritableStorage } from './index.js' import type { PersistOptions } from './utils/persist.js' diff --git a/packages/ipfs-unixfs-importer/src/utils/persist.ts b/packages/ipfs-unixfs-importer/src/utils/persist.ts index 2bbe36e1..2911b043 100644 --- a/packages/ipfs-unixfs-importer/src/utils/persist.ts +++ b/packages/ipfs-unixfs-importer/src/utils/persist.ts @@ -1,9 +1,9 @@ -import { CID } from 'multiformats/cid' import * as dagPb from '@ipld/dag-pb' +import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' import type { WritableStorage } from '../index.js' -import type { BlockCodec } from 'multiformats/codecs/interface' import type { Version as CIDVersion } from 'multiformats/cid' +import type { BlockCodec } from 'multiformats/codecs/interface' import type { ProgressOptions } from 'progress-events' export interface PersistOptions extends ProgressOptions { diff --git a/packages/ipfs-unixfs-importer/test/builder-balanced.spec.ts b/packages/ipfs-unixfs-importer/test/builder-balanced.spec.ts index 850defcc..63fd4a13 100644 --- a/packages/ipfs-unixfs-importer/test/builder-balanced.spec.ts +++ b/packages/ipfs-unixfs-importer/test/builder-balanced.spec.ts @@ -1,14 +1,14 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { balanced } from '../src/layout/balanced.js' import { CID } from 'multiformats/cid' +import { balanced } from '../src/layout/balanced.js' import type { InProgressImportResult } from '../src/index.js' async function reduce (leaves: InProgressImportResult[]): Promise { if (leaves.length > 1) { return { - // @ts-expect-error + // @ts-expect-error children is not part of InProgressImportResult children: leaves } } else { @@ -62,7 +62,7 @@ describe('builder: balanced', () => { it('obeys max children per node', async () => { const source = [1, 2, 3, 4] - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await balanced(options)((async function * () { yield * source }()), reduce) @@ -79,7 +79,7 @@ describe('builder: balanced', () => { it('refolds 2 parent nodes', async () => { const source = [1, 2, 3, 4, 5, 6, 7] - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await balanced(options)((async function * () { yield * source }()), reduce) diff --git a/packages/ipfs-unixfs-importer/test/builder-flat.spec.ts b/packages/ipfs-unixfs-importer/test/builder-flat.spec.ts index 6a8c6a52..f79b47d1 100644 --- a/packages/ipfs-unixfs-importer/test/builder-flat.spec.ts +++ b/packages/ipfs-unixfs-importer/test/builder-flat.spec.ts @@ -14,7 +14,7 @@ function reduce (leaves: any[]): any { describe('builder: flat', () => { it('reduces one value into itself', async () => { const source = [1] - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await flat()(source, reduce) expect(result).to.be.equal(1) @@ -22,7 +22,7 @@ describe('builder: flat', () => { it('reduces 2 values into parent', async () => { const source = [1, 2] - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await flat()(source, reduce) expect(result).to.be.eql({ children: [1, 2] }) diff --git a/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.ts b/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.ts index dc5f0843..6dd046d4 100644 --- a/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.ts +++ b/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.ts @@ -29,14 +29,14 @@ const options = { describe('builder: trickle', () => { it('reduces one value into itself', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(asAsyncIterable([1]), reduce) expect(result).to.deep.equal(1) }) it('reduces 3 values into parent', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(3), reduce) expect(result).to.deep.equal({ @@ -49,7 +49,7 @@ describe('builder: trickle', () => { }) it('reduces 6 values correctly', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(6), reduce) expect(result).to.deep.equal({ @@ -69,7 +69,7 @@ describe('builder: trickle', () => { }) it('reduces 9 values correctly', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(9), reduce) expect(result).to.deep.equal({ @@ -96,7 +96,7 @@ describe('builder: trickle', () => { }) it('reduces 12 values correctly', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(12), reduce) expect(result).to.deep.equal({ @@ -130,7 +130,7 @@ describe('builder: trickle', () => { }) it('reduces 21 values correctly', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(21), reduce) expect(result).to.deep.equal({ @@ -185,7 +185,7 @@ describe('builder: trickle', () => { }) it('reduces 68 values correctly', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(68), reduce) expect(result).to.deep.equal( @@ -353,7 +353,7 @@ describe('builder: trickle', () => { }) it('reduces 93 values correctly', async () => { - // @ts-expect-error + // @ts-expect-error number is incorrect type const result = await trickle(options)(createValues(93), reduce) expect(result).to.deep.equal( diff --git a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.ts b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.ts index 7fb112bd..3237ce76 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.ts +++ b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.ts @@ -1,13 +1,13 @@ /* eslint-env mocha */ -import { importer } from '../src/index.js' import { expect } from 'aegir/chai' +import { MemoryBlockstore } from 'blockstore-core' +import { UnixFS } from 'ipfs-unixfs' +import * as Block from 'multiformats/block' import * as rawCodec from 'multiformats/codecs/raw' import { sha256 } from 'multiformats/hashes/sha2' -import * as Block from 'multiformats/block' -import { MemoryBlockstore } from 'blockstore-core' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { UnixFS } from 'ipfs-unixfs' +import { importer } from '../src/index.js' import type { CID } from 'multiformats' const iter = async function * (): AsyncGenerator { @@ -40,7 +40,7 @@ describe('custom chunker', function () { chunker: source => source, bufferImporter: async function * (file, block) { for await (const item of file.content) { - yield async () => await put(item) + yield async () => put(item) } } })) { diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.ts b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.ts index 5597a83d..1ed56294 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.ts +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.ts @@ -1,10 +1,10 @@ /* eslint-env mocha */ -import { fixedSize } from '../src/chunker/fixed-size.js' import { expect } from 'aegir/chai' import all from 'it-all' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { fixedSize } from '../src/chunker/fixed-size.js' import asAsyncIterable from './helpers/as-async-iterable.js' const rawFile = new Uint8Array(Math.pow(2, 20)) diff --git a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.ts b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.ts index 2fb11180..f081687e 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.ts +++ b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.ts @@ -1,12 +1,12 @@ /* eslint-env mocha */ -import { rabin } from '../src/chunker/rabin.js' import { expect } from 'aegir/chai' import all from 'it-all' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import asAsyncIterable from './helpers/as-async-iterable.js' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { isElectronRenderer } from 'wherearewe' +import { rabin } from '../src/chunker/rabin.js' +import asAsyncIterable from './helpers/as-async-iterable.js' const rawFile = new Uint8Array(Math.pow(2, 20)).fill(1) diff --git a/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.ts b/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.ts index 1be6b2c5..04637910 100644 --- a/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.ts +++ b/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.ts @@ -1,13 +1,13 @@ /* eslint-env mocha */ -import { importer, ImporterOptions } from '../src/index.js' import { expect } from 'aegir/chai' -import randomByteStream from './helpers/finite-pseudorandom-byte-stream.js' +import { MemoryBlockstore } from 'blockstore-core' import first from 'it-first' import last from 'it-last' -import { MemoryBlockstore } from 'blockstore-core' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { balanced, FileLayout, flat, trickle } from '../src/layout/index.js' +import { importer, type ImporterOptions } from '../src/index.js' +import { balanced, type FileLayout, flat, trickle } from '../src/layout/index.js' +import randomByteStream from './helpers/finite-pseudorandom-byte-stream.js' const strategies: Record<'flat' | 'trickle' | 'balanced', FileLayout> = { flat: flat(), diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.ts b/packages/ipfs-unixfs/test/unixfs-format.spec.ts index 7f483bcf..a15d0f2e 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.ts +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.ts @@ -3,8 +3,7 @@ import { expect } from 'aegir/chai' import loadFixture from 'aegir/fixtures' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' - -import { Mtime, UnixFS } from '../src/index.js' +import { type Mtime, UnixFS } from '../src/index.js' import * as Pb from '../src/unixfs.js' const PBData = Pb.Data From 1cc648333456305bf474edea40a72eae228fd669 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 11 May 2023 17:02:09 +0100 Subject: [PATCH 3/3] chore: fix up deps --- packages/ipfs-unixfs-importer/package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 4c8048c1..9bd2a3ce 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -179,8 +179,6 @@ "devDependencies": { "aegir": "^39.0.6", "blockstore-core": "^4.0.1", - "it-buffer-stream": "^3.0.0", - "it-drain": "^3.0.2", "it-last": "^3.0.2", "wherearewe": "^2.0.1" },