resolveIDs<V> method

List<V> resolveIDs<V>(
  1. Object? value
)

Implementation

List<V> resolveIDs<V>(Object? value) {
  if (value == null) return <V>[];

  if (value is O) {
    var id = getID(value as O);
    return id != null ? <V>[id] : [];
  } else if (value is Map) {
    var id = resolveIDFromMap(value);
    return id != null ? <V>[id] : [];
  } else if (value is Iterable) {
    var ids =
        value.map((e) => resolveID<V>(e)).whereNotNullResolved().toList();
    return ids;
  } else if (value is EntityReference) {
    var id = value.id;
    var ids = id != null ? <V>[id as V] : <V>[];
    return ids;
  } else if (value is EntityReferenceList) {
    var ids = value.idsNotNull.cast<V>().toList();
    return ids;
  }

  var idType = TypeInfo.fromType(this.idType());

  if (idType.isInt) {
    var ids = TypeParser.parseList<int>(value,
            elementParser: TypeParser.parseInt) ??
        <int>[];
    return ids as List<V>;
  } else if (idType.isBigInt) {
    var ids = TypeParser.parseList<BigInt>(value,
            elementParser: TypeParser.parseBigInt) ??
        <BigInt>[];
    return ids as List<V>;
  } else if (idType.isDouble) {
    var ids = TypeParser.parseList<double>(value,
            elementParser: TypeParser.parseDouble) ??
        <double>[];
    return ids as List<V>;
  } else if (idType.isString) {
    var ids = value
        .toString()
        .trim()
        .split(RegExp(r'\s+'))
        .map((s) => s.trim())
        .map((s) => (s.startsWith('"') && s.endsWith('"')) ||
                (s.startsWith("'") && s.endsWith("'"))
            ? s.substring(1, s.length - 1)
            : s)
        .where((s) => s.isNotEmpty)
        .toList();
    return ids as List<V>;
  }

  return <V>[value as V];
}