tidbGeneratedEndpointSetIsComplete function

bool tidbGeneratedEndpointSetIsComplete(
  1. Iterable<Object?> generated,
  2. Iterable<Map<String, dynamic>> remote
)

Returns whether every generated endpoint has a matching remote method/path.

The local ownership file is only a record of a previous successful apply; it cannot prove that the endpoint still exists in TiDB Cloud.

Implementation

bool tidbGeneratedEndpointSetIsComplete(
  Iterable<Object?> generated,
  Iterable<Map<String, dynamic>> remote,
) {
  final remoteKeys = remote
      .map(
        (item) => "${item["method"]?.toString().toUpperCase()}:${item["path"]}",
      )
      .toSet();
  return generated.every((raw) {
    final item = raw is Map
        ? raw.map((key, value) => MapEntry(key.toString(), value))
        : const <String, dynamic>{};
    final method = item["method"]?.toString().toUpperCase() ?? "";
    final path = item["endpoint"]?.toString() ?? "";
    return method.isNotEmpty &&
        path.isNotEmpty &&
        remoteKeys.contains("$method:$path");
  });
}