From b4b6351b92f037b1b6b2db157482ba600efb4bec Mon Sep 17 00:00:00 2001 From: tabcat Date: Mon, 28 Oct 2024 19:22:52 +0700 Subject: [PATCH] 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. --- packages/strings/src/index.ts | 4 +--- packages/strings/test/get.spec.ts | 10 ---------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/strings/src/index.ts b/packages/strings/src/index.ts index fe13d27ce..1342f159e 100644 --- a/packages/strings/src/index.ts +++ b/packages/strings/src/index.ts @@ -40,7 +40,6 @@ export interface StringsComponents { export interface AddOptions extends AbortOptions, ProgressOptions { hasher: MultihashHasher - codec: BlockCodec } export interface GetOptions extends AbortOptions, ProgressOptions { @@ -105,8 +104,7 @@ class DefaultStrings implements Strings { async add (string: string, options: Partial = {}): Promise { 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) diff --git a/packages/strings/test/get.spec.ts b/packages/strings/test/get.spec.ts index 5b69301d0..d7e4d2af9 100644 --- a/packages/strings/test/get.spec.ts +++ b/packages/strings/test/get.spec.ts @@ -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' @@ -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) - }) })