Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b4b6351

Browse files
committedOct 28, 2024
refactor(strings)!: remove codec from AddOptions
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.
1 parent 194fa65 commit b4b6351

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed
 

‎packages/strings/src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export interface StringsComponents {
4040

4141
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
4242
hasher: MultihashHasher
43-
codec: BlockCodec<any, unknown>
4443
}
4544

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

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

‎packages/strings/test/get.spec.ts

-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { expect } from 'aegir/chai'
44
import { MemoryBlockstore } from 'blockstore-core'
5-
import * as json from 'multiformats/codecs/json'
65
import { identity } from 'multiformats/hashes/identity'
76
import { strings, type Strings } from '../src/index.js'
87
import type { Blockstore } from 'interface-blockstore'
@@ -34,13 +33,4 @@ describe('get', () => {
3433

3534
await expect(str.get(cid)).to.eventually.equal(input)
3635
})
37-
38-
it('gets a string with a non-default block codec', async () => {
39-
const input = 'hello world'
40-
const cid = await str.add(input, {
41-
codec: json
42-
})
43-
44-
await expect(str.get(cid)).to.eventually.equal(input)
45-
})
4636
})

0 commit comments

Comments
 (0)
Please sign in to comment.