diff --git a/package.json b/package.json index d0eb9683a..9a5f02064 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "release": "npm run docs:no-publish && aegir run release && npm run docs" }, "devDependencies": { - "aegir": "^38.1.0" + "aegir": "^39.0.3" }, "type": "module", "workspaces": [ diff --git a/packages/interop/package.json b/packages/interop/package.json index 67dbc219b..565158d58 100644 --- a/packages/interop/package.json +++ b/packages/interop/package.json @@ -58,19 +58,17 @@ "@helia/strings": "~0.0.0", "@libp2p/tcp": "^6.1.2", "@libp2p/websockets": "^5.0.3", - "aegir": "^38.1.0", + "aegir": "^39.0.3", "blockstore-core": "^4.0.1", "datastore-core": "^9.0.3", "go-ipfs": "^0.19.0", "helia": "^1.0.0", "ipfs-core-types": "^0.14.0", - "ipfs-unixfs-importer": "^15.1.0", "ipfsd-ctl": "^13.0.0", - "it-to-buffer": "^4.0.1", "kubo-rpc-client": "^3.0.0", "libp2p": "^0.43.2", "merge-options": "^3.0.4", - "multiformats": "^11.0.1", + "uint8arrays": "^4.0.3", "wherearewe": "^2.0.1" }, "browser": { diff --git a/packages/interop/test/fixtures/create-helia.browser.ts b/packages/interop/test/fixtures/create-helia.browser.ts index d28c6efa4..6baa5299a 100644 --- a/packages/interop/test/fixtures/create-helia.browser.ts +++ b/packages/interop/test/fixtures/create-helia.browser.ts @@ -1,11 +1,11 @@ -import { createHelia } from 'helia' -import { createLibp2p } from 'libp2p' -import { webSockets } from '@libp2p/websockets' -import { all } from '@libp2p/websockets/filters' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' +import { webSockets } from '@libp2p/websockets' +import { all } from '@libp2p/websockets/filters' import { MemoryBlockstore } from 'blockstore-core' import { MemoryDatastore } from 'datastore-core' +import { createHelia } from 'helia' +import { createLibp2p } from 'libp2p' import type { Helia } from '@helia/interface' export async function createHeliaNode (): Promise { diff --git a/packages/interop/test/fixtures/create-helia.ts b/packages/interop/test/fixtures/create-helia.ts index 7a7201b09..c92d309b7 100644 --- a/packages/interop/test/fixtures/create-helia.ts +++ b/packages/interop/test/fixtures/create-helia.ts @@ -1,10 +1,10 @@ -import { createHelia } from 'helia' -import { createLibp2p, Libp2pOptions } from 'libp2p' -import { tcp } from '@libp2p/tcp' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' +import { tcp } from '@libp2p/tcp' import { MemoryBlockstore } from 'blockstore-core' import { MemoryDatastore } from 'datastore-core' +import { createHelia } from 'helia' +import { createLibp2p, type Libp2pOptions } from 'libp2p' import type { Helia } from '@helia/interface' export async function createHeliaNode (config: Libp2pOptions = {}): Promise { diff --git a/packages/interop/test/fixtures/create-kubo.ts b/packages/interop/test/fixtures/create-kubo.ts index 7fd487297..52ed76e19 100644 --- a/packages/interop/test/fixtures/create-kubo.ts +++ b/packages/interop/test/fixtures/create-kubo.ts @@ -1,10 +1,10 @@ // @ts-expect-error no types import * as goIpfs from 'go-ipfs' -import { Controller, ControllerOptions, createController } from 'ipfsd-ctl' +import { type Controller, type ControllerOptions, createController } from 'ipfsd-ctl' import * as kuboRpcClient from 'kubo-rpc-client' -import { isElectronMain, isNode } from 'wherearewe' import mergeOptions from 'merge-options' +import { isElectronMain, isNode } from 'wherearewe' export async function createKuboNode (options: ControllerOptions<'go'> = {}): Promise { const opts = mergeOptions({ @@ -24,5 +24,5 @@ export async function createKuboNode (options: ControllerOptions<'go'> = {}): Pr } }, options) - return await createController(opts) + return createController(opts) } diff --git a/packages/interop/test/strings.spec.ts b/packages/interop/test/strings.spec.ts index a243a58ad..7262404ba 100644 --- a/packages/interop/test/strings.spec.ts +++ b/packages/interop/test/strings.spec.ts @@ -1,14 +1,14 @@ /* eslint-env mocha */ +import { strings, type Strings, type AddOptions } from '@helia/strings' import { expect } from 'aegir/chai' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { createHeliaNode } from './fixtures/create-helia.js' import { createKuboNode } from './fixtures/create-kubo.js' import type { Helia } from '@helia/interface' -import type { Controller } from 'ipfsd-ctl' -import { strings, Strings, AddOptions } from '@helia/strings' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import type { PutOptions as KuboAddOptions } from 'ipfs-core-types/src/block/index.js' +import type { Controller } from 'ipfsd-ctl' describe('strings interop', () => { let helia: Helia diff --git a/packages/strings/package.json b/packages/strings/package.json index e0d35ae30..8b9731157 100644 --- a/packages/strings/package.json +++ b/packages/strings/package.json @@ -139,13 +139,15 @@ "release": "aegir release" }, "dependencies": { + "@helia/interface": "^1.0.0", + "@libp2p/interfaces": "^3.3.1", "interface-blockstore": "^5.0.0", "multiformats": "^11.0.1", "progress-events": "^1.0.0", "uint8arrays": "^4.0.3" }, "devDependencies": { - "aegir": "^38.1.0", + "aegir": "^39.0.3", "blockstore-core": "^4.0.1" }, "typedoc": { diff --git a/packages/strings/src/index.ts b/packages/strings/src/index.ts index 4ee415e0f..9006dd6d2 100644 --- a/packages/strings/src/index.ts +++ b/packages/strings/src/index.ts @@ -22,15 +22,15 @@ */ import { CID } from 'multiformats/cid' -import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' -import type { AbortOptions } from '@libp2p/interfaces' -import type { ProgressOptions } from 'progress-events' -import { sha256 } from 'multiformats/hashes/sha2' import * as raw from 'multiformats/codecs/raw' +import { sha256 } from 'multiformats/hashes/sha2' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { AbortOptions } from '@libp2p/interfaces' import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' +import type { ProgressOptions } from 'progress-events' export interface StringsComponents { blockstore: Blocks @@ -46,8 +46,8 @@ export interface GetOptions extends AbortOptions, ProgressOptions { let blockstore: Blockstore @@ -20,4 +22,20 @@ describe('put', () => { expect(`${cid}`).to.equal('bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e') }) + + it('adds a string with a non-default hashing algorithm', async () => { + const cid = await str.add('hello world', { + hasher: identity + }) + + expect(`${cid}`).to.equal('bafkqac3imvwgy3zao5xxe3de') + }) + + it('adds a string with a non-default block codec', async () => { + const cid = await str.add('hello world', { + codec: json + }) + + expect(`${cid}`).to.equal('bagaaieraxfgspomtju7arjjokll5u7nl7lcij37dpjjyb3uqrd32zyxpzxuq') + }) }) diff --git a/packages/strings/test/get.spec.ts b/packages/strings/test/get.spec.ts index 7fbfca2fd..5b69301d0 100644 --- a/packages/strings/test/get.spec.ts +++ b/packages/strings/test/get.spec.ts @@ -1,9 +1,11 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import type { Blockstore } from 'interface-blockstore' -import { strings, Strings } from '../src/index.js' import { MemoryBlockstore } from 'blockstore-core' +import * as json from 'multiformats/codecs/json' +import { identity } from 'multiformats/hashes/identity' +import { strings, type Strings } from '../src/index.js' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' describe('get', () => { @@ -18,9 +20,27 @@ describe('get', () => { cid = await str.add('hello world') }) - it('adds a string', async () => { + it('gets a string', async () => { const string = await str.get(cid) expect(`${string}`).to.equal('hello world') }) + + it('gets a string with a non-default hashing algorithm', async () => { + const input = 'hello world' + const cid = await str.add(input, { + hasher: identity + }) + + await expect(str.get(cid)).to.eventually.equal(input) + }) + + it('gets a string with a non-default block codec', async () => { + const input = 'hello world' + const cid = await str.add(input, { + codec: json + }) + + await expect(str.get(cid)).to.eventually.equal(input) + }) })