Update

Use the create endpoint to update a specific key content from an existing Aggregate.

Since creating an Aggregate message mutates the value of the specific key, if the key exists, the value object will be updated (mutated) with the object you are saving.

Usage

Post an aggregate

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';

(async () => {
    await publishAggregate({
        account: account,
        key: 'test_key',
        content: {'a': 1, 'my_array': ["ETH", "AVAX"] },
        channel: "TEST",
  })
})();

The message result is here

"content": { "a": 1, "my_array": [ "ETH", "AVAX" ] }

Update the aggregate

With the same account, send another aggregate message that refers to the same key:

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';

(async () => {
    await publishAggregate({
        account: account,
        key: 'test_key',
        content: {'a': 1895},
        channel: "TEST",
  })
})();

The message result is here

"content": { "a": 1895 }

Checking the result

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Get as getAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';

(async () => {
    const fetched = await getAggregate({
		address: account.address,
		APIServer: 'https://api2.aleph.im'
	})
})();

When fetching the result you can see that the a key was correctly updated

{ test_key: { a: 1895, my_array: [ 'ETH', 'AVAX' ] } }

Last updated