parseCrdtChangeset function

CrdtChangeset parseCrdtChangeset(
  1. Map<String, dynamic> message
)

Utility function to simplify parsing untyped changesets. It performs all necessary casts to satisfy Dart's type system, and parses Hlc timestamps. Useful when receiving datasets over the wire.

Implementation

CrdtChangeset parseCrdtChangeset(Map<String, dynamic> message) =>
    // Cast payload to CrdtChangeset
    message.map((table, records) => MapEntry(
        table,
        (records as List)
            .cast<Map<String, dynamic>>()
            // Parse Hlc
            .map((e) => e.map((key, value) =>
                MapEntry(key, key == 'hlc' ? Hlc.parse(value) : value)))
            .toList()));