Description
Per the specification, the package info response includes isDiscontinued, replacedBy, and advisoriesUpdated fields. Currently, isDiscontinued and replacedBy are only exposed via the separate packageOptions() endpoint, not in the main PubPackage model.
Having these fields in the main model would:
- Match the API spec more closely
- Avoid extra API calls to get this basic package metadata
- Provide better developer experience
Priority
Medium - Improves API coverage and reduces unnecessary calls
Implementation
File: lib/src/models/pub_package_model.dart:10-28
Update the PubPackage model:
@MappableClass(includeCustomMappers: [PubspecMapper()])
class PubPackage with PubPackageMappable {
final String name;
final PackageVersion latest;
final List<PackageVersion> versions;
final bool isDiscontinued; // Add this
final String? replacedBy; // Add this
final DateTime? advisoriesUpdated; // Add this
const PubPackage({
required this.name,
required this.latest,
this.versions = const [],
this.isDiscontinued = false, // Default to false
this.replacedBy,
this.advisoriesUpdated,
});
String get version => latest.version;
String get description => latestPubspec.description ?? '';
String get url => 'https://pub.dev/packages/$name';
String get changelogUrl => '$url/changelog';
Pubspec get latestPubspec => latest.pubspec;
static const fromMap = PubPackageMapper.fromMap;
static const fromJson = PubPackageMapper.fromJson;
}
Note: After modifying the model, run the build_runner:
dart run build_runner build --delete-conflicting-outputs
Validation
- Fetch a discontinued package (if available):
await client.packageInfo('discontinued_package')
- Verify
isDiscontinued is true and replacedBy contains replacement package name
- Fetch a normal package and verify
isDiscontinued is false and replacedBy is null
- Check that
advisoriesUpdated is populated when available
Testing
- Update existing
packageInfo tests to check these new fields
- Test with a discontinued package (if one exists on pub.dev)
- Test with a normal, active package
- Verify backward compatibility - fields should be optional
Considerations
- The
PackageOptions endpoint can remain for now for backward compatibility
- These fields are optional in the API response, so handle them gracefully
advisoriesUpdated is only present if the server supports advisories
References
- Spec lines 228-232: Package info response with these fields
- Spec line 230:
"isDiscontinued": true || false
- Spec line 231:
"replacedBy": "<package>"
- Spec line 232:
"advisoriesUpdated": "<date-time>"
Description
Per the specification, the package info response includes
isDiscontinued,replacedBy, andadvisoriesUpdatedfields. Currently,isDiscontinuedandreplacedByare only exposed via the separatepackageOptions()endpoint, not in the mainPubPackagemodel.Having these fields in the main model would:
Priority
Medium - Improves API coverage and reduces unnecessary calls
Implementation
File:
lib/src/models/pub_package_model.dart:10-28Update the
PubPackagemodel:Note: After modifying the model, run the build_runner:
Validation
await client.packageInfo('discontinued_package')isDiscontinuedistrueandreplacedBycontains replacement package nameisDiscontinuedisfalseandreplacedByisnulladvisoriesUpdatedis populated when availableTesting
packageInfotests to check these new fieldsConsiderations
PackageOptionsendpoint can remain for now for backward compatibilityadvisoriesUpdatedis only present if the server supports advisoriesReferences
"isDiscontinued": true || false"replacedBy": "<package>""advisoriesUpdated": "<date-time>"