Skip to content

Commit cb0249a

Browse files
authored
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
1 parent 0500f93 commit cb0249a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/message/__tests__/store/publish.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ describe('Store message publish', () => {
1313
const { account } = ethereum.newAccount()
1414
const fileContent = readFileSync('./packages/message/__tests__/store/testFile.txt')
1515

16+
const extraFields: Record<string, unknown> = {
17+
key1: 'value1',
18+
key2: 123,
19+
}
20+
1621
const hash = await store.send({
1722
channel: 'TEST',
1823
account: account,
1924
fileObject: fileContent,
25+
extraFields,
2026
})
2127

2228
const response = await store.download(hash.content.item_hash)
@@ -25,6 +31,7 @@ describe('Store message publish', () => {
2531
const expected = 'y'
2632

2733
expect(got).toBe(expected)
34+
expect(hash.content.extra_fields).toEqual(extraFields)
2835
})
2936

3037
it('should pin a file and retrieve it correctly', async () => {

packages/message/src/store/impl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class StoreMessageClient {
4343
channel,
4444
fileHash,
4545
fileObject,
46+
extraFields,
4647
sync = false,
4748
}: RequireOnlyOne<StorePublishConfiguration, 'fileObject' | 'fileHash'>): Promise<StoreMessage> {
4849
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 {
6566
item_type: storageEngine,
6667
item_hash: hash,
6768
time: timestamp,
69+
extra_fields: extraFields,
6870
}
6971

7072
const builtMessage = buildStoreMessage({

packages/message/src/store/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type StoreContent = BaseContent & {
77
size?: number
88
content_type?: string
99
ref?: string
10+
extra_fields?: Record<string, unknown>
1011
}
1112

1213
// -------- PIN ----------
@@ -44,7 +45,7 @@ export type StorePinConfiguration = {
4445
*
4546
* inlineRequested: If set to False, the Store message will be store on the same storageEngine you picked.
4647
*
47-
* apiServer: The API server endpoint used to carry the request to the Aleph's network.
48+
* extraFields: Extra fields to add to the Store message.
4849
*
4950
* sync: If true, the function will wait for the message to be confirmed by the API server.
5051
*/

0 commit comments

Comments
 (0)