diff --git a/src/bee.ts b/src/bee.ts index 067d7ac7..3a3f9996 100644 --- a/src/bee.ts +++ b/src/bee.ts @@ -69,6 +69,7 @@ import { AllTagsOptions, CHUNK_SIZE, Collection, + FeedManifestResult, Ky, Readable, ReferenceCidOrEns, @@ -892,7 +893,6 @@ export class Bee { * * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds) * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post) - * TODO: Once breaking add support for Feed CID */ async createFeedManifest( postageBatchId: string | BatchId, @@ -900,7 +900,7 @@ export class Bee { topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: RequestOptions, - ): Promise { + ): Promise { assertRequestOptions(options) assertFeedType(type) assertBatchId(postageBatchId) @@ -908,7 +908,11 @@ export class Bee { const canonicalTopic = makeTopic(topic) const canonicalOwner = makeHexEthAddress(owner) - return createFeedManifest(this.getKy(options), canonicalOwner, canonicalTopic, postageBatchId, { type }) + const reference = await createFeedManifest(this.getKy(options), canonicalOwner, canonicalTopic, postageBatchId, { + type, + }) + + return addCidConversionFunction({ reference }, ReferenceType.FEED) } /** diff --git a/src/types/index.ts b/src/types/index.ts index d8b3b0d8..047bbc8d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -404,6 +404,23 @@ export const TOPIC_HEX_LENGTH = 64 */ export type Topic = HexString +/** + * Result of upload calls. + */ +export interface FeedManifestResult { + /** + * Reference of the uploaded data + */ + reference: Reference + + /** + * Function that converts the reference into Swarm Feed CID. + * + * @see https://github.com/ethersphere/swarm-cid-js + */ + cid: () => string +} + /** * FeedReader is an interface for downloading feed updates */ diff --git a/src/utils/type.ts b/src/utils/type.ts index 9d8eac6a..0d0ca588 100644 --- a/src/utils/type.ts +++ b/src/utils/type.ts @@ -25,8 +25,6 @@ import { PostageBatchOptions, CashoutOptions, ReferenceOrEns, - UploadResult, - UploadResultWithCid, } from '../types' import { BeeArgumentError, BeeError } from './error' import { isFile } from './file' @@ -199,7 +197,10 @@ export function makeReferenceOrEns(value: unknown, expectedCidType: ReferenceTyp * @param result * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType */ -export function addCidConversionFunction(result: UploadResult, cidType: ReferenceType): UploadResultWithCid { +export function addCidConversionFunction( + result: T, + cidType: ReferenceType, +): T & { cid: () => string } { return { ...result, cid() { diff --git a/test/integration/bee-class.spec.ts b/test/integration/bee-class.spec.ts index a6c15d8e..900d6d2f 100644 --- a/test/integration/bee-class.spec.ts +++ b/test/integration/bee-class.spec.ts @@ -578,12 +578,17 @@ describe('Bee class', () => { const feed = bee.makeFeedWriter('sequence', topic, signer) await feed.upload(getPostageBatch(), cacResult.reference) - const manifestReference = await bee.createFeedManifest(getPostageBatch(), 'sequence', topic, owner) + const manifestResult = await bee.createFeedManifest(getPostageBatch(), 'sequence', topic, owner) - expect(typeof manifestReference).toBe('string') + expect(manifestResult).toEqual( + expect.objectContaining({ + reference: expect.any(String), + cid: expect.any(Function), + }), + ) // this calls /bzz endpoint that should resolve the manifest and the feed returning the latest feed's content - const file = await bee.downloadFile(manifestReference, 'index.html') + const file = await bee.downloadFile(manifestResult.reference, 'index.html') expect(new TextDecoder().decode(file.data)).toEqual('some data') }, FEED_TIMEOUT,