Skip to content

Commit

Permalink
refactor(strings)!: remove codec from AddOptions
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Removes `codec` from AddOptions for `@helia/strings.add`. Anyone relying
on this option currently would have to encode, hash, and import the data
using helia's blockstore (unless implemented by another helia importer
e.g. `@helia/json` or `@helia/dag-cbor`) in order to receive the same
CID as before.

This changes @helia/strings to act more like the other helia importers.
  • Loading branch information
tabcat committed Oct 28, 2024
1 parent 194fa65 commit b4b6351
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
4 changes: 1 addition & 3 deletions packages/strings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface StringsComponents {

export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
hasher: MultihashHasher
codec: BlockCodec<any, unknown>
}

export interface GetOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
Expand Down Expand Up @@ -105,8 +104,7 @@ class DefaultStrings implements Strings {
async add (string: string, options: Partial<AddOptions> = {}): Promise<CID> {
const buf = uint8ArrayFromString(string)
const hash = await (options.hasher ?? sha256).digest(buf)
const codec = options.codec ?? raw
const cid = CID.createV1(codec.code, hash)
const cid = CID.createV1(raw.code, hash)

await this.components.blockstore.put(cid, buf, options)

Expand Down
10 changes: 0 additions & 10 deletions packages/strings/test/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { expect } from 'aegir/chai'
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'
Expand Down Expand Up @@ -34,13 +33,4 @@ describe('get', () => {

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)
})
})

0 comments on commit b4b6351

Please sign in to comment.