Skip to content

Commit

Permalink
feat(sdk)!: Rename StreamrClient#updateStream() and `Stream#update(…
Browse files Browse the repository at this point in the history
…)` (#2862)

**This is a breaking change as this changes the API**

Renamed to `setStreamMetadata()` and `setMetadata()`. The new names
describe the functionality clearly: the methods updates only the
metadata, and any existing value is overwritten by the new value.
  • Loading branch information
teogeb authored Nov 11, 2024
1 parent af2bcb8 commit c734928
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ Changes before Tatum release are not documented in this file.
- **BREAKING CHANGE:** Type `StreamMetadata` is `Record<string, unknown>` (https://github.com/streamr-dev/network/pull/2825, https://github.com/streamr-dev/network/pull/2845)
- some new accessors available, see above
- no default values are injected (https://github.com/streamr-dev/network/pull/2851)
- **BREAKING CHANGE:** Method `Stream#update()` overwrites metadata instead of merging it (https://github.com/streamr-dev/network/pull/2826)
- **BREAKING CHANGE:** Method `Stream#addToStorageNode()` doesn't wait for acknowledgment by default (https://github.com/streamr-dev/network/pull/2810)
- **BREAKING CHANGE:** Parameters and return type of method `StreamrClient#updateStream()` (https://github.com/streamr-dev/network/pull/2859, https://github.com/streamr-dev/network/pull/2855)
- **BREAKING CHANGE:** Replace methods `StreamrClient#updateStream()` and `Stream#update()`: (https://github.com/streamr-dev/network/pull/2826, https://github.com/streamr-dev/network/pull/2855, https://github.com/streamr-dev/network/pull/2859, https://github.com/streamr-dev/network/pull/2862)
- use `StreamrClient#setStreamMetadata()` and `Stream#setMetadata()` instead
- both methods overwrite metadata instead of merging it
- Upgrade `StreamRegistry` from v4 to v5 (https://github.com/streamr-dev/network/pull/2780)
- Network-level changes:
- avoid routing through proxy connections (https://github.com/streamr-dev/network/pull/2801)
Expand Down
14 changes: 7 additions & 7 deletions packages/sdk/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export class Stream {
/**
* Updates the metadata of the stream.
*/
async update(metadata: StreamMetadata): Promise<void> {
await this.client.updateStream(this.id, metadata)
async setMetadata(metadata: StreamMetadata): Promise<void> {
await this.client.setStreamMetadata(this.id, metadata)
this.metadata = metadata
}

Expand Down Expand Up @@ -159,8 +159,8 @@ export class Stream {
/**
* See {@link StreamrClient.removeStreamFromStorageNode | StreamrClient.removeStreamFromStorageNode}.
*/
async removeFromStorageNode(storageNodeAddress: HexString): Promise<void> {
return this.client.removeStreamFromStorageNode(this.id, toEthereumAddress(storageNodeAddress))
async removeFromStorageNode(nodeAddress: HexString): Promise<void> {
return this.client.removeStreamFromStorageNode(this.id, toEthereumAddress(nodeAddress))
}

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ export class Stream {
fields
}
})
await this.update(merged)
await this.setMetadata(merged)
}

/**
Expand All @@ -231,7 +231,7 @@ export class Stream {
}

async setDescription(description: string): Promise<void> {
await this.update({
await this.setMetadata({
...this.getMetadata(),
description
})
Expand All @@ -253,7 +253,7 @@ export class Stream {
* Sets the value of `storageDays` field
*/
async setStorageDayCount(count: number): Promise<void> {
await this.update({
await this.setMetadata({
...this.getMetadata(),
storageDays: count
})
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/StreamrClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ export class StreamrClient {
/**
* Updates the metadata of a stream.
*/
async updateStream(streamIdOrPath: string, metadata: StreamMetadata): Promise<void> {
async setStreamMetadata(streamIdOrPath: string, metadata: StreamMetadata): Promise<void> {
const streamId = await this.streamIdBuilder.toStreamID(streamIdOrPath)
await this.streamRegistry.updateStreamMetadata(streamId, metadata)
await this.streamRegistry.setStreamMetadata(streamId, metadata)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/contracts/StreamRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class StreamRegistry {
}
}

async updateStreamMetadata(streamId: StreamID, metadata: StreamMetadata): Promise<void> {
async setStreamMetadata(streamId: StreamID, metadata: StreamMetadata): Promise<void> {
await this.connectToContract()
const ethersOverrides = await getEthersOverrides(this.rpcProviderSource, this.config)
await waitForTx(this.streamRegistryContract!.updateStreamMetadata(
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/test/end-to-end/StreamRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ describe('StreamRegistry', () => {
}, TIMEOUT)
})

describe('update', () => {
describe('setMetadata', () => {
it('happy path', async () => {
const description = `description-${Date.now()}`
await createdStream.update({
await createdStream.setMetadata({
description
})
await until(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/test-utils/fake/FakeStreamRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class FakeStreamRegistry implements Methods<StreamRegistry> {
}
}

async updateStreamMetadata(streamId: StreamID, metadata: StreamMetadata): Promise<void> {
async setStreamMetadata(streamId: StreamID, metadata: StreamMetadata): Promise<void> {
const registryItem = this.chain.getStream(streamId)
if (registryItem === undefined) {
throw new Error('Stream not found')
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/test/unit/Stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ describe('Stream', () => {
})
})

describe('update', () => {
describe('setMetadata', () => {
it('fields not updated if transaction fails', async () => {
const client: Partial<StreamrClient> = {
updateStream: jest.fn().mockRejectedValue(new Error('mock-error')),
setStreamMetadata: jest.fn().mockRejectedValue(new Error('mock-error')),
}

const stream = new Stream(toStreamID('mock-id'), {
description: 'original-description'
}, client as any)

await expect(() => {
return stream.update({
return stream.setMetadata({
description: 'updated-description'
})
}).rejects.toThrow('mock-error')
Expand Down

0 comments on commit c734928

Please sign in to comment.