Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Changes before Tatum release are not documented in this file.
#### Changed

- **BREAKING CHANGE:** Field `StreamMetadata#partitions` is nullable (https://github.com/streamr-dev/network/pull/2825)
- **BREAKING CHANGE:** Method `Stream#update()` overwrites metadata instead of merging it (https://github.com/streamr-dev/network/pull/2826)
- Network-level changes
- Avoid routing through proxy connections (https://github.com/streamr-dev/network/pull/2801)
- Internal record `StreamPartitionInfo` format changed (https://github.com/streamr-dev/network/pull/2738, https://github.com/streamr-dev/network/pull/2790)
Expand Down
13 changes: 5 additions & 8 deletions packages/sdk/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,15 @@ export class Stream {
}

/**
* Updates the metadata of the stream by merging with the existing metadata.
* Updates the metadata of the stream.
*/
async update(metadata: Partial<StreamMetadata>): Promise<void> {
Comment thread
teogeb marked this conversation as resolved.
// TODO maybe should use deep merge, i.e. merge() from @streamr/utils as that corresponds
// the implicit intention of the method description. But we'll harmonize this method soon in NET-1364,
// so we don't change the behavior now.
const merged = flatMerge(this.getMetadata(), metadata)
try {
await this._streamRegistry.updateStream(this.id, merged)
await this._streamRegistry.updateStream(this.id, metadata)
} finally {
this._streamRegistry.clearStreamCache(this.id)
}
this.metadata = merged
this.metadata = metadata
}

/**
Expand Down Expand Up @@ -234,11 +230,12 @@ export class Stream {
}).filter(Boolean) as Field[] // see https://github.com/microsoft/TypeScript/issues/30621

// Save field config back to the stream
await this.update({
const merged = flatMerge(this.getMetadata(), {
config: {
fields
}
})
await this.update(merged)
}

/**
Expand Down
12 changes: 10 additions & 2 deletions packages/sdk/test/end-to-end/StreamRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ describe('StreamRegistry', () => {

describe('update', () => {
it('happy path', async () => {
const description = `description-${Date.now()}`
await createdStream.update({
description: `description-${Date.now()}`
description
})
await until(async () => {
try {
Expand All @@ -263,7 +264,14 @@ describe('StreamRegistry', () => {
}, 100000, 1000)
// check that other fields not overwritten
const updatedStream = await client.getStream(createdStream.id)
expect(updatedStream.getMetadata().partitions).toBe(PARTITION_COUNT)
expect(updatedStream.getMetadata()).toEqual({
description,
// these are injected in the Stream constructor (maybe we'll change this functionality in the future)
partitions: 1,
config: {
fields: []
}
})
}, TIMEOUT)
})

Expand Down