TinyBase logoTinyBase

TransactionChanges

The TransactionChanges type describes the net meaningful changes that were made to a Store during a transaction.

[{[tableId: Id]: {[rowId: Id]: {[cellId: Id]: Cell | null} | null} | null}, {[valueId: Id]: Value | null}]

This contains mostly equivalent information to a TransactionLog, but in a form that can be more efficiently parsed and serialized (for example in the case of synchronization between systems).

It is an array of two objects, representing tabular and keyed value changes. If the first item is an empty object, it means no tabular changes were made. If the second item is an empty object, it means no keyed value changes were made.

If not empty, the first object has an entry for each Table in a Store that has had a change within it. If the entry is null, it means that whole Table was deleted. Otherwise, the entry will be an object with an entry for each Row in that Table that had a change within it. In turn, if that entry is null, it means the Row was deleted. Otherwise, the entry will be an object with an entry for each Cell in that Row that had a change within it. If the entry is null, the Cell was deleted, otherwise it will contain the new value the Cell was changed to during the transaction.

If not empty, the second object has an entry for each Value in a Store that has had a change. If the entry is null, the Value was deleted, otherwise it will contain the new Value it was changed to during the transaction.

Example

The following is a valid TransactionChanges array that conveys the following:

[
  {                     // changes to tabular data in the Store
    "pets": {             // this Table was changed
      "fido": null,         // this Row was deleted
      "felix": {            // this Row was changed
        "sold": true,         // this Cell was changed
        "price": null,        // this Cell was deleted
      },
    },
    "pendingSales": null, // this Table was deleted
  },
  {},                   // no changes to keyed value data in the Store
]

Since

v4.0.0