extractSupabaseList<T extends SupabaseObject> static method

List<T> extractSupabaseList<T extends SupabaseObject>(
  1. List<Map<String, dynamic>> response
)

Extracts a list of SupabaseObjects from a response. If some records could not be extracted, ExtractionFailedException is thrown containing the extracted records and the faulty records.

Implementation

static List<T> extractSupabaseList<T extends SupabaseObject>(
  List<Map<String, dynamic>> response,
) {
  final extracted = <T>[];
  final notExtracted = <JsonWithError>[];
  for (final json in response) {
    try {
      extracted.add(SupabaseObjectFunctions.fromJson<T>(json));
      // ignore: avoid_catching_errors
    } on ArgumentError catch (error) {
      // We are catching ArgumentError because unknown enums throw an ArgumentError
      // and UnknownJsonTypeError is a subclass of ArgumentError
      notExtracted.add(JsonWithError(json, error));
    }
  }
  if (notExtracted.isNotEmpty) {
    // If some records could not be extracted, we throw an exception
    // with the extracted records and the faulty records
    throw ExtractionFailedException(extracted, notExtracted);
  }
  return extracted;
}