Skip to content

Commit

Permalink
Feature: Add Extra Fields to Store Messages (#173)
Browse files Browse the repository at this point in the history
* feat: included extra fields in Store messages

* tests: updated file store test

* doc: clean up docs and include extraFields and Lint

---------

Authored-by: @teezzan
  • Loading branch information
teezzan authored May 30, 2024
1 parent 0500f93 commit cb0249a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/message/__tests__/store/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ describe('Store message publish', () => {
const { account } = ethereum.newAccount()
const fileContent = readFileSync('./packages/message/__tests__/store/testFile.txt')

const extraFields: Record<string, unknown> = {
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)
Expand All @@ -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 () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/message/src/store/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class StoreMessageClient {
channel,
fileHash,
fileObject,
extraFields,
sync = false,
}: RequireOnlyOne<StorePublishConfiguration, 'fileObject' | 'fileHash'>): Promise<StoreMessage> {
if (!fileObject && !fileHash) throw new Error('You need to specify a File to upload or a Hash to pin.')
Expand All @@ -65,6 +66,7 @@ export class StoreMessageClient {
item_type: storageEngine,
item_hash: hash,
time: timestamp,
extra_fields: extraFields,
}

const builtMessage = buildStoreMessage({
Expand Down
3 changes: 2 additions & 1 deletion packages/message/src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type StoreContent = BaseContent & {
size?: number
content_type?: string
ref?: string
extra_fields?: Record<string, unknown>
}

// -------- PIN ----------
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit cb0249a

Please sign in to comment.