From cb0249ad1710bc12cc67011a25086625811a107c Mon Sep 17 00:00:00 2001 From: Yusuf Taiwo Hassan Date: Thu, 30 May 2024 14:36:54 +0100 Subject: [PATCH] Feature: Add Extra Fields to Store Messages (#173) * feat: included extra fields in Store messages * tests: updated file store test * doc: clean up docs and include extraFields and Lint --------- Authored-by: @teezzan --- packages/message/__tests__/store/publish.test.ts | 7 +++++++ packages/message/src/store/impl.ts | 2 ++ packages/message/src/store/types.ts | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/message/__tests__/store/publish.test.ts b/packages/message/__tests__/store/publish.test.ts index 44558e54..10fcf9ad 100644 --- a/packages/message/__tests__/store/publish.test.ts +++ b/packages/message/__tests__/store/publish.test.ts @@ -13,10 +13,16 @@ describe('Store message publish', () => { const { account } = ethereum.newAccount() const fileContent = readFileSync('./packages/message/__tests__/store/testFile.txt') + const extraFields: Record = { + key1: 'value1', + key2: 123, + } + const hash = await store.send({ channel: 'TEST', account: account, fileObject: fileContent, + extraFields, }) const response = await store.download(hash.content.item_hash) @@ -25,6 +31,7 @@ describe('Store message publish', () => { const expected = 'y' expect(got).toBe(expected) + expect(hash.content.extra_fields).toEqual(extraFields) }) it('should pin a file and retrieve it correctly', async () => { diff --git a/packages/message/src/store/impl.ts b/packages/message/src/store/impl.ts index a4704755..ac97905a 100644 --- a/packages/message/src/store/impl.ts +++ b/packages/message/src/store/impl.ts @@ -43,6 +43,7 @@ export class StoreMessageClient { channel, fileHash, fileObject, + extraFields, sync = false, }: RequireOnlyOne): Promise { if (!fileObject && !fileHash) throw new Error('You need to specify a File to upload or a Hash to pin.') @@ -65,6 +66,7 @@ export class StoreMessageClient { item_type: storageEngine, item_hash: hash, time: timestamp, + extra_fields: extraFields, } const builtMessage = buildStoreMessage({ diff --git a/packages/message/src/store/types.ts b/packages/message/src/store/types.ts index df35ecea..bb9cb18e 100644 --- a/packages/message/src/store/types.ts +++ b/packages/message/src/store/types.ts @@ -7,6 +7,7 @@ export type StoreContent = BaseContent & { size?: number content_type?: string ref?: string + extra_fields?: Record } // -------- PIN ---------- @@ -44,7 +45,7 @@ export type StorePinConfiguration = { * * inlineRequested: If set to False, the Store message will be store on the same storageEngine you picked. * - * apiServer: The API server endpoint used to carry the request to the Aleph's network. + * extraFields: Extra fields to add to the Store message. * * sync: If true, the function will wait for the message to be confirmed by the API server. */