Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add Extra Fields to Store Messages #173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading