Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(strings)!: remove codec from AddOptions #668

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 0 additions & 9 deletions packages/strings/test/add.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 @@ -30,12 +29,4 @@ describe('put', () => {

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