Skip to content

Add isDiscontinued, replacedBy, and advisoriesUpdated to PubPackage model #68

Description

@leoafarias

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:

  1. Match the API spec more closely
  2. Avoid extra API calls to get this basic package metadata
  3. 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

  1. Fetch a discontinued package (if available): await client.packageInfo('discontinued_package')
  2. Verify isDiscontinued is true and replacedBy contains replacement package name
  3. Fetch a normal package and verify isDiscontinued is false and replacedBy is null
  4. 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>"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions