getVersions method

Future<List<PackageId>> getVersions(
  1. PackageRef ref, {
  2. Duration? maxAge,
  3. Version? allowedRetractedVersion,
})

Get the IDs of all versions that match ref.

Note that this does not require the packages to be downloaded locally, which is the point. This is used during version resolution to determine which package versions are available to be downloaded (or already downloaded).

By default, this assumes that each description has a single version and uses describe to get that version.

If maxAge is given answers can be taken from cache - up to that age old.

If given, the allowedRetractedVersion is the only version which can be selected even if it is marked as retracted. Otherwise, all the returned IDs correspond to non-retracted versions.

Implementation

Future<List<PackageId>> getVersions(
  PackageRef ref, {
  Duration? maxAge,
  Version? allowedRetractedVersion,
}) async {
  var versions = await ref.source.doGetVersions(ref, maxAge, this);

  versions = (await Future.wait(
    versions.map((id) async {
      final packageStatus = await ref.source.status(
        id.toRef(),
        id.version,
        this,
        maxAge: maxAge,
      );
      if (!packageStatus.isRetracted ||
          id.version == allowedRetractedVersion) {
        return id;
      }
      return null;
    }),
  ))
      .nonNulls
      .toList();

  return versions;
}