needsAssignment method

bool needsAssignment(
  1. ClientParam param, [
  2. RecursiveMap? existingRoots
])

If a param is found within an existing map, it does not need to be assigned

// payload
{
  "data": {
    "name": "John",
    "email": "some@email.com"
  }
}

If access: [data, email] were passed in to the param then it would not need to be assigned

Implementation

bool needsAssignment(ClientParam param, [RecursiveMap? existingRoots]) {
  final roots = existingRoots ?? this.roots();

  if (roots.isEmpty && isNotEmpty) {
    return param.access.isEmpty;
  }

  RecursiveMap? current = roots;
  for (final (index, segment) in param.access.indexed) {
    if (current?[segment] == null) {
      if (index == 0) {
        // this root does not exist, so it does not need to be assigned
        return false;
      }

      return current?.keys.isNotEmpty ?? false;
    }

    current = current?[segment];
  }

  return true;
}