PatchbaySnapshotSelection.resolve constructor

PatchbaySnapshotSelection.resolve(
  1. Map<String, Object?> snapshot,
  2. String path
)

Resolves path against snapshot, segment by segment.

The value is returned verbatim, including whole subtrees. It is a slice of what the snapshot RPC already serves, never a re-derived or summarised view: a debugging read that reshapes what it read is a read nobody can reason about.

Implementation

factory PatchbaySnapshotSelection.resolve(
  Map<String, Object?> snapshot,
  String path,
) {
  Object? current = snapshot;
  final List<String> segments = path.split('.');
  for (var index = 0; index < segments.length; index += 1) {
    if (current == null) {
      return PatchbaySnapshotSelection.missing(
        path,
        PatchbaySnapshotMiss.nullValue,
      );
    }
    if (current is! Map<Object?, Object?>) {
      return PatchbaySnapshotSelection.missing(
        path,
        PatchbaySnapshotMiss.notAnObject,
      );
    }
    final String segment = segments[index];
    if (!current.containsKey(segment)) {
      return PatchbaySnapshotSelection.missing(
        path,
        PatchbaySnapshotMiss.missingKey,
      );
    }
    current = current[segment];
  }
  return current == null
      ? PatchbaySnapshotSelection.missing(
          path,
          PatchbaySnapshotMiss.nullValue,
        )
      : PatchbaySnapshotSelection.found(path, current);
}