changedFieldNames function
What changedFields() reports for one proposed update (05 ยง2.2), as the
platform's changedFieldNames and the emulator's: the named top-level
fields whose stored value differs from the candidate's, by deep JSON
equality, absent and null alike. Pass both images as the rule reads them
(record and newRecord). A writeOnly or serverOnly field counts as
changed whenever the patch names it (patched), whatever its value. System
fields are never named.
Implementation
List<String> changedFieldNames(
Iterable<String> fieldNames,
Map<String, String> markers,
Map<String, Object?> stored,
Map<String, Object?> candidate,
Iterable<String> patched,
) {
final named = patched.toSet();
return [
for (final name in fieldNames)
if (markers[name] == 'writeOnly' || markers[name] == 'serverOnly'
? named.contains(name)
: !_sameValue(stored[name], candidate[name]))
name,
];
}