TinyBase logoTinyBase

Changes

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

[changedTables: {[tableId: Id]: {[rowId: Id]: {[cellId: Id]: CellOrUndefined} | undefined} | undefined}, changedValues: {[valueId: Id]: ValueOrUndefined}, isChanges: 1]

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.

A third, required, item in the array is the digit 1, so that instances of Content and Changes types can be disambiguated.

Example

The following is a valid Changes 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
  1,                    // indicates that this is a Changes array
]

Since

v4.0.0