From 911c67ac8f90c38d0bd01beb979602953341895b Mon Sep 17 00:00:00 2001 From: leoafarias Date: Thu, 25 Mar 2021 06:36:37 -0400 Subject: [PATCH] Null safety migration, and dependency upgrades --- .github/workflows/build.yml | 4 +- .gitignore | 1 + CHANGELOG.md | 5 + build.yaml | 14 + lib/pub_api_client.dart | 1 - lib/src/endpoints.dart | 12 +- lib/src/helpers/console_helper.dart | 6 +- lib/src/helpers/deps_builder.dart | 27 ++ lib/src/helpers/google_packages.dart | 14 +- lib/src/helpers/google_packages_list.dart | 59 +-- lib/src/models/latest_version_model.dart | 6 +- .../models/package_documentation_model.dart | 16 +- .../package_documentation_model.freezed.dart | 162 ++++--- .../models/package_documentation_model.g.dart | 10 +- lib/src/models/package_metrics_model.dart | 6 +- .../models/package_metrics_model.freezed.dart | 68 +-- lib/src/models/package_metrics_model.g.dart | 9 +- lib/src/models/package_options_model.dart | 8 +- .../models/package_options_model.freezed.dart | 113 +++-- lib/src/models/package_options_model.g.dart | 8 +- lib/src/models/package_publisher_model.dart | 2 +- .../package_publisher_model.freezed.dart | 47 +- lib/src/models/package_score_model.dart | 38 +- .../models/package_score_model.freezed.dart | 409 ++++++++++-------- lib/src/models/package_score_model.g.dart | 46 +- lib/src/models/pub_credentials_model.dart | 12 +- .../models/pub_credentials_model.freezed.dart | 158 ++++--- lib/src/models/pub_credentials_model.g.dart | 4 +- lib/src/models/pub_package_model.dart | 16 +- lib/src/models/pub_package_model.freezed.dart | 203 +++++---- lib/src/models/pub_package_model.g.dart | 23 +- lib/src/models/search_results_model.dart | 17 +- .../models/search_results_model.freezed.dart | 104 +++-- lib/src/models/search_results_model.g.dart | 10 +- lib/src/pub_api_client_base.dart | 37 +- pubspec.yaml | 32 +- test/helpers_test.dart | 15 +- test/pubdev_api_test.dart | 32 +- 38 files changed, 1003 insertions(+), 751 deletions(-) create mode 100644 build.yaml create mode 100644 lib/src/helpers/deps_builder.dart diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a08bf72..68700e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,9 +25,9 @@ jobs: - name: Test Coverage run: pub run test_coverage - name: Remove generated files from Coverage - run: pub run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$' + run: pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$' - name: Remove freezed files from Coverage - run: pub run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.freezed.dart$' + run: pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.freezed.dart$' - name: Coveralls GitHub Action uses: coverallsapp/github-action@v1.1.2 with: diff --git a/.gitignore b/.gitignore index 1853368..105ef8b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ coverage/lcov.info .fvm .vscode/settings.json _notes.md +.env diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5ad51..9dd2581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.0 + +- Deprecated checkUpdatePrinter +- Changed latest version to display stable version only + ## 1.0.9 - Ability to pass custom http Client as param. diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..6fda545 --- /dev/null +++ b/build.yaml @@ -0,0 +1,14 @@ +# # Read about `build.yaml` at https://pub.dev/packages/build_config +# targets: +# $default: +# builders: +# build_google_deps: +# enabled: false + +# builders: +# build_google_deps: +# import: "package:pub_api_client/src/helpers/deps_builder.dart" +# builder_factories: ["googleDepsBuilder"] +# build_extensions: {"$lib$": ["src/helpers/google_packages_list.dart"]} +# build_to: source +# auto_apply: dependents \ No newline at end of file diff --git a/lib/pub_api_client.dart b/lib/pub_api_client.dart index 48a0da6..5fb5289 100644 --- a/lib/pub_api_client.dart +++ b/lib/pub_api_client.dart @@ -1,4 +1,3 @@ -export 'src/helpers/console_helper.dart'; export 'src/helpers/google_packages.dart'; export 'src/models/barrel.dart'; export 'src/pub_api_client_base.dart'; diff --git a/lib/src/endpoints.dart b/lib/src/endpoints.dart index 5869d78..24a5f43 100644 --- a/lib/src/endpoints.dart +++ b/lib/src/endpoints.dart @@ -1,13 +1,13 @@ /// Pub.dev api Endpoints class Endpoint { - String baseUrl; - String apiUrl; - String searchUrl; - String packageUrl; - String accountUrl; + late String baseUrl; + late String apiUrl; + late String searchUrl; + late String packageUrl; + late String accountUrl; /// Constructor for API endpoints based on an [url] - Endpoint(String url) { + Endpoint(String? url) { baseUrl = url ?? 'https://pub.dartlang.org'; // Use pub.dev instead? apiUrl = '$baseUrl/api'; searchUrl = '$apiUrl/search'; diff --git a/lib/src/helpers/console_helper.dart b/lib/src/helpers/console_helper.dart index 03439ee..39271c3 100644 --- a/lib/src/helpers/console_helper.dart +++ b/lib/src/helpers/console_helper.dart @@ -4,10 +4,10 @@ import '../../pub_api_client.dart'; /// is not the latest version. Future checkUpdatePrinter( String package, { - String currentVersion, + required String currentVersion, }) async { - final api = PubClient(); - final latest = await api.checkLatest(package, currentVersion: currentVersion); + final latest = + await PubClient().checkLatest(package, currentVersion: currentVersion); final latestVersion = latest.latestVersion; if (latest.needUpdate) { diff --git a/lib/src/helpers/deps_builder.dart b/lib/src/helpers/deps_builder.dart new file mode 100644 index 0000000..de4546c --- /dev/null +++ b/lib/src/helpers/deps_builder.dart @@ -0,0 +1,27 @@ +import 'dart:async'; +import 'dart:convert'; + +import 'package:build/build.dart'; +import 'package:pub_api_client/src/helpers/google_packages.dart'; + +Builder googleDepsBuilder([BuilderOptions? options]) => _DepsBuilder(); + +class _DepsBuilder implements Builder { + @override + Future build(BuildStep buildStep) async { + final googleDeps = await getGooglePackages(); + final deps = jsonEncode(googleDeps); + await buildStep.writeAsString( + AssetId(buildStep.inputId.package, + 'lib/src/helpers/google_packages_list.dart'), + ''' +// Generated code. Do not modify. +const googlePackagesList = $googleDeps ; +'''); + } + + @override + final buildExtensions = const { + r'$lib$': ['src/helpers/google_packages_list.dart'] + }; +} diff --git a/lib/src/helpers/google_packages.dart b/lib/src/helpers/google_packages.dart index 7ea080e..1a5a317 100644 --- a/lib/src/helpers/google_packages.dart +++ b/lib/src/helpers/google_packages.dart @@ -1,6 +1,5 @@ import '../models/search_results_model.dart'; import '../pub_api_client_base.dart'; -import 'google_packages_list.dart'; /// List of Google publishers on pub.dev const _publishers = [ @@ -10,16 +9,11 @@ const _publishers = [ 'firebase.google.com' ]; -final _googleDependencies = {for (var v in googlePackagesList) v: true}; - -/// Check is [package] is from Google -bool isGooglePubPackage(String package) => _googleDependencies[package] == true; - /// Retrieves all Google packages from pub.dev /// Mostly used as an internal tool to generate /// google_packages_list.dart /// You should probably use that instead -Future> getGooglePackages() async { +Future> getGooglePackages() async { final futures = >>[]; for (var publisher in _publishers) { futures.add(getPublisherPackages(publisher)); @@ -35,11 +29,13 @@ Future> getPublisherPackages(String publisherName) async { } Future> _recursivePaging(SearchResults prevResults) async { - final packages = prevResults.packages ?? []; + final packages = prevResults.packages; if (prevResults.next != null) { - final results = await prevResults.nextResults(); + // TODO: Check why linting not working for nullable and remove ?? '' + final results = await PubClient().nextPage(prevResults.next ?? ''); final nextResults = await _recursivePaging(results); packages.addAll(nextResults); } + return packages; } diff --git a/lib/src/helpers/google_packages_list.dart b/lib/src/helpers/google_packages_list.dart index 87b4262..7fab3b3 100644 --- a/lib/src/helpers/google_packages_list.dart +++ b/lib/src/helpers/google_packages_list.dart @@ -6,6 +6,7 @@ const googlePackagesList = [ 'video_player', 'animations', 'palette_generator', + 'image_picker', 'connectivity', 'device_info', 'pointer_interceptor', @@ -18,41 +19,40 @@ const googlePackagesList = [ 'camera', 'android_intent', 'sensors', + 'cross_file', 'battery', 'android_alarm_manager', 'quick_actions', 'integration_test', - 'multicast_dns', 'path_provider', - 'xdg_directories', - 'extension_google_sign_in_as_googleapis_auth', + 'multicast_dns', 'share', + 'devtools', 'local_auth', 'in_app_purchase', - 'cross_file', - 'devtools_shared', + 'xdg_directories', 'flutter_plugin_android_lifecycle', - 'devtools', + 'extension_google_sign_in_as_googleapis_auth', 'shared_preferences_windows', + 'devtools_shared', 'file_selector', 'connectivity_for_web', 'wifi_info_flutter', 'path_provider_windows', - 'url_launcher_windows', - 'ios_platform_images', - 'espresso', 'image_picker_for_web', + 'url_launcher_windows', 'google_maps_flutter_web', 'web_benchmarks', + 'ios_platform_images', + 'espresso', 'file_selector_web', 'devtools_server', - 'image_picker', - 'devtools_app', + 'quick_actions_platform_interface', 'devtools_testing', + 'devtools_app', 'http', 'path', 'crypto', - 'built_value', 'built_collection', 'yaml', 'googleapis', @@ -68,50 +68,51 @@ const googlePackagesList = [ 'markdown', 'protobuf', 'googleapis_auth', - 'built_value_generator', 'matcher', - 'typed_data', 'meta', + 'typed_data', 'html', - 'mockito', 'dart_style', 'grpc', - 'build_runner', + 'ffigen', 'test', + 'build_runner', 'http2', + 'mockito', 'intl_translation', - 'protoc_plugin', 'native_stack_traces', - 'os_detect', 'vm_snapshot_analysis', + 'protoc_plugin', + 'os_detect', 'test_core', 'built_value_test', '_fe_analyzer_shared', - 'ffigen', + 'built_value', + 'built_value_generator', 'google_fonts', 'adaptive_breakpoints', 'adaptive_navigation', 'adaptive_components', - 'firebase_analytics', - 'firebase_core', 'firebase_auth', - 'cloud_firestore', - 'firebase_dynamic_links', - 'firebase_remote_config', - 'firebase_ml_vision', 'cloud_functions', - 'firebase_performance', - 'firebase_messaging', + 'firebase_remote_config', 'firebase_storage', + 'firebase_analytics', 'firebase_crashlytics', + 'firebase_dynamic_links', + 'firebase_ml_vision', + 'firebase_performance', 'firebase_database', 'firebase_in_app_messaging', - 'firebase_ml_custom', 'firebase_core_web', 'firebase_messaging_web', 'firebase_auth_web', + 'firebase_ml_custom', 'cloud_firestore_web', 'cloud_functions_web', + 'firebase_storage_web', 'firebase_analytics_web', - 'firebase_storage_web' + 'firebase_core', + 'cloud_firestore', + 'firebase_messaging' ]; diff --git a/lib/src/models/latest_version_model.dart b/lib/src/models/latest_version_model.dart index 7c81ab8..c1fca61 100644 --- a/lib/src/models/latest_version_model.dart +++ b/lib/src/models/latest_version_model.dart @@ -8,8 +8,8 @@ class LatestVersion { /// Constructor LatestVersion({ - this.needUpdate, - this.latestVersion, - this.packageInfo, + required this.needUpdate, + required this.latestVersion, + required this.packageInfo, }); } diff --git a/lib/src/models/package_documentation_model.dart b/lib/src/models/package_documentation_model.dart index 4afaa18..7a77341 100644 --- a/lib/src/models/package_documentation_model.dart +++ b/lib/src/models/package_documentation_model.dart @@ -5,11 +5,11 @@ part 'package_documentation_model.g.dart'; /// Package Documentation Model @freezed -abstract class PackageDocumentation with _$PackageDocumentation { +class PackageDocumentation with _$PackageDocumentation { factory PackageDocumentation({ - final String name, - final String latestStableVersion, - final List versions, + required final String name, + required final String latestStableVersion, + @Default([]) final List versions, }) = _PackageDocumentation; factory PackageDocumentation.fromJson(Map json) => @@ -18,11 +18,11 @@ abstract class PackageDocumentation with _$PackageDocumentation { /// Package Documentation Version Model @freezed -abstract class PackageDocumentationVersion with _$PackageDocumentationVersion { +class PackageDocumentationVersion with _$PackageDocumentationVersion { factory PackageDocumentationVersion({ - final String version, - final String status, - final bool hasDocumentation, + required final String version, + required final String status, + required final bool hasDocumentation, }) = _PackageDocumentationVersion; factory PackageDocumentationVersion.fromJson(Map json) => diff --git a/lib/src/models/package_documentation_model.freezed.dart b/lib/src/models/package_documentation_model.freezed.dart index bb84cc3..be91581 100644 --- a/lib/src/models/package_documentation_model.freezed.dart +++ b/lib/src/models/package_documentation_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'package_documentation_model.dart'; @@ -8,6 +8,10 @@ part of 'package_documentation_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PackageDocumentation _$PackageDocumentationFromJson(Map json) { return _PackageDocumentation.fromJson(json); } @@ -16,11 +20,10 @@ PackageDocumentation _$PackageDocumentationFromJson(Map json) { class _$PackageDocumentationTearOff { const _$PackageDocumentationTearOff(); -// ignore: unused_element _PackageDocumentation call( - {String name, - String latestStableVersion, - List versions}) { + {required String name, + required String latestStableVersion, + List versions = const []}) { return _PackageDocumentation( name: name, latestStableVersion: latestStableVersion, @@ -28,24 +31,25 @@ class _$PackageDocumentationTearOff { ); } -// ignore: unused_element PackageDocumentation fromJson(Map json) { return PackageDocumentation.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageDocumentation = _$PackageDocumentationTearOff(); /// @nodoc mixin _$PackageDocumentation { - String get name; - String get latestStableVersion; - List get versions; - - Map toJson(); - $PackageDocumentationCopyWith get copyWith; + String get name => throw _privateConstructorUsedError; + String get latestStableVersion => throw _privateConstructorUsedError; + List get versions => + throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageDocumentationCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -70,18 +74,23 @@ class _$PackageDocumentationCopyWithImpl<$Res> @override $Res call({ - Object name = freezed, - Object latestStableVersion = freezed, - Object versions = freezed, + Object? name = freezed, + Object? latestStableVersion = freezed, + Object? versions = freezed, }) { return _then(_value.copyWith( - name: name == freezed ? _value.name : name as String, + name: name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, latestStableVersion: latestStableVersion == freezed ? _value.latestStableVersion - : latestStableVersion as String, + : latestStableVersion // ignore: cast_nullable_to_non_nullable + as String, versions: versions == freezed ? _value.versions - : versions as List, + : versions // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -112,18 +121,23 @@ class __$PackageDocumentationCopyWithImpl<$Res> @override $Res call({ - Object name = freezed, - Object latestStableVersion = freezed, - Object versions = freezed, + Object? name = freezed, + Object? latestStableVersion = freezed, + Object? versions = freezed, }) { return _then(_PackageDocumentation( - name: name == freezed ? _value.name : name as String, + name: name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, latestStableVersion: latestStableVersion == freezed ? _value.latestStableVersion - : latestStableVersion as String, + : latestStableVersion // ignore: cast_nullable_to_non_nullable + as String, versions: versions == freezed ? _value.versions - : versions as List, + : versions // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -132,7 +146,10 @@ class __$PackageDocumentationCopyWithImpl<$Res> /// @nodoc class _$_PackageDocumentation implements _PackageDocumentation { - _$_PackageDocumentation({this.name, this.latestStableVersion, this.versions}); + _$_PackageDocumentation( + {required this.name, + required this.latestStableVersion, + this.versions = const []}); factory _$_PackageDocumentation.fromJson(Map json) => _$_$_PackageDocumentationFromJson(json); @@ -141,6 +158,7 @@ class _$_PackageDocumentation implements _PackageDocumentation { final String name; @override final String latestStableVersion; + @JsonKey(defaultValue: const []) @override final List versions; @@ -170,6 +188,7 @@ class _$_PackageDocumentation implements _PackageDocumentation { const DeepCollectionEquality().hash(latestStableVersion) ^ const DeepCollectionEquality().hash(versions); + @JsonKey(ignore: true) @override _$PackageDocumentationCopyWith<_PackageDocumentation> get copyWith => __$PackageDocumentationCopyWithImpl<_PackageDocumentation>( @@ -183,21 +202,24 @@ class _$_PackageDocumentation implements _PackageDocumentation { abstract class _PackageDocumentation implements PackageDocumentation { factory _PackageDocumentation( - {String name, - String latestStableVersion, + {required String name, + required String latestStableVersion, List versions}) = _$_PackageDocumentation; factory _PackageDocumentation.fromJson(Map json) = _$_PackageDocumentation.fromJson; @override - String get name; + String get name => throw _privateConstructorUsedError; @override - String get latestStableVersion; + String get latestStableVersion => throw _privateConstructorUsedError; @override - List get versions; + List get versions => + throw _privateConstructorUsedError; @override - _$PackageDocumentationCopyWith<_PackageDocumentation> get copyWith; + @JsonKey(ignore: true) + _$PackageDocumentationCopyWith<_PackageDocumentation> get copyWith => + throw _privateConstructorUsedError; } PackageDocumentationVersion _$PackageDocumentationVersionFromJson( @@ -209,9 +231,10 @@ PackageDocumentationVersion _$PackageDocumentationVersionFromJson( class _$PackageDocumentationVersionTearOff { const _$PackageDocumentationVersionTearOff(); -// ignore: unused_element _PackageDocumentationVersion call( - {String version, String status, bool hasDocumentation}) { + {required String version, + required String status, + required bool hasDocumentation}) { return _PackageDocumentationVersion( version: version, status: status, @@ -219,25 +242,24 @@ class _$PackageDocumentationVersionTearOff { ); } -// ignore: unused_element PackageDocumentationVersion fromJson(Map json) { return PackageDocumentationVersion.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageDocumentationVersion = _$PackageDocumentationVersionTearOff(); /// @nodoc mixin _$PackageDocumentationVersion { - String get version; - String get status; - bool get hasDocumentation; + String get version => throw _privateConstructorUsedError; + String get status => throw _privateConstructorUsedError; + bool get hasDocumentation => throw _privateConstructorUsedError; - Map toJson(); + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) $PackageDocumentationVersionCopyWith - get copyWith; + get copyWith => throw _privateConstructorUsedError; } /// @nodoc @@ -260,16 +282,23 @@ class _$PackageDocumentationVersionCopyWithImpl<$Res> @override $Res call({ - Object version = freezed, - Object status = freezed, - Object hasDocumentation = freezed, + Object? version = freezed, + Object? status = freezed, + Object? hasDocumentation = freezed, }) { return _then(_value.copyWith( - version: version == freezed ? _value.version : version as String, - status: status == freezed ? _value.status : status as String, + version: version == freezed + ? _value.version + : version // ignore: cast_nullable_to_non_nullable + as String, + status: status == freezed + ? _value.status + : status // ignore: cast_nullable_to_non_nullable + as String, hasDocumentation: hasDocumentation == freezed ? _value.hasDocumentation - : hasDocumentation as bool, + : hasDocumentation // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -300,16 +329,23 @@ class __$PackageDocumentationVersionCopyWithImpl<$Res> @override $Res call({ - Object version = freezed, - Object status = freezed, - Object hasDocumentation = freezed, + Object? version = freezed, + Object? status = freezed, + Object? hasDocumentation = freezed, }) { return _then(_PackageDocumentationVersion( - version: version == freezed ? _value.version : version as String, - status: status == freezed ? _value.status : status as String, + version: version == freezed + ? _value.version + : version // ignore: cast_nullable_to_non_nullable + as String, + status: status == freezed + ? _value.status + : status // ignore: cast_nullable_to_non_nullable + as String, hasDocumentation: hasDocumentation == freezed ? _value.hasDocumentation - : hasDocumentation as bool, + : hasDocumentation // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -319,7 +355,9 @@ class __$PackageDocumentationVersionCopyWithImpl<$Res> /// @nodoc class _$_PackageDocumentationVersion implements _PackageDocumentationVersion { _$_PackageDocumentationVersion( - {this.version, this.status, this.hasDocumentation}); + {required this.version, + required this.status, + required this.hasDocumentation}); factory _$_PackageDocumentationVersion.fromJson(Map json) => _$_$_PackageDocumentationVersionFromJson(json); @@ -357,6 +395,7 @@ class _$_PackageDocumentationVersion implements _PackageDocumentationVersion { const DeepCollectionEquality().hash(status) ^ const DeepCollectionEquality().hash(hasDocumentation); + @JsonKey(ignore: true) @override _$PackageDocumentationVersionCopyWith<_PackageDocumentationVersion> get copyWith => __$PackageDocumentationVersionCopyWithImpl< @@ -371,20 +410,21 @@ class _$_PackageDocumentationVersion implements _PackageDocumentationVersion { abstract class _PackageDocumentationVersion implements PackageDocumentationVersion { factory _PackageDocumentationVersion( - {String version, - String status, - bool hasDocumentation}) = _$_PackageDocumentationVersion; + {required String version, + required String status, + required bool hasDocumentation}) = _$_PackageDocumentationVersion; factory _PackageDocumentationVersion.fromJson(Map json) = _$_PackageDocumentationVersion.fromJson; @override - String get version; + String get version => throw _privateConstructorUsedError; @override - String get status; + String get status => throw _privateConstructorUsedError; @override - bool get hasDocumentation; + bool get hasDocumentation => throw _privateConstructorUsedError; @override + @JsonKey(ignore: true) _$PackageDocumentationVersionCopyWith<_PackageDocumentationVersion> - get copyWith; + get copyWith => throw _privateConstructorUsedError; } diff --git a/lib/src/models/package_documentation_model.g.dart b/lib/src/models/package_documentation_model.g.dart index 6975be6..d105663 100644 --- a/lib/src/models/package_documentation_model.g.dart +++ b/lib/src/models/package_documentation_model.g.dart @@ -11,11 +11,11 @@ _$_PackageDocumentation _$_$_PackageDocumentationFromJson( return _$_PackageDocumentation( name: json['name'] as String, latestStableVersion: json['latestStableVersion'] as String, - versions: (json['versions'] as List) - ?.map((e) => e == null - ? null - : PackageDocumentationVersion.fromJson(e as Map)) - ?.toList(), + versions: (json['versions'] as List?) + ?.map((e) => + PackageDocumentationVersion.fromJson(e as Map)) + .toList() ?? + [], ); } diff --git a/lib/src/models/package_metrics_model.dart b/lib/src/models/package_metrics_model.dart index 1c0b798..69f3c4c 100644 --- a/lib/src/models/package_metrics_model.dart +++ b/lib/src/models/package_metrics_model.dart @@ -6,10 +6,10 @@ part 'package_metrics_model.g.dart'; /// Package Metrics Model @freezed -abstract class PackageMetrics with _$PackageMetrics { +class PackageMetrics with _$PackageMetrics { factory PackageMetrics({ - final PackageScore score, - final PackageScoreCard scorecard, + required final PackageScore score, + required final PackageScoreCard scorecard, }) = _PackageMetrics; factory PackageMetrics.fromJson(Map json) => diff --git a/lib/src/models/package_metrics_model.freezed.dart b/lib/src/models/package_metrics_model.freezed.dart index 318f32a..7749144 100644 --- a/lib/src/models/package_metrics_model.freezed.dart +++ b/lib/src/models/package_metrics_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'package_metrics_model.dart'; @@ -8,6 +8,10 @@ part of 'package_metrics_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PackageMetrics _$PackageMetricsFromJson(Map json) { return _PackageMetrics.fromJson(json); } @@ -16,31 +20,31 @@ PackageMetrics _$PackageMetricsFromJson(Map json) { class _$PackageMetricsTearOff { const _$PackageMetricsTearOff(); -// ignore: unused_element - _PackageMetrics call({PackageScore score, PackageScoreCard scorecard}) { + _PackageMetrics call( + {required PackageScore score, required PackageScoreCard scorecard}) { return _PackageMetrics( score: score, scorecard: scorecard, ); } -// ignore: unused_element PackageMetrics fromJson(Map json) { return PackageMetrics.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageMetrics = _$PackageMetricsTearOff(); /// @nodoc mixin _$PackageMetrics { - PackageScore get score; - PackageScoreCard get scorecard; + PackageScore get score => throw _privateConstructorUsedError; + PackageScoreCard get scorecard => throw _privateConstructorUsedError; - Map toJson(); - $PackageMetricsCopyWith get copyWith; + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageMetricsCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -65,22 +69,23 @@ class _$PackageMetricsCopyWithImpl<$Res> @override $Res call({ - Object score = freezed, - Object scorecard = freezed, + Object? score = freezed, + Object? scorecard = freezed, }) { return _then(_value.copyWith( - score: score == freezed ? _value.score : score as PackageScore, + score: score == freezed + ? _value.score + : score // ignore: cast_nullable_to_non_nullable + as PackageScore, scorecard: scorecard == freezed ? _value.scorecard - : scorecard as PackageScoreCard, + : scorecard // ignore: cast_nullable_to_non_nullable + as PackageScoreCard, )); } @override $PackageScoreCopyWith<$Res> get score { - if (_value.score == null) { - return null; - } return $PackageScoreCopyWith<$Res>(_value.score, (value) { return _then(_value.copyWith(score: value)); }); @@ -88,9 +93,6 @@ class _$PackageMetricsCopyWithImpl<$Res> @override $PackageScoreCardCopyWith<$Res> get scorecard { - if (_value.scorecard == null) { - return null; - } return $PackageScoreCardCopyWith<$Res>(_value.scorecard, (value) { return _then(_value.copyWith(scorecard: value)); }); @@ -125,14 +127,18 @@ class __$PackageMetricsCopyWithImpl<$Res> @override $Res call({ - Object score = freezed, - Object scorecard = freezed, + Object? score = freezed, + Object? scorecard = freezed, }) { return _then(_PackageMetrics( - score: score == freezed ? _value.score : score as PackageScore, + score: score == freezed + ? _value.score + : score // ignore: cast_nullable_to_non_nullable + as PackageScore, scorecard: scorecard == freezed ? _value.scorecard - : scorecard as PackageScoreCard, + : scorecard // ignore: cast_nullable_to_non_nullable + as PackageScoreCard, )); } } @@ -141,7 +147,7 @@ class __$PackageMetricsCopyWithImpl<$Res> /// @nodoc class _$_PackageMetrics implements _PackageMetrics { - _$_PackageMetrics({this.score, this.scorecard}); + _$_PackageMetrics({required this.score, required this.scorecard}); factory _$_PackageMetrics.fromJson(Map json) => _$_$_PackageMetricsFromJson(json); @@ -173,6 +179,7 @@ class _$_PackageMetrics implements _PackageMetrics { const DeepCollectionEquality().hash(score) ^ const DeepCollectionEquality().hash(scorecard); + @JsonKey(ignore: true) @override _$PackageMetricsCopyWith<_PackageMetrics> get copyWith => __$PackageMetricsCopyWithImpl<_PackageMetrics>(this, _$identity); @@ -184,16 +191,19 @@ class _$_PackageMetrics implements _PackageMetrics { } abstract class _PackageMetrics implements PackageMetrics { - factory _PackageMetrics({PackageScore score, PackageScoreCard scorecard}) = - _$_PackageMetrics; + factory _PackageMetrics( + {required PackageScore score, + required PackageScoreCard scorecard}) = _$_PackageMetrics; factory _PackageMetrics.fromJson(Map json) = _$_PackageMetrics.fromJson; @override - PackageScore get score; + PackageScore get score => throw _privateConstructorUsedError; @override - PackageScoreCard get scorecard; + PackageScoreCard get scorecard => throw _privateConstructorUsedError; @override - _$PackageMetricsCopyWith<_PackageMetrics> get copyWith; + @JsonKey(ignore: true) + _$PackageMetricsCopyWith<_PackageMetrics> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/package_metrics_model.g.dart b/lib/src/models/package_metrics_model.g.dart index f24d9ba..50a9f98 100644 --- a/lib/src/models/package_metrics_model.g.dart +++ b/lib/src/models/package_metrics_model.g.dart @@ -8,12 +8,9 @@ part of 'package_metrics_model.dart'; _$_PackageMetrics _$_$_PackageMetricsFromJson(Map json) { return _$_PackageMetrics( - score: json['score'] == null - ? null - : PackageScore.fromJson(json['score'] as Map), - scorecard: json['scorecard'] == null - ? null - : PackageScoreCard.fromJson(json['scorecard'] as Map), + score: PackageScore.fromJson(json['score'] as Map), + scorecard: + PackageScoreCard.fromJson(json['scorecard'] as Map), ); } diff --git a/lib/src/models/package_options_model.dart b/lib/src/models/package_options_model.dart index 7abb507..4f9b973 100644 --- a/lib/src/models/package_options_model.dart +++ b/lib/src/models/package_options_model.dart @@ -5,11 +5,11 @@ part 'package_options_model.g.dart'; /// Package Options Model @freezed -abstract class PackageOptions with _$PackageOptions { +class PackageOptions with _$PackageOptions { factory PackageOptions({ - final bool isDiscontinued, - final String replacedBy, - final bool isUnlisted, + @Default(false) final bool isDiscontinued, + @Default(false) final bool isUnlisted, + final String? replacedBy, }) = _PackageOptions; factory PackageOptions.fromJson(Map json) => diff --git a/lib/src/models/package_options_model.freezed.dart b/lib/src/models/package_options_model.freezed.dart index 3227226..1dc8adb 100644 --- a/lib/src/models/package_options_model.freezed.dart +++ b/lib/src/models/package_options_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'package_options_model.dart'; @@ -8,6 +8,10 @@ part of 'package_options_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PackageOptions _$PackageOptionsFromJson(Map json) { return _PackageOptions.fromJson(json); } @@ -16,34 +20,35 @@ PackageOptions _$PackageOptionsFromJson(Map json) { class _$PackageOptionsTearOff { const _$PackageOptionsTearOff(); -// ignore: unused_element _PackageOptions call( - {bool isDiscontinued, String replacedBy, bool isUnlisted}) { + {bool isDiscontinued = false, + bool isUnlisted = false, + String? replacedBy}) { return _PackageOptions( isDiscontinued: isDiscontinued, - replacedBy: replacedBy, isUnlisted: isUnlisted, + replacedBy: replacedBy, ); } -// ignore: unused_element PackageOptions fromJson(Map json) { return PackageOptions.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageOptions = _$PackageOptionsTearOff(); /// @nodoc mixin _$PackageOptions { - bool get isDiscontinued; - String get replacedBy; - bool get isUnlisted; - - Map toJson(); - $PackageOptionsCopyWith get copyWith; + bool get isDiscontinued => throw _privateConstructorUsedError; + bool get isUnlisted => throw _privateConstructorUsedError; + String? get replacedBy => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageOptionsCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -51,7 +56,7 @@ abstract class $PackageOptionsCopyWith<$Res> { factory $PackageOptionsCopyWith( PackageOptions value, $Res Function(PackageOptions) then) = _$PackageOptionsCopyWithImpl<$Res>; - $Res call({bool isDiscontinued, String replacedBy, bool isUnlisted}); + $Res call({bool isDiscontinued, bool isUnlisted, String? replacedBy}); } /// @nodoc @@ -65,18 +70,23 @@ class _$PackageOptionsCopyWithImpl<$Res> @override $Res call({ - Object isDiscontinued = freezed, - Object replacedBy = freezed, - Object isUnlisted = freezed, + Object? isDiscontinued = freezed, + Object? isUnlisted = freezed, + Object? replacedBy = freezed, }) { return _then(_value.copyWith( isDiscontinued: isDiscontinued == freezed ? _value.isDiscontinued - : isDiscontinued as bool, - replacedBy: - replacedBy == freezed ? _value.replacedBy : replacedBy as String, - isUnlisted: - isUnlisted == freezed ? _value.isUnlisted : isUnlisted as bool, + : isDiscontinued // ignore: cast_nullable_to_non_nullable + as bool, + isUnlisted: isUnlisted == freezed + ? _value.isUnlisted + : isUnlisted // ignore: cast_nullable_to_non_nullable + as bool, + replacedBy: replacedBy == freezed + ? _value.replacedBy + : replacedBy // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -88,7 +98,7 @@ abstract class _$PackageOptionsCopyWith<$Res> _PackageOptions value, $Res Function(_PackageOptions) then) = __$PackageOptionsCopyWithImpl<$Res>; @override - $Res call({bool isDiscontinued, String replacedBy, bool isUnlisted}); + $Res call({bool isDiscontinued, bool isUnlisted, String? replacedBy}); } /// @nodoc @@ -104,18 +114,23 @@ class __$PackageOptionsCopyWithImpl<$Res> @override $Res call({ - Object isDiscontinued = freezed, - Object replacedBy = freezed, - Object isUnlisted = freezed, + Object? isDiscontinued = freezed, + Object? isUnlisted = freezed, + Object? replacedBy = freezed, }) { return _then(_PackageOptions( isDiscontinued: isDiscontinued == freezed ? _value.isDiscontinued - : isDiscontinued as bool, - replacedBy: - replacedBy == freezed ? _value.replacedBy : replacedBy as String, - isUnlisted: - isUnlisted == freezed ? _value.isUnlisted : isUnlisted as bool, + : isDiscontinued // ignore: cast_nullable_to_non_nullable + as bool, + isUnlisted: isUnlisted == freezed + ? _value.isUnlisted + : isUnlisted // ignore: cast_nullable_to_non_nullable + as bool, + replacedBy: replacedBy == freezed + ? _value.replacedBy + : replacedBy // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -124,21 +139,24 @@ class __$PackageOptionsCopyWithImpl<$Res> /// @nodoc class _$_PackageOptions implements _PackageOptions { - _$_PackageOptions({this.isDiscontinued, this.replacedBy, this.isUnlisted}); + _$_PackageOptions( + {this.isDiscontinued = false, this.isUnlisted = false, this.replacedBy}); factory _$_PackageOptions.fromJson(Map json) => _$_$_PackageOptionsFromJson(json); + @JsonKey(defaultValue: false) @override final bool isDiscontinued; - @override - final String replacedBy; + @JsonKey(defaultValue: false) @override final bool isUnlisted; + @override + final String? replacedBy; @override String toString() { - return 'PackageOptions(isDiscontinued: $isDiscontinued, replacedBy: $replacedBy, isUnlisted: $isUnlisted)'; + return 'PackageOptions(isDiscontinued: $isDiscontinued, isUnlisted: $isUnlisted, replacedBy: $replacedBy)'; } @override @@ -148,21 +166,22 @@ class _$_PackageOptions implements _PackageOptions { (identical(other.isDiscontinued, isDiscontinued) || const DeepCollectionEquality() .equals(other.isDiscontinued, isDiscontinued)) && - (identical(other.replacedBy, replacedBy) || - const DeepCollectionEquality() - .equals(other.replacedBy, replacedBy)) && (identical(other.isUnlisted, isUnlisted) || const DeepCollectionEquality() - .equals(other.isUnlisted, isUnlisted))); + .equals(other.isUnlisted, isUnlisted)) && + (identical(other.replacedBy, replacedBy) || + const DeepCollectionEquality() + .equals(other.replacedBy, replacedBy))); } @override int get hashCode => runtimeType.hashCode ^ const DeepCollectionEquality().hash(isDiscontinued) ^ - const DeepCollectionEquality().hash(replacedBy) ^ - const DeepCollectionEquality().hash(isUnlisted); + const DeepCollectionEquality().hash(isUnlisted) ^ + const DeepCollectionEquality().hash(replacedBy); + @JsonKey(ignore: true) @override _$PackageOptionsCopyWith<_PackageOptions> get copyWith => __$PackageOptionsCopyWithImpl<_PackageOptions>(this, _$identity); @@ -176,18 +195,20 @@ class _$_PackageOptions implements _PackageOptions { abstract class _PackageOptions implements PackageOptions { factory _PackageOptions( {bool isDiscontinued, - String replacedBy, - bool isUnlisted}) = _$_PackageOptions; + bool isUnlisted, + String? replacedBy}) = _$_PackageOptions; factory _PackageOptions.fromJson(Map json) = _$_PackageOptions.fromJson; @override - bool get isDiscontinued; + bool get isDiscontinued => throw _privateConstructorUsedError; @override - String get replacedBy; + bool get isUnlisted => throw _privateConstructorUsedError; @override - bool get isUnlisted; + String? get replacedBy => throw _privateConstructorUsedError; @override - _$PackageOptionsCopyWith<_PackageOptions> get copyWith; + @JsonKey(ignore: true) + _$PackageOptionsCopyWith<_PackageOptions> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/package_options_model.g.dart b/lib/src/models/package_options_model.g.dart index 9ced1d8..b23ee6a 100644 --- a/lib/src/models/package_options_model.g.dart +++ b/lib/src/models/package_options_model.g.dart @@ -8,15 +8,15 @@ part of 'package_options_model.dart'; _$_PackageOptions _$_$_PackageOptionsFromJson(Map json) { return _$_PackageOptions( - isDiscontinued: json['isDiscontinued'] as bool, - replacedBy: json['replacedBy'] as String, - isUnlisted: json['isUnlisted'] as bool, + isDiscontinued: json['isDiscontinued'] as bool? ?? false, + isUnlisted: json['isUnlisted'] as bool? ?? false, + replacedBy: json['replacedBy'] as String?, ); } Map _$_$_PackageOptionsToJson(_$_PackageOptions instance) => { 'isDiscontinued': instance.isDiscontinued, - 'replacedBy': instance.replacedBy, 'isUnlisted': instance.isUnlisted, + 'replacedBy': instance.replacedBy, }; diff --git a/lib/src/models/package_publisher_model.dart b/lib/src/models/package_publisher_model.dart index a30119c..44761b9 100644 --- a/lib/src/models/package_publisher_model.dart +++ b/lib/src/models/package_publisher_model.dart @@ -7,7 +7,7 @@ part 'package_publisher_model.g.dart'; @freezed abstract class PackagePublisher with _$PackagePublisher { factory PackagePublisher({ - final String publisherId, + required final String publisherId, }) = _PackagePublisher; factory PackagePublisher.fromJson(Map json) => diff --git a/lib/src/models/package_publisher_model.freezed.dart b/lib/src/models/package_publisher_model.freezed.dart index 24b7b44..3dc7d9f 100644 --- a/lib/src/models/package_publisher_model.freezed.dart +++ b/lib/src/models/package_publisher_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'package_publisher_model.dart'; @@ -8,6 +8,10 @@ part of 'package_publisher_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PackagePublisher _$PackagePublisherFromJson(Map json) { return _PackagePublisher.fromJson(json); } @@ -16,29 +20,28 @@ PackagePublisher _$PackagePublisherFromJson(Map json) { class _$PackagePublisherTearOff { const _$PackagePublisherTearOff(); -// ignore: unused_element - _PackagePublisher call({String publisherId}) { + _PackagePublisher call({required String publisherId}) { return _PackagePublisher( publisherId: publisherId, ); } -// ignore: unused_element PackagePublisher fromJson(Map json) { return PackagePublisher.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackagePublisher = _$PackagePublisherTearOff(); /// @nodoc mixin _$PackagePublisher { - String get publisherId; + String get publisherId => throw _privateConstructorUsedError; - Map toJson(); - $PackagePublisherCopyWith get copyWith; + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackagePublisherCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -60,11 +63,13 @@ class _$PackagePublisherCopyWithImpl<$Res> @override $Res call({ - Object publisherId = freezed, + Object? publisherId = freezed, }) { return _then(_value.copyWith( - publisherId: - publisherId == freezed ? _value.publisherId : publisherId as String, + publisherId: publisherId == freezed + ? _value.publisherId + : publisherId // ignore: cast_nullable_to_non_nullable + as String, )); } } @@ -92,11 +97,13 @@ class __$PackagePublisherCopyWithImpl<$Res> @override $Res call({ - Object publisherId = freezed, + Object? publisherId = freezed, }) { return _then(_PackagePublisher( - publisherId: - publisherId == freezed ? _value.publisherId : publisherId as String, + publisherId: publisherId == freezed + ? _value.publisherId + : publisherId // ignore: cast_nullable_to_non_nullable + as String, )); } } @@ -105,7 +112,7 @@ class __$PackagePublisherCopyWithImpl<$Res> /// @nodoc class _$_PackagePublisher implements _PackagePublisher { - _$_PackagePublisher({this.publisherId}); + _$_PackagePublisher({required this.publisherId}); factory _$_PackagePublisher.fromJson(Map json) => _$_$_PackagePublisherFromJson(json); @@ -131,6 +138,7 @@ class _$_PackagePublisher implements _PackagePublisher { int get hashCode => runtimeType.hashCode ^ const DeepCollectionEquality().hash(publisherId); + @JsonKey(ignore: true) @override _$PackagePublisherCopyWith<_PackagePublisher> get copyWith => __$PackagePublisherCopyWithImpl<_PackagePublisher>(this, _$identity); @@ -142,13 +150,16 @@ class _$_PackagePublisher implements _PackagePublisher { } abstract class _PackagePublisher implements PackagePublisher { - factory _PackagePublisher({String publisherId}) = _$_PackagePublisher; + factory _PackagePublisher({required String publisherId}) = + _$_PackagePublisher; factory _PackagePublisher.fromJson(Map json) = _$_PackagePublisher.fromJson; @override - String get publisherId; + String get publisherId => throw _privateConstructorUsedError; @override - _$PackagePublisherCopyWith<_PackagePublisher> get copyWith; + @JsonKey(ignore: true) + _$PackagePublisherCopyWith<_PackagePublisher> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/package_score_model.dart b/lib/src/models/package_score_model.dart index 4dd009c..505fcc4 100644 --- a/lib/src/models/package_score_model.dart +++ b/lib/src/models/package_score_model.dart @@ -5,13 +5,13 @@ part 'package_score_model.g.dart'; /// Package Score Model @freezed -abstract class PackageScore with _$PackageScore { +class PackageScore with _$PackageScore { factory PackageScore({ - final int grantedPoints, - final int maxPoints, - final int likeCount, - final double popularityScore, - final DateTime lastUpdated, + required final int grantedPoints, + required final int maxPoints, + required final int likeCount, + required final double popularityScore, + required final DateTime lastUpdated, }) = _PackageScore; factory PackageScore.fromJson(Map json) => @@ -20,20 +20,20 @@ abstract class PackageScore with _$PackageScore { /// Package Score Card Model @freezed -abstract class PackageScoreCard with _$PackageScoreCard { +class PackageScoreCard with _$PackageScoreCard { factory PackageScoreCard({ - final String packageName, - final String packageVersion, - final String runtimeVersion, - final DateTime updated, - final DateTime packageCreated, - final DateTime packageVersionCreated, - final int grantedPubPoints, - final int maxPubPoints, - final double popularityScore, - final List derivedTags, - final List flags, - final List reportTypes, + required final String packageName, + required final String packageVersion, + required final String runtimeVersion, + required final DateTime updated, + required final DateTime packageCreated, + required final DateTime packageVersionCreated, + required final int grantedPubPoints, + required final int maxPubPoints, + required final double popularityScore, + @Default([]) final List derivedTags, + @Default([]) final List flags, + @Default([]) final List reportTypes, }) = _PackageScoreCard; factory PackageScoreCard.fromJson(Map json) => diff --git a/lib/src/models/package_score_model.freezed.dart b/lib/src/models/package_score_model.freezed.dart index 469ce8b..37f60fe 100644 --- a/lib/src/models/package_score_model.freezed.dart +++ b/lib/src/models/package_score_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'package_score_model.dart'; @@ -8,6 +8,10 @@ part of 'package_score_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PackageScore _$PackageScoreFromJson(Map json) { return _PackageScore.fromJson(json); } @@ -16,13 +20,12 @@ PackageScore _$PackageScoreFromJson(Map json) { class _$PackageScoreTearOff { const _$PackageScoreTearOff(); -// ignore: unused_element _PackageScore call( - {int grantedPoints, - int maxPoints, - int likeCount, - double popularityScore, - DateTime lastUpdated}) { + {required int grantedPoints, + required int maxPoints, + required int likeCount, + required double popularityScore, + required DateTime lastUpdated}) { return _PackageScore( grantedPoints: grantedPoints, maxPoints: maxPoints, @@ -32,26 +35,26 @@ class _$PackageScoreTearOff { ); } -// ignore: unused_element PackageScore fromJson(Map json) { return PackageScore.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageScore = _$PackageScoreTearOff(); /// @nodoc mixin _$PackageScore { - int get grantedPoints; - int get maxPoints; - int get likeCount; - double get popularityScore; - DateTime get lastUpdated; - - Map toJson(); - $PackageScoreCopyWith get copyWith; + int get grantedPoints => throw _privateConstructorUsedError; + int get maxPoints => throw _privateConstructorUsedError; + int get likeCount => throw _privateConstructorUsedError; + double get popularityScore => throw _privateConstructorUsedError; + DateTime get lastUpdated => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageScoreCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -77,23 +80,33 @@ class _$PackageScoreCopyWithImpl<$Res> implements $PackageScoreCopyWith<$Res> { @override $Res call({ - Object grantedPoints = freezed, - Object maxPoints = freezed, - Object likeCount = freezed, - Object popularityScore = freezed, - Object lastUpdated = freezed, + Object? grantedPoints = freezed, + Object? maxPoints = freezed, + Object? likeCount = freezed, + Object? popularityScore = freezed, + Object? lastUpdated = freezed, }) { return _then(_value.copyWith( grantedPoints: grantedPoints == freezed ? _value.grantedPoints - : grantedPoints as int, - maxPoints: maxPoints == freezed ? _value.maxPoints : maxPoints as int, - likeCount: likeCount == freezed ? _value.likeCount : likeCount as int, + : grantedPoints // ignore: cast_nullable_to_non_nullable + as int, + maxPoints: maxPoints == freezed + ? _value.maxPoints + : maxPoints // ignore: cast_nullable_to_non_nullable + as int, + likeCount: likeCount == freezed + ? _value.likeCount + : likeCount // ignore: cast_nullable_to_non_nullable + as int, popularityScore: popularityScore == freezed ? _value.popularityScore - : popularityScore as double, - lastUpdated: - lastUpdated == freezed ? _value.lastUpdated : lastUpdated as DateTime, + : popularityScore // ignore: cast_nullable_to_non_nullable + as double, + lastUpdated: lastUpdated == freezed + ? _value.lastUpdated + : lastUpdated // ignore: cast_nullable_to_non_nullable + as DateTime, )); } } @@ -125,23 +138,33 @@ class __$PackageScoreCopyWithImpl<$Res> extends _$PackageScoreCopyWithImpl<$Res> @override $Res call({ - Object grantedPoints = freezed, - Object maxPoints = freezed, - Object likeCount = freezed, - Object popularityScore = freezed, - Object lastUpdated = freezed, + Object? grantedPoints = freezed, + Object? maxPoints = freezed, + Object? likeCount = freezed, + Object? popularityScore = freezed, + Object? lastUpdated = freezed, }) { return _then(_PackageScore( grantedPoints: grantedPoints == freezed ? _value.grantedPoints - : grantedPoints as int, - maxPoints: maxPoints == freezed ? _value.maxPoints : maxPoints as int, - likeCount: likeCount == freezed ? _value.likeCount : likeCount as int, + : grantedPoints // ignore: cast_nullable_to_non_nullable + as int, + maxPoints: maxPoints == freezed + ? _value.maxPoints + : maxPoints // ignore: cast_nullable_to_non_nullable + as int, + likeCount: likeCount == freezed + ? _value.likeCount + : likeCount // ignore: cast_nullable_to_non_nullable + as int, popularityScore: popularityScore == freezed ? _value.popularityScore - : popularityScore as double, - lastUpdated: - lastUpdated == freezed ? _value.lastUpdated : lastUpdated as DateTime, + : popularityScore // ignore: cast_nullable_to_non_nullable + as double, + lastUpdated: lastUpdated == freezed + ? _value.lastUpdated + : lastUpdated // ignore: cast_nullable_to_non_nullable + as DateTime, )); } } @@ -151,11 +174,11 @@ class __$PackageScoreCopyWithImpl<$Res> extends _$PackageScoreCopyWithImpl<$Res> /// @nodoc class _$_PackageScore implements _PackageScore { _$_PackageScore( - {this.grantedPoints, - this.maxPoints, - this.likeCount, - this.popularityScore, - this.lastUpdated}); + {required this.grantedPoints, + required this.maxPoints, + required this.likeCount, + required this.popularityScore, + required this.lastUpdated}); factory _$_PackageScore.fromJson(Map json) => _$_$_PackageScoreFromJson(json); @@ -206,6 +229,7 @@ class _$_PackageScore implements _PackageScore { const DeepCollectionEquality().hash(popularityScore) ^ const DeepCollectionEquality().hash(lastUpdated); + @JsonKey(ignore: true) @override _$PackageScoreCopyWith<_PackageScore> get copyWith => __$PackageScoreCopyWithImpl<_PackageScore>(this, _$identity); @@ -218,27 +242,29 @@ class _$_PackageScore implements _PackageScore { abstract class _PackageScore implements PackageScore { factory _PackageScore( - {int grantedPoints, - int maxPoints, - int likeCount, - double popularityScore, - DateTime lastUpdated}) = _$_PackageScore; + {required int grantedPoints, + required int maxPoints, + required int likeCount, + required double popularityScore, + required DateTime lastUpdated}) = _$_PackageScore; factory _PackageScore.fromJson(Map json) = _$_PackageScore.fromJson; @override - int get grantedPoints; + int get grantedPoints => throw _privateConstructorUsedError; @override - int get maxPoints; + int get maxPoints => throw _privateConstructorUsedError; @override - int get likeCount; + int get likeCount => throw _privateConstructorUsedError; @override - double get popularityScore; + double get popularityScore => throw _privateConstructorUsedError; @override - DateTime get lastUpdated; + DateTime get lastUpdated => throw _privateConstructorUsedError; @override - _$PackageScoreCopyWith<_PackageScore> get copyWith; + @JsonKey(ignore: true) + _$PackageScoreCopyWith<_PackageScore> get copyWith => + throw _privateConstructorUsedError; } PackageScoreCard _$PackageScoreCardFromJson(Map json) { @@ -249,20 +275,19 @@ PackageScoreCard _$PackageScoreCardFromJson(Map json) { class _$PackageScoreCardTearOff { const _$PackageScoreCardTearOff(); -// ignore: unused_element _PackageScoreCard call( - {String packageName, - String packageVersion, - String runtimeVersion, - DateTime updated, - DateTime packageCreated, - DateTime packageVersionCreated, - int grantedPubPoints, - int maxPubPoints, - double popularityScore, - List derivedTags, - List flags, - List reportTypes}) { + {required String packageName, + required String packageVersion, + required String runtimeVersion, + required DateTime updated, + required DateTime packageCreated, + required DateTime packageVersionCreated, + required int grantedPubPoints, + required int maxPubPoints, + required double popularityScore, + List derivedTags = const [], + List flags = const [], + List reportTypes = const []}) { return _PackageScoreCard( packageName: packageName, packageVersion: packageVersion, @@ -279,33 +304,33 @@ class _$PackageScoreCardTearOff { ); } -// ignore: unused_element PackageScoreCard fromJson(Map json) { return PackageScoreCard.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageScoreCard = _$PackageScoreCardTearOff(); /// @nodoc mixin _$PackageScoreCard { - String get packageName; - String get packageVersion; - String get runtimeVersion; - DateTime get updated; - DateTime get packageCreated; - DateTime get packageVersionCreated; - int get grantedPubPoints; - int get maxPubPoints; - double get popularityScore; - List get derivedTags; - List get flags; - List get reportTypes; - - Map toJson(); - $PackageScoreCardCopyWith get copyWith; + String get packageName => throw _privateConstructorUsedError; + String get packageVersion => throw _privateConstructorUsedError; + String get runtimeVersion => throw _privateConstructorUsedError; + DateTime get updated => throw _privateConstructorUsedError; + DateTime get packageCreated => throw _privateConstructorUsedError; + DateTime get packageVersionCreated => throw _privateConstructorUsedError; + int get grantedPubPoints => throw _privateConstructorUsedError; + int get maxPubPoints => throw _privateConstructorUsedError; + double get popularityScore => throw _privateConstructorUsedError; + List get derivedTags => throw _privateConstructorUsedError; + List get flags => throw _privateConstructorUsedError; + List get reportTypes => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageScoreCardCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -339,50 +364,68 @@ class _$PackageScoreCardCopyWithImpl<$Res> @override $Res call({ - Object packageName = freezed, - Object packageVersion = freezed, - Object runtimeVersion = freezed, - Object updated = freezed, - Object packageCreated = freezed, - Object packageVersionCreated = freezed, - Object grantedPubPoints = freezed, - Object maxPubPoints = freezed, - Object popularityScore = freezed, - Object derivedTags = freezed, - Object flags = freezed, - Object reportTypes = freezed, + Object? packageName = freezed, + Object? packageVersion = freezed, + Object? runtimeVersion = freezed, + Object? updated = freezed, + Object? packageCreated = freezed, + Object? packageVersionCreated = freezed, + Object? grantedPubPoints = freezed, + Object? maxPubPoints = freezed, + Object? popularityScore = freezed, + Object? derivedTags = freezed, + Object? flags = freezed, + Object? reportTypes = freezed, }) { return _then(_value.copyWith( - packageName: - packageName == freezed ? _value.packageName : packageName as String, + packageName: packageName == freezed + ? _value.packageName + : packageName // ignore: cast_nullable_to_non_nullable + as String, packageVersion: packageVersion == freezed ? _value.packageVersion - : packageVersion as String, + : packageVersion // ignore: cast_nullable_to_non_nullable + as String, runtimeVersion: runtimeVersion == freezed ? _value.runtimeVersion - : runtimeVersion as String, - updated: updated == freezed ? _value.updated : updated as DateTime, + : runtimeVersion // ignore: cast_nullable_to_non_nullable + as String, + updated: updated == freezed + ? _value.updated + : updated // ignore: cast_nullable_to_non_nullable + as DateTime, packageCreated: packageCreated == freezed ? _value.packageCreated - : packageCreated as DateTime, + : packageCreated // ignore: cast_nullable_to_non_nullable + as DateTime, packageVersionCreated: packageVersionCreated == freezed ? _value.packageVersionCreated - : packageVersionCreated as DateTime, + : packageVersionCreated // ignore: cast_nullable_to_non_nullable + as DateTime, grantedPubPoints: grantedPubPoints == freezed ? _value.grantedPubPoints - : grantedPubPoints as int, - maxPubPoints: - maxPubPoints == freezed ? _value.maxPubPoints : maxPubPoints as int, + : grantedPubPoints // ignore: cast_nullable_to_non_nullable + as int, + maxPubPoints: maxPubPoints == freezed + ? _value.maxPubPoints + : maxPubPoints // ignore: cast_nullable_to_non_nullable + as int, popularityScore: popularityScore == freezed ? _value.popularityScore - : popularityScore as double, + : popularityScore // ignore: cast_nullable_to_non_nullable + as double, derivedTags: derivedTags == freezed ? _value.derivedTags - : derivedTags as List, - flags: flags == freezed ? _value.flags : flags as List, + : derivedTags // ignore: cast_nullable_to_non_nullable + as List, + flags: flags == freezed + ? _value.flags + : flags // ignore: cast_nullable_to_non_nullable + as List, reportTypes: reportTypes == freezed ? _value.reportTypes - : reportTypes as List, + : reportTypes // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -422,50 +465,68 @@ class __$PackageScoreCardCopyWithImpl<$Res> @override $Res call({ - Object packageName = freezed, - Object packageVersion = freezed, - Object runtimeVersion = freezed, - Object updated = freezed, - Object packageCreated = freezed, - Object packageVersionCreated = freezed, - Object grantedPubPoints = freezed, - Object maxPubPoints = freezed, - Object popularityScore = freezed, - Object derivedTags = freezed, - Object flags = freezed, - Object reportTypes = freezed, + Object? packageName = freezed, + Object? packageVersion = freezed, + Object? runtimeVersion = freezed, + Object? updated = freezed, + Object? packageCreated = freezed, + Object? packageVersionCreated = freezed, + Object? grantedPubPoints = freezed, + Object? maxPubPoints = freezed, + Object? popularityScore = freezed, + Object? derivedTags = freezed, + Object? flags = freezed, + Object? reportTypes = freezed, }) { return _then(_PackageScoreCard( - packageName: - packageName == freezed ? _value.packageName : packageName as String, + packageName: packageName == freezed + ? _value.packageName + : packageName // ignore: cast_nullable_to_non_nullable + as String, packageVersion: packageVersion == freezed ? _value.packageVersion - : packageVersion as String, + : packageVersion // ignore: cast_nullable_to_non_nullable + as String, runtimeVersion: runtimeVersion == freezed ? _value.runtimeVersion - : runtimeVersion as String, - updated: updated == freezed ? _value.updated : updated as DateTime, + : runtimeVersion // ignore: cast_nullable_to_non_nullable + as String, + updated: updated == freezed + ? _value.updated + : updated // ignore: cast_nullable_to_non_nullable + as DateTime, packageCreated: packageCreated == freezed ? _value.packageCreated - : packageCreated as DateTime, + : packageCreated // ignore: cast_nullable_to_non_nullable + as DateTime, packageVersionCreated: packageVersionCreated == freezed ? _value.packageVersionCreated - : packageVersionCreated as DateTime, + : packageVersionCreated // ignore: cast_nullable_to_non_nullable + as DateTime, grantedPubPoints: grantedPubPoints == freezed ? _value.grantedPubPoints - : grantedPubPoints as int, - maxPubPoints: - maxPubPoints == freezed ? _value.maxPubPoints : maxPubPoints as int, + : grantedPubPoints // ignore: cast_nullable_to_non_nullable + as int, + maxPubPoints: maxPubPoints == freezed + ? _value.maxPubPoints + : maxPubPoints // ignore: cast_nullable_to_non_nullable + as int, popularityScore: popularityScore == freezed ? _value.popularityScore - : popularityScore as double, + : popularityScore // ignore: cast_nullable_to_non_nullable + as double, derivedTags: derivedTags == freezed ? _value.derivedTags - : derivedTags as List, - flags: flags == freezed ? _value.flags : flags as List, + : derivedTags // ignore: cast_nullable_to_non_nullable + as List, + flags: flags == freezed + ? _value.flags + : flags // ignore: cast_nullable_to_non_nullable + as List, reportTypes: reportTypes == freezed ? _value.reportTypes - : reportTypes as List, + : reportTypes // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -475,18 +536,18 @@ class __$PackageScoreCardCopyWithImpl<$Res> /// @nodoc class _$_PackageScoreCard implements _PackageScoreCard { _$_PackageScoreCard( - {this.packageName, - this.packageVersion, - this.runtimeVersion, - this.updated, - this.packageCreated, - this.packageVersionCreated, - this.grantedPubPoints, - this.maxPubPoints, - this.popularityScore, - this.derivedTags, - this.flags, - this.reportTypes}); + {required this.packageName, + required this.packageVersion, + required this.runtimeVersion, + required this.updated, + required this.packageCreated, + required this.packageVersionCreated, + required this.grantedPubPoints, + required this.maxPubPoints, + required this.popularityScore, + this.derivedTags = const [], + this.flags = const [], + this.reportTypes = const []}); factory _$_PackageScoreCard.fromJson(Map json) => _$_$_PackageScoreCardFromJson(json); @@ -509,10 +570,13 @@ class _$_PackageScoreCard implements _PackageScoreCard { final int maxPubPoints; @override final double popularityScore; + @JsonKey(defaultValue: const []) @override final List derivedTags; + @JsonKey(defaultValue: const []) @override final List flags; + @JsonKey(defaultValue: const []) @override final List reportTypes; @@ -578,6 +642,7 @@ class _$_PackageScoreCard implements _PackageScoreCard { const DeepCollectionEquality().hash(flags) ^ const DeepCollectionEquality().hash(reportTypes); + @JsonKey(ignore: true) @override _$PackageScoreCardCopyWith<_PackageScoreCard> get copyWith => __$PackageScoreCardCopyWithImpl<_PackageScoreCard>(this, _$identity); @@ -590,15 +655,15 @@ class _$_PackageScoreCard implements _PackageScoreCard { abstract class _PackageScoreCard implements PackageScoreCard { factory _PackageScoreCard( - {String packageName, - String packageVersion, - String runtimeVersion, - DateTime updated, - DateTime packageCreated, - DateTime packageVersionCreated, - int grantedPubPoints, - int maxPubPoints, - double popularityScore, + {required String packageName, + required String packageVersion, + required String runtimeVersion, + required DateTime updated, + required DateTime packageCreated, + required DateTime packageVersionCreated, + required int grantedPubPoints, + required int maxPubPoints, + required double popularityScore, List derivedTags, List flags, List reportTypes}) = _$_PackageScoreCard; @@ -607,29 +672,31 @@ abstract class _PackageScoreCard implements PackageScoreCard { _$_PackageScoreCard.fromJson; @override - String get packageName; + String get packageName => throw _privateConstructorUsedError; @override - String get packageVersion; + String get packageVersion => throw _privateConstructorUsedError; @override - String get runtimeVersion; + String get runtimeVersion => throw _privateConstructorUsedError; @override - DateTime get updated; + DateTime get updated => throw _privateConstructorUsedError; @override - DateTime get packageCreated; + DateTime get packageCreated => throw _privateConstructorUsedError; @override - DateTime get packageVersionCreated; + DateTime get packageVersionCreated => throw _privateConstructorUsedError; @override - int get grantedPubPoints; + int get grantedPubPoints => throw _privateConstructorUsedError; @override - int get maxPubPoints; + int get maxPubPoints => throw _privateConstructorUsedError; @override - double get popularityScore; + double get popularityScore => throw _privateConstructorUsedError; @override - List get derivedTags; + List get derivedTags => throw _privateConstructorUsedError; @override - List get flags; + List get flags => throw _privateConstructorUsedError; @override - List get reportTypes; + List get reportTypes => throw _privateConstructorUsedError; @override - _$PackageScoreCardCopyWith<_PackageScoreCard> get copyWith; + @JsonKey(ignore: true) + _$PackageScoreCardCopyWith<_PackageScoreCard> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/package_score_model.g.dart b/lib/src/models/package_score_model.g.dart index e5a4d02..6c6d570 100644 --- a/lib/src/models/package_score_model.g.dart +++ b/lib/src/models/package_score_model.g.dart @@ -11,10 +11,8 @@ _$_PackageScore _$_$_PackageScoreFromJson(Map json) { grantedPoints: json['grantedPoints'] as int, maxPoints: json['maxPoints'] as int, likeCount: json['likeCount'] as int, - popularityScore: (json['popularityScore'] as num)?.toDouble(), - lastUpdated: json['lastUpdated'] == null - ? null - : DateTime.parse(json['lastUpdated'] as String), + popularityScore: (json['popularityScore'] as num).toDouble(), + lastUpdated: DateTime.parse(json['lastUpdated'] as String), ); } @@ -24,7 +22,7 @@ Map _$_$_PackageScoreToJson(_$_PackageScore instance) => 'maxPoints': instance.maxPoints, 'likeCount': instance.likeCount, 'popularityScore': instance.popularityScore, - 'lastUpdated': instance.lastUpdated?.toIso8601String(), + 'lastUpdated': instance.lastUpdated.toIso8601String(), }; _$_PackageScoreCard _$_$_PackageScoreCardFromJson(Map json) { @@ -32,23 +30,24 @@ _$_PackageScoreCard _$_$_PackageScoreCardFromJson(Map json) { packageName: json['packageName'] as String, packageVersion: json['packageVersion'] as String, runtimeVersion: json['runtimeVersion'] as String, - updated: json['updated'] == null - ? null - : DateTime.parse(json['updated'] as String), - packageCreated: json['packageCreated'] == null - ? null - : DateTime.parse(json['packageCreated'] as String), - packageVersionCreated: json['packageVersionCreated'] == null - ? null - : DateTime.parse(json['packageVersionCreated'] as String), + updated: DateTime.parse(json['updated'] as String), + packageCreated: DateTime.parse(json['packageCreated'] as String), + packageVersionCreated: + DateTime.parse(json['packageVersionCreated'] as String), grantedPubPoints: json['grantedPubPoints'] as int, maxPubPoints: json['maxPubPoints'] as int, - popularityScore: (json['popularityScore'] as num)?.toDouble(), - derivedTags: - (json['derivedTags'] as List)?.map((e) => e as String)?.toList(), - flags: (json['flags'] as List)?.map((e) => e as String)?.toList(), - reportTypes: - (json['reportTypes'] as List)?.map((e) => e as String)?.toList(), + popularityScore: (json['popularityScore'] as num).toDouble(), + derivedTags: (json['derivedTags'] as List?) + ?.map((e) => e as String) + .toList() ?? + [], + flags: + (json['flags'] as List?)?.map((e) => e as String).toList() ?? + [], + reportTypes: (json['reportTypes'] as List?) + ?.map((e) => e as String) + .toList() ?? + [], ); } @@ -58,10 +57,9 @@ Map _$_$_PackageScoreCardToJson( 'packageName': instance.packageName, 'packageVersion': instance.packageVersion, 'runtimeVersion': instance.runtimeVersion, - 'updated': instance.updated?.toIso8601String(), - 'packageCreated': instance.packageCreated?.toIso8601String(), - 'packageVersionCreated': - instance.packageVersionCreated?.toIso8601String(), + 'updated': instance.updated.toIso8601String(), + 'packageCreated': instance.packageCreated.toIso8601String(), + 'packageVersionCreated': instance.packageVersionCreated.toIso8601String(), 'grantedPubPoints': instance.grantedPubPoints, 'maxPubPoints': instance.maxPubPoints, 'popularityScore': instance.popularityScore, diff --git a/lib/src/models/pub_credentials_model.dart b/lib/src/models/pub_credentials_model.dart index ff3baef..003e26d 100644 --- a/lib/src/models/pub_credentials_model.dart +++ b/lib/src/models/pub_credentials_model.dart @@ -7,12 +7,12 @@ part 'pub_credentials_model.g.dart'; @freezed abstract class PubCredentials with _$PubCredentials { factory PubCredentials({ - final String accessToken, - final String refreshToken, - final String idToken, - final double tokenEndpoint, - final List scopes, - final int expiration, + required final String accessToken, + required final String refreshToken, + required final String idToken, + required final double tokenEndpoint, + required final List scopes, + required final int expiration, }) = _PubCredentials; factory PubCredentials.fromJson(Map json) => diff --git a/lib/src/models/pub_credentials_model.freezed.dart b/lib/src/models/pub_credentials_model.freezed.dart index c809519..2653be1 100644 --- a/lib/src/models/pub_credentials_model.freezed.dart +++ b/lib/src/models/pub_credentials_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'pub_credentials_model.dart'; @@ -8,6 +8,10 @@ part of 'pub_credentials_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PubCredentials _$PubCredentialsFromJson(Map json) { return _PubCredentials.fromJson(json); } @@ -16,14 +20,13 @@ PubCredentials _$PubCredentialsFromJson(Map json) { class _$PubCredentialsTearOff { const _$PubCredentialsTearOff(); -// ignore: unused_element _PubCredentials call( - {String accessToken, - String refreshToken, - String idToken, - double tokenEndpoint, - List scopes, - int expiration}) { + {required String accessToken, + required String refreshToken, + required String idToken, + required double tokenEndpoint, + required List scopes, + required int expiration}) { return _PubCredentials( accessToken: accessToken, refreshToken: refreshToken, @@ -34,27 +37,27 @@ class _$PubCredentialsTearOff { ); } -// ignore: unused_element PubCredentials fromJson(Map json) { return PubCredentials.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PubCredentials = _$PubCredentialsTearOff(); /// @nodoc mixin _$PubCredentials { - String get accessToken; - String get refreshToken; - String get idToken; - double get tokenEndpoint; - List get scopes; - int get expiration; + String get accessToken => throw _privateConstructorUsedError; + String get refreshToken => throw _privateConstructorUsedError; + String get idToken => throw _privateConstructorUsedError; + double get tokenEndpoint => throw _privateConstructorUsedError; + List get scopes => throw _privateConstructorUsedError; + int get expiration => throw _privateConstructorUsedError; - Map toJson(); - $PubCredentialsCopyWith get copyWith; + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PubCredentialsCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -82,25 +85,38 @@ class _$PubCredentialsCopyWithImpl<$Res> @override $Res call({ - Object accessToken = freezed, - Object refreshToken = freezed, - Object idToken = freezed, - Object tokenEndpoint = freezed, - Object scopes = freezed, - Object expiration = freezed, + Object? accessToken = freezed, + Object? refreshToken = freezed, + Object? idToken = freezed, + Object? tokenEndpoint = freezed, + Object? scopes = freezed, + Object? expiration = freezed, }) { return _then(_value.copyWith( - accessToken: - accessToken == freezed ? _value.accessToken : accessToken as String, + accessToken: accessToken == freezed + ? _value.accessToken + : accessToken // ignore: cast_nullable_to_non_nullable + as String, refreshToken: refreshToken == freezed ? _value.refreshToken - : refreshToken as String, - idToken: idToken == freezed ? _value.idToken : idToken as String, + : refreshToken // ignore: cast_nullable_to_non_nullable + as String, + idToken: idToken == freezed + ? _value.idToken + : idToken // ignore: cast_nullable_to_non_nullable + as String, tokenEndpoint: tokenEndpoint == freezed ? _value.tokenEndpoint - : tokenEndpoint as double, - scopes: scopes == freezed ? _value.scopes : scopes as List, - expiration: expiration == freezed ? _value.expiration : expiration as int, + : tokenEndpoint // ignore: cast_nullable_to_non_nullable + as double, + scopes: scopes == freezed + ? _value.scopes + : scopes // ignore: cast_nullable_to_non_nullable + as List, + expiration: expiration == freezed + ? _value.expiration + : expiration // ignore: cast_nullable_to_non_nullable + as int, )); } } @@ -134,25 +150,38 @@ class __$PubCredentialsCopyWithImpl<$Res> @override $Res call({ - Object accessToken = freezed, - Object refreshToken = freezed, - Object idToken = freezed, - Object tokenEndpoint = freezed, - Object scopes = freezed, - Object expiration = freezed, + Object? accessToken = freezed, + Object? refreshToken = freezed, + Object? idToken = freezed, + Object? tokenEndpoint = freezed, + Object? scopes = freezed, + Object? expiration = freezed, }) { return _then(_PubCredentials( - accessToken: - accessToken == freezed ? _value.accessToken : accessToken as String, + accessToken: accessToken == freezed + ? _value.accessToken + : accessToken // ignore: cast_nullable_to_non_nullable + as String, refreshToken: refreshToken == freezed ? _value.refreshToken - : refreshToken as String, - idToken: idToken == freezed ? _value.idToken : idToken as String, + : refreshToken // ignore: cast_nullable_to_non_nullable + as String, + idToken: idToken == freezed + ? _value.idToken + : idToken // ignore: cast_nullable_to_non_nullable + as String, tokenEndpoint: tokenEndpoint == freezed ? _value.tokenEndpoint - : tokenEndpoint as double, - scopes: scopes == freezed ? _value.scopes : scopes as List, - expiration: expiration == freezed ? _value.expiration : expiration as int, + : tokenEndpoint // ignore: cast_nullable_to_non_nullable + as double, + scopes: scopes == freezed + ? _value.scopes + : scopes // ignore: cast_nullable_to_non_nullable + as List, + expiration: expiration == freezed + ? _value.expiration + : expiration // ignore: cast_nullable_to_non_nullable + as int, )); } } @@ -162,12 +191,12 @@ class __$PubCredentialsCopyWithImpl<$Res> /// @nodoc class _$_PubCredentials implements _PubCredentials { _$_PubCredentials( - {this.accessToken, - this.refreshToken, - this.idToken, - this.tokenEndpoint, - this.scopes, - this.expiration}); + {required this.accessToken, + required this.refreshToken, + required this.idToken, + required this.tokenEndpoint, + required this.scopes, + required this.expiration}); factory _$_PubCredentials.fromJson(Map json) => _$_$_PubCredentialsFromJson(json); @@ -223,6 +252,7 @@ class _$_PubCredentials implements _PubCredentials { const DeepCollectionEquality().hash(scopes) ^ const DeepCollectionEquality().hash(expiration); + @JsonKey(ignore: true) @override _$PubCredentialsCopyWith<_PubCredentials> get copyWith => __$PubCredentialsCopyWithImpl<_PubCredentials>(this, _$identity); @@ -235,28 +265,30 @@ class _$_PubCredentials implements _PubCredentials { abstract class _PubCredentials implements PubCredentials { factory _PubCredentials( - {String accessToken, - String refreshToken, - String idToken, - double tokenEndpoint, - List scopes, - int expiration}) = _$_PubCredentials; + {required String accessToken, + required String refreshToken, + required String idToken, + required double tokenEndpoint, + required List scopes, + required int expiration}) = _$_PubCredentials; factory _PubCredentials.fromJson(Map json) = _$_PubCredentials.fromJson; @override - String get accessToken; + String get accessToken => throw _privateConstructorUsedError; @override - String get refreshToken; + String get refreshToken => throw _privateConstructorUsedError; @override - String get idToken; + String get idToken => throw _privateConstructorUsedError; @override - double get tokenEndpoint; + double get tokenEndpoint => throw _privateConstructorUsedError; @override - List get scopes; + List get scopes => throw _privateConstructorUsedError; @override - int get expiration; + int get expiration => throw _privateConstructorUsedError; @override - _$PubCredentialsCopyWith<_PubCredentials> get copyWith; + @JsonKey(ignore: true) + _$PubCredentialsCopyWith<_PubCredentials> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/pub_credentials_model.g.dart b/lib/src/models/pub_credentials_model.g.dart index b7e31ef..d55697a 100644 --- a/lib/src/models/pub_credentials_model.g.dart +++ b/lib/src/models/pub_credentials_model.g.dart @@ -11,8 +11,8 @@ _$_PubCredentials _$_$_PubCredentialsFromJson(Map json) { accessToken: json['accessToken'] as String, refreshToken: json['refreshToken'] as String, idToken: json['idToken'] as String, - tokenEndpoint: (json['tokenEndpoint'] as num)?.toDouble(), - scopes: (json['scopes'] as List)?.map((e) => e as String)?.toList(), + tokenEndpoint: (json['tokenEndpoint'] as num).toDouble(), + scopes: (json['scopes'] as List).map((e) => e as String).toList(), expiration: json['expiration'] as int, ); } diff --git a/lib/src/models/pub_package_model.dart b/lib/src/models/pub_package_model.dart index d80290a..794caa4 100644 --- a/lib/src/models/pub_package_model.dart +++ b/lib/src/models/pub_package_model.dart @@ -11,16 +11,16 @@ abstract class PubPackage implements _$PubPackage { const PubPackage._(); factory PubPackage({ - String name, - PackageVersion latest, - List versions, + required String name, + required PackageVersion latest, + @Default([]) List versions, }) = _PubPackage; factory PubPackage.fromJson(Map json) => _$PubPackageFromJson(json); String get version => latestPubspec.version.toString(); - String get description => latestPubspec.description; + String get description => latestPubspec.description ?? ''; String get url => 'https://pub.dev/packages/$name'; String get changelogUrl => '$url/changelog'; Pubspec get latestPubspec => latest.pubspec; @@ -31,10 +31,10 @@ abstract class PubPackage implements _$PubPackage { abstract class PackageVersion with _$PackageVersion { @JsonSerializable(fieldRename: FieldRename.snake) factory PackageVersion({ - String version, - Pubspec pubspec, - String archiveUrl, - DateTime published, + required String version, + required Pubspec pubspec, + required String archiveUrl, + required DateTime published, }) = _PackageVersion; factory PackageVersion.fromJson(Map json) => diff --git a/lib/src/models/pub_package_model.freezed.dart b/lib/src/models/pub_package_model.freezed.dart index c3237a5..c08cef0 100644 --- a/lib/src/models/pub_package_model.freezed.dart +++ b/lib/src/models/pub_package_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'pub_package_model.dart'; @@ -8,6 +8,10 @@ part of 'pub_package_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + PubPackage _$PubPackageFromJson(Map json) { return _PubPackage.fromJson(json); } @@ -16,9 +20,10 @@ PubPackage _$PubPackageFromJson(Map json) { class _$PubPackageTearOff { const _$PubPackageTearOff(); -// ignore: unused_element _PubPackage call( - {String name, PackageVersion latest, List versions}) { + {required String name, + required PackageVersion latest, + List versions = const []}) { return _PubPackage( name: name, latest: latest, @@ -26,24 +31,24 @@ class _$PubPackageTearOff { ); } -// ignore: unused_element PubPackage fromJson(Map json) { return PubPackage.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PubPackage = _$PubPackageTearOff(); /// @nodoc mixin _$PubPackage { - String get name; - PackageVersion get latest; - List get versions; - - Map toJson(); - $PubPackageCopyWith get copyWith; + String get name => throw _privateConstructorUsedError; + PackageVersion get latest => throw _privateConstructorUsedError; + List get versions => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PubPackageCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -67,24 +72,28 @@ class _$PubPackageCopyWithImpl<$Res> implements $PubPackageCopyWith<$Res> { @override $Res call({ - Object name = freezed, - Object latest = freezed, - Object versions = freezed, + Object? name = freezed, + Object? latest = freezed, + Object? versions = freezed, }) { return _then(_value.copyWith( - name: name == freezed ? _value.name : name as String, - latest: latest == freezed ? _value.latest : latest as PackageVersion, + name: name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + latest: latest == freezed + ? _value.latest + : latest // ignore: cast_nullable_to_non_nullable + as PackageVersion, versions: versions == freezed ? _value.versions - : versions as List, + : versions // ignore: cast_nullable_to_non_nullable + as List, )); } @override $PackageVersionCopyWith<$Res> get latest { - if (_value.latest == null) { - return null; - } return $PackageVersionCopyWith<$Res>(_value.latest, (value) { return _then(_value.copyWith(latest: value)); }); @@ -116,16 +125,23 @@ class __$PubPackageCopyWithImpl<$Res> extends _$PubPackageCopyWithImpl<$Res> @override $Res call({ - Object name = freezed, - Object latest = freezed, - Object versions = freezed, + Object? name = freezed, + Object? latest = freezed, + Object? versions = freezed, }) { return _then(_PubPackage( - name: name == freezed ? _value.name : name as String, - latest: latest == freezed ? _value.latest : latest as PackageVersion, + name: name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + latest: latest == freezed + ? _value.latest + : latest // ignore: cast_nullable_to_non_nullable + as PackageVersion, versions: versions == freezed ? _value.versions - : versions as List, + : versions // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -134,7 +150,9 @@ class __$PubPackageCopyWithImpl<$Res> extends _$PubPackageCopyWithImpl<$Res> /// @nodoc class _$_PubPackage extends _PubPackage { - _$_PubPackage({this.name, this.latest, this.versions}) : super._(); + _$_PubPackage( + {required this.name, required this.latest, this.versions = const []}) + : super._(); factory _$_PubPackage.fromJson(Map json) => _$_$_PubPackageFromJson(json); @@ -143,6 +161,7 @@ class _$_PubPackage extends _PubPackage { final String name; @override final PackageVersion latest; + @JsonKey(defaultValue: const []) @override final List versions; @@ -171,6 +190,7 @@ class _$_PubPackage extends _PubPackage { const DeepCollectionEquality().hash(latest) ^ const DeepCollectionEquality().hash(versions); + @JsonKey(ignore: true) @override _$PubPackageCopyWith<_PubPackage> get copyWith => __$PubPackageCopyWithImpl<_PubPackage>(this, _$identity); @@ -182,23 +202,25 @@ class _$_PubPackage extends _PubPackage { } abstract class _PubPackage extends PubPackage { - _PubPackage._() : super._(); factory _PubPackage( - {String name, - PackageVersion latest, + {required String name, + required PackageVersion latest, List versions}) = _$_PubPackage; + _PubPackage._() : super._(); factory _PubPackage.fromJson(Map json) = _$_PubPackage.fromJson; @override - String get name; + String get name => throw _privateConstructorUsedError; @override - PackageVersion get latest; + PackageVersion get latest => throw _privateConstructorUsedError; @override - List get versions; + List get versions => throw _privateConstructorUsedError; @override - _$PubPackageCopyWith<_PubPackage> get copyWith; + @JsonKey(ignore: true) + _$PubPackageCopyWith<_PubPackage> get copyWith => + throw _privateConstructorUsedError; } PackageVersion _$PackageVersionFromJson(Map json) { @@ -209,12 +231,11 @@ PackageVersion _$PackageVersionFromJson(Map json) { class _$PackageVersionTearOff { const _$PackageVersionTearOff(); -// ignore: unused_element _PackageVersion call( - {String version, - Pubspec pubspec, - String archiveUrl, - DateTime published}) { + {required String version, + required Pubspec pubspec, + required String archiveUrl, + required DateTime published}) { return _PackageVersion( version: version, pubspec: pubspec, @@ -223,25 +244,25 @@ class _$PackageVersionTearOff { ); } -// ignore: unused_element PackageVersion fromJson(Map json) { return PackageVersion.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageVersion = _$PackageVersionTearOff(); /// @nodoc mixin _$PackageVersion { - String get version; - Pubspec get pubspec; - String get archiveUrl; - DateTime get published; - - Map toJson(); - $PackageVersionCopyWith get copyWith; + String get version => throw _privateConstructorUsedError; + Pubspec get pubspec => throw _privateConstructorUsedError; + String get archiveUrl => throw _privateConstructorUsedError; + DateTime get published => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageVersionCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -264,18 +285,28 @@ class _$PackageVersionCopyWithImpl<$Res> @override $Res call({ - Object version = freezed, - Object pubspec = freezed, - Object archiveUrl = freezed, - Object published = freezed, + Object? version = freezed, + Object? pubspec = freezed, + Object? archiveUrl = freezed, + Object? published = freezed, }) { return _then(_value.copyWith( - version: version == freezed ? _value.version : version as String, - pubspec: pubspec == freezed ? _value.pubspec : pubspec as Pubspec, - archiveUrl: - archiveUrl == freezed ? _value.archiveUrl : archiveUrl as String, - published: - published == freezed ? _value.published : published as DateTime, + version: version == freezed + ? _value.version + : version // ignore: cast_nullable_to_non_nullable + as String, + pubspec: pubspec == freezed + ? _value.pubspec + : pubspec // ignore: cast_nullable_to_non_nullable + as Pubspec, + archiveUrl: archiveUrl == freezed + ? _value.archiveUrl + : archiveUrl // ignore: cast_nullable_to_non_nullable + as String, + published: published == freezed + ? _value.published + : published // ignore: cast_nullable_to_non_nullable + as DateTime, )); } } @@ -304,18 +335,28 @@ class __$PackageVersionCopyWithImpl<$Res> @override $Res call({ - Object version = freezed, - Object pubspec = freezed, - Object archiveUrl = freezed, - Object published = freezed, + Object? version = freezed, + Object? pubspec = freezed, + Object? archiveUrl = freezed, + Object? published = freezed, }) { return _then(_PackageVersion( - version: version == freezed ? _value.version : version as String, - pubspec: pubspec == freezed ? _value.pubspec : pubspec as Pubspec, - archiveUrl: - archiveUrl == freezed ? _value.archiveUrl : archiveUrl as String, - published: - published == freezed ? _value.published : published as DateTime, + version: version == freezed + ? _value.version + : version // ignore: cast_nullable_to_non_nullable + as String, + pubspec: pubspec == freezed + ? _value.pubspec + : pubspec // ignore: cast_nullable_to_non_nullable + as Pubspec, + archiveUrl: archiveUrl == freezed + ? _value.archiveUrl + : archiveUrl // ignore: cast_nullable_to_non_nullable + as String, + published: published == freezed + ? _value.published + : published // ignore: cast_nullable_to_non_nullable + as DateTime, )); } } @@ -325,7 +366,10 @@ class __$PackageVersionCopyWithImpl<$Res> /// @nodoc class _$_PackageVersion implements _PackageVersion { _$_PackageVersion( - {this.version, this.pubspec, this.archiveUrl, this.published}); + {required this.version, + required this.pubspec, + required this.archiveUrl, + required this.published}); factory _$_PackageVersion.fromJson(Map json) => _$_$_PackageVersionFromJson(json); @@ -370,6 +414,7 @@ class _$_PackageVersion implements _PackageVersion { const DeepCollectionEquality().hash(archiveUrl) ^ const DeepCollectionEquality().hash(published); + @JsonKey(ignore: true) @override _$PackageVersionCopyWith<_PackageVersion> get copyWith => __$PackageVersionCopyWithImpl<_PackageVersion>(this, _$identity); @@ -382,22 +427,24 @@ class _$_PackageVersion implements _PackageVersion { abstract class _PackageVersion implements PackageVersion { factory _PackageVersion( - {String version, - Pubspec pubspec, - String archiveUrl, - DateTime published}) = _$_PackageVersion; + {required String version, + required Pubspec pubspec, + required String archiveUrl, + required DateTime published}) = _$_PackageVersion; factory _PackageVersion.fromJson(Map json) = _$_PackageVersion.fromJson; @override - String get version; + String get version => throw _privateConstructorUsedError; @override - Pubspec get pubspec; + Pubspec get pubspec => throw _privateConstructorUsedError; @override - String get archiveUrl; + String get archiveUrl => throw _privateConstructorUsedError; @override - DateTime get published; + DateTime get published => throw _privateConstructorUsedError; @override - _$PackageVersionCopyWith<_PackageVersion> get copyWith; + @JsonKey(ignore: true) + _$PackageVersionCopyWith<_PackageVersion> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/pub_package_model.g.dart b/lib/src/models/pub_package_model.g.dart index 10ca849..0a1b93a 100644 --- a/lib/src/models/pub_package_model.g.dart +++ b/lib/src/models/pub_package_model.g.dart @@ -9,14 +9,11 @@ part of 'pub_package_model.dart'; _$_PubPackage _$_$_PubPackageFromJson(Map json) { return _$_PubPackage( name: json['name'] as String, - latest: json['latest'] == null - ? null - : PackageVersion.fromJson(json['latest'] as Map), - versions: (json['versions'] as List) - ?.map((e) => e == null - ? null - : PackageVersion.fromJson(e as Map)) - ?.toList(), + latest: PackageVersion.fromJson(json['latest'] as Map), + versions: (json['versions'] as List?) + ?.map((e) => PackageVersion.fromJson(e as Map)) + .toList() ?? + [], ); } @@ -30,13 +27,9 @@ Map _$_$_PubPackageToJson(_$_PubPackage instance) => _$_PackageVersion _$_$_PackageVersionFromJson(Map json) { return _$_PackageVersion( version: json['version'] as String, - pubspec: json['pubspec'] == null - ? null - : Pubspec.fromJson(json['pubspec'] as Map), + pubspec: Pubspec.fromJson(json['pubspec'] as Map), archiveUrl: json['archive_url'] as String, - published: json['published'] == null - ? null - : DateTime.parse(json['published'] as String), + published: DateTime.parse(json['published'] as String), ); } @@ -45,5 +38,5 @@ Map _$_$_PackageVersionToJson(_$_PackageVersion instance) => 'version': instance.version, 'pubspec': instance.pubspec, 'archive_url': instance.archiveUrl, - 'published': instance.published?.toIso8601String(), + 'published': instance.published.toIso8601String(), }; diff --git a/lib/src/models/search_results_model.dart b/lib/src/models/search_results_model.dart index 2c685b0..9761e40 100644 --- a/lib/src/models/search_results_model.dart +++ b/lib/src/models/search_results_model.dart @@ -1,7 +1,4 @@ -import 'dart:convert'; - import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:http/http.dart' as http; part 'search_results_model.freezed.dart'; part 'search_results_model.g.dart'; @@ -11,24 +8,18 @@ part 'search_results_model.g.dart'; abstract class SearchResults implements _$SearchResults { const SearchResults._(); factory SearchResults({ - final List packages, - String next, + required final List packages, + final String? next, }) = _SearchResults; factory SearchResults.fromJson(Map json) => _$SearchResultsFromJson(json); - - Future nextResults() async { - final response = await http.get(next); - return SearchResults.fromJson( - jsonDecode(response.body) as Map); - } } /// Package Result Model returns within a `SearchResult` @freezed -abstract class PackageResult with _$PackageResult { - factory PackageResult({String package}) = _PackageResult; +class PackageResult with _$PackageResult { + factory PackageResult({required String package}) = _PackageResult; factory PackageResult.fromJson(Map json) => _$PackageResultFromJson(json); diff --git a/lib/src/models/search_results_model.freezed.dart b/lib/src/models/search_results_model.freezed.dart index 3d418b9..72c4408 100644 --- a/lib/src/models/search_results_model.freezed.dart +++ b/lib/src/models/search_results_model.freezed.dart @@ -1,5 +1,5 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides part of 'search_results_model.dart'; @@ -8,6 +8,10 @@ part of 'search_results_model.dart'; // ************************************************************************** T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + SearchResults _$SearchResultsFromJson(Map json) { return _SearchResults.fromJson(json); } @@ -16,31 +20,30 @@ SearchResults _$SearchResultsFromJson(Map json) { class _$SearchResultsTearOff { const _$SearchResultsTearOff(); -// ignore: unused_element - _SearchResults call({List packages, String next}) { + _SearchResults call({required List packages, String? next}) { return _SearchResults( packages: packages, next: next, ); } -// ignore: unused_element SearchResults fromJson(Map json) { return SearchResults.fromJson(json); } } /// @nodoc -// ignore: unused_element const $SearchResults = _$SearchResultsTearOff(); /// @nodoc mixin _$SearchResults { - List get packages; - String get next; + List get packages => throw _privateConstructorUsedError; + String? get next => throw _privateConstructorUsedError; - Map toJson(); - $SearchResultsCopyWith get copyWith; + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SearchResultsCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -48,7 +51,7 @@ abstract class $SearchResultsCopyWith<$Res> { factory $SearchResultsCopyWith( SearchResults value, $Res Function(SearchResults) then) = _$SearchResultsCopyWithImpl<$Res>; - $Res call({List packages, String next}); + $Res call({List packages, String? next}); } /// @nodoc @@ -62,14 +65,18 @@ class _$SearchResultsCopyWithImpl<$Res> @override $Res call({ - Object packages = freezed, - Object next = freezed, + Object? packages = freezed, + Object? next = freezed, }) { return _then(_value.copyWith( packages: packages == freezed ? _value.packages - : packages as List, - next: next == freezed ? _value.next : next as String, + : packages // ignore: cast_nullable_to_non_nullable + as List, + next: next == freezed + ? _value.next + : next // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -81,7 +88,7 @@ abstract class _$SearchResultsCopyWith<$Res> _SearchResults value, $Res Function(_SearchResults) then) = __$SearchResultsCopyWithImpl<$Res>; @override - $Res call({List packages, String next}); + $Res call({List packages, String? next}); } /// @nodoc @@ -97,14 +104,18 @@ class __$SearchResultsCopyWithImpl<$Res> @override $Res call({ - Object packages = freezed, - Object next = freezed, + Object? packages = freezed, + Object? next = freezed, }) { return _then(_SearchResults( packages: packages == freezed ? _value.packages - : packages as List, - next: next == freezed ? _value.next : next as String, + : packages // ignore: cast_nullable_to_non_nullable + as List, + next: next == freezed + ? _value.next + : next // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -113,7 +124,7 @@ class __$SearchResultsCopyWithImpl<$Res> /// @nodoc class _$_SearchResults extends _SearchResults { - _$_SearchResults({this.packages, this.next}) : super._(); + _$_SearchResults({required this.packages, this.next}) : super._(); factory _$_SearchResults.fromJson(Map json) => _$_$_SearchResultsFromJson(json); @@ -121,7 +132,7 @@ class _$_SearchResults extends _SearchResults { @override final List packages; @override - final String next; + final String? next; @override String toString() { @@ -145,6 +156,7 @@ class _$_SearchResults extends _SearchResults { const DeepCollectionEquality().hash(packages) ^ const DeepCollectionEquality().hash(next); + @JsonKey(ignore: true) @override _$SearchResultsCopyWith<_SearchResults> get copyWith => __$SearchResultsCopyWithImpl<_SearchResults>(this, _$identity); @@ -156,19 +168,21 @@ class _$_SearchResults extends _SearchResults { } abstract class _SearchResults extends SearchResults { + factory _SearchResults( + {required List packages, String? next}) = _$_SearchResults; _SearchResults._() : super._(); - factory _SearchResults({List packages, String next}) = - _$_SearchResults; factory _SearchResults.fromJson(Map json) = _$_SearchResults.fromJson; @override - List get packages; + List get packages => throw _privateConstructorUsedError; @override - String get next; + String? get next => throw _privateConstructorUsedError; @override - _$SearchResultsCopyWith<_SearchResults> get copyWith; + @JsonKey(ignore: true) + _$SearchResultsCopyWith<_SearchResults> get copyWith => + throw _privateConstructorUsedError; } PackageResult _$PackageResultFromJson(Map json) { @@ -179,29 +193,28 @@ PackageResult _$PackageResultFromJson(Map json) { class _$PackageResultTearOff { const _$PackageResultTearOff(); -// ignore: unused_element - _PackageResult call({String package}) { + _PackageResult call({required String package}) { return _PackageResult( package: package, ); } -// ignore: unused_element PackageResult fromJson(Map json) { return PackageResult.fromJson(json); } } /// @nodoc -// ignore: unused_element const $PackageResult = _$PackageResultTearOff(); /// @nodoc mixin _$PackageResult { - String get package; + String get package => throw _privateConstructorUsedError; - Map toJson(); - $PackageResultCopyWith get copyWith; + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $PackageResultCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc @@ -223,10 +236,13 @@ class _$PackageResultCopyWithImpl<$Res> @override $Res call({ - Object package = freezed, + Object? package = freezed, }) { return _then(_value.copyWith( - package: package == freezed ? _value.package : package as String, + package: package == freezed + ? _value.package + : package // ignore: cast_nullable_to_non_nullable + as String, )); } } @@ -254,10 +270,13 @@ class __$PackageResultCopyWithImpl<$Res> @override $Res call({ - Object package = freezed, + Object? package = freezed, }) { return _then(_PackageResult( - package: package == freezed ? _value.package : package as String, + package: package == freezed + ? _value.package + : package // ignore: cast_nullable_to_non_nullable + as String, )); } } @@ -266,7 +285,7 @@ class __$PackageResultCopyWithImpl<$Res> /// @nodoc class _$_PackageResult implements _PackageResult { - _$_PackageResult({this.package}); + _$_PackageResult({required this.package}); factory _$_PackageResult.fromJson(Map json) => _$_$_PackageResultFromJson(json); @@ -291,6 +310,7 @@ class _$_PackageResult implements _PackageResult { int get hashCode => runtimeType.hashCode ^ const DeepCollectionEquality().hash(package); + @JsonKey(ignore: true) @override _$PackageResultCopyWith<_PackageResult> get copyWith => __$PackageResultCopyWithImpl<_PackageResult>(this, _$identity); @@ -302,13 +322,15 @@ class _$_PackageResult implements _PackageResult { } abstract class _PackageResult implements PackageResult { - factory _PackageResult({String package}) = _$_PackageResult; + factory _PackageResult({required String package}) = _$_PackageResult; factory _PackageResult.fromJson(Map json) = _$_PackageResult.fromJson; @override - String get package; + String get package => throw _privateConstructorUsedError; @override - _$PackageResultCopyWith<_PackageResult> get copyWith; + @JsonKey(ignore: true) + _$PackageResultCopyWith<_PackageResult> get copyWith => + throw _privateConstructorUsedError; } diff --git a/lib/src/models/search_results_model.g.dart b/lib/src/models/search_results_model.g.dart index b9a9713..5451b4e 100644 --- a/lib/src/models/search_results_model.g.dart +++ b/lib/src/models/search_results_model.g.dart @@ -8,12 +8,10 @@ part of 'search_results_model.dart'; _$_SearchResults _$_$_SearchResultsFromJson(Map json) { return _$_SearchResults( - packages: (json['packages'] as List) - ?.map((e) => e == null - ? null - : PackageResult.fromJson(e as Map)) - ?.toList(), - next: json['next'] as String, + packages: (json['packages'] as List) + .map((e) => PackageResult.fromJson(e as Map)) + .toList(), + next: json['next'] as String?, ); } diff --git a/lib/src/pub_api_client_base.dart b/lib/src/pub_api_client_base.dart index 9833bbc..a2f3966 100644 --- a/lib/src/pub_api_client_base.dart +++ b/lib/src/pub_api_client_base.dart @@ -6,6 +6,7 @@ import 'package:pub_semver/pub_semver.dart'; import 'endpoints.dart'; import 'helpers/http_client.dart'; import 'models/latest_version_model.dart'; + import 'models/package_documentation_model.dart'; import 'models/package_metrics_model.dart'; import 'models/package_options_model.dart'; @@ -19,12 +20,11 @@ typedef FetchFunction = Future> Function(String url); /// Pub API Client class PubClient { - final String pubUrl; - - final PubCredentials credentials; final Endpoint endpoint; - final Client client; - PubApiHttpClient _client; + final String? pubUrl; + final Client? client; + final PubCredentials? credentials; + late PubApiHttpClient _client; PubClient({ this.pubUrl, this.credentials, @@ -34,7 +34,7 @@ class PubClient { } Future> _fetch(String url) async { - final response = await _client.get(url); + final response = await _client.get(Uri.parse(url)); return jsonDecode(response.body) as Map; } @@ -59,6 +59,7 @@ class PubClient { /// Returns the `PackageOptions` for package [packageName] Future packageOptions(String packageName) async { final data = await _fetch(endpoint.packageOptions(packageName)); + return PackageOptions.fromJson(data); } @@ -93,8 +94,8 @@ class PubClient { Future search( String query, { int page = 1, - String publisher, - String dependency, + String? publisher, + String? dependency, }) async { final publisherQuery = publisher != null ? 'publisher:$publisher ' : ''; final dependencyQuery = dependency != null ? 'dependency:$dependency ' : ''; @@ -103,6 +104,15 @@ class PubClient { return SearchResults.fromJson(data); } + /// Receives [nextPageUrl] + /// returns `SearchResults` + Future nextPage(String nextPageUrl) async { + final data = await _fetch(nextPageUrl); + return SearchResults.fromJson(data); + } + + // Future _nextSearchPage() async {} + /// Returns `PackageDocumentation` for a [packageName] Future documentation(String packageName) async { final data = await _fetch(endpoint.packageDocumentation(packageName)); @@ -113,16 +123,15 @@ class PubClient { /// comparing with [currentVersion] returns `LatestVersion` Future checkLatest( String packageName, { - String currentVersion, + required String currentVersion, }) async { final package = await packageInfo(packageName); final latestVersion = Version.parse(package.version); var needUpdate = false; - if (currentVersion != null) { - final current = Version.parse(currentVersion); - // Check as need update if latest version is higher - needUpdate = latestVersion > current; - } + + final current = Version.parse(currentVersion); + // Check as need update if latest version is higher + needUpdate = latestVersion > current; return LatestVersion( needUpdate: needUpdate, diff --git a/pubspec.yaml b/pubspec.yaml index 0804ccf..f1d1096 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,23 +4,23 @@ version: 1.0.9 homepage: https://github.com/leoafarias/pub_api_client environment: - sdk: '>=2.8.1 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: - freezed_annotation: ^0.12.0 - http: ^0.12.2 - json_annotation: ^3.1.0 - meta: ^1.2.3 - pub_semver: ^1.4.4 - pubspec_parse: ^0.1.5 + pub_semver: ^2.0.0 + freezed_annotation: ^0.14.1 + http: ^0.13.1 + json_annotation: ^4.0.1 + pubspec: ^2.0.1 + + dev_dependencies: - build_runner: ^1.10.3 - build_version: ^2.0.1 - freezed: ^0.12.2 - json_serializable: ^3.5.0 - pedantic: ^1.9.2 - pubspec_yaml: ^2.0.1 - remove_from_coverage: ^1.0.7 - test: ^1.15.4 - test_coverage: ^0.4.3 + build_runner: ^1.12.2 + build_version: ^2.0.2 + freezed: ^0.14.1+1 + json_serializable: ^4.1.0 + pedantic: ^1.11.0 + + test: ^1.16.8 + test_cov: ^1.0.1 diff --git a/test/helpers_test.dart b/test/helpers_test.dart index 7208dd7..25d850e 100644 --- a/test/helpers_test.dart +++ b/test/helpers_test.dart @@ -1,12 +1,14 @@ import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:pub_api_client/pub_api_client.dart'; import 'package:pub_api_client/src/helpers/console_helper.dart'; + import 'package:pub_api_client/src/helpers/google_packages.dart'; import 'package:pub_api_client/src/helpers/google_packages_list.dart'; import 'package:pub_api_client/src/version.dart'; -import 'package:pubspec_yaml/pubspec_yaml.dart'; +import 'package:pubspec/pubspec.dart'; import 'package:test/test.dart'; @@ -36,23 +38,22 @@ dynamic Function() overridePrint(dynamic Function() testFn) => () { void main() { group('Helpers', () { test('Check Update Printer', overridePrint(() async { - await checkUpdatePrinter(packageName); + await checkUpdatePrinter(packageName, currentVersion: '10.0.0'); expect(printLog.isEmpty, true); await checkUpdatePrinter(packageName, currentVersion: '1.0.0'); expect(printLog.length, 2); })); - test('Get all Google packages', () async { final googleDeps = await getGooglePackages(); - // print(googleDeps); + print(jsonEncode(googleDeps)); expect(googleDeps.length, googlePackagesList.length); }); test('Does Package version match', () async { - final pubspec = File( + final pubspec = PubSpec.fromYamlString(File( '${Directory.current.path}/pubspec.yaml', - ).readAsStringSync().toPubspecYaml(); - expect(pubspec.version.valueOr(() => null), packageVersion); + ).readAsStringSync()); + expect(pubspec.version.toString(), packageVersion); }); }); } diff --git a/test/pubdev_api_test.dart b/test/pubdev_api_test.dart index 8c42b84..871145b 100644 --- a/test/pubdev_api_test.dart +++ b/test/pubdev_api_test.dart @@ -2,14 +2,9 @@ import 'package:pub_api_client/pub_api_client.dart'; import 'package:test/test.dart'; const packageName = 'fvm'; +final client = PubClient(); void main() { group('PubDev Client', () { - PubClient client; - - setUp(() { - client = PubClient(); - }); - test('Can Fetch package info', () async { final packageInfo = await client.packageInfo(packageName); @@ -67,7 +62,7 @@ void main() { test('Search for packages', () async { final payload = await client.search('json'); - final nextPagePayload = await payload.nextResults(); + final nextPagePayload = await client.nextPage(payload.next ?? ''); expect(payload.packages.length, greaterThan(1)); expect(nextPagePayload.packages.length, greaterThan(1)); }); @@ -86,28 +81,5 @@ void main() { expect(documentation.latestStableVersion, packageInfo.version); expect(documentation.versions.length, packageInfo.versions.length); }); - - test('Check package update', () async { - final packageInfo = await client.packageInfo(packageName); - final latestWithoutCurrent = await client.checkLatest(packageName); - - expect(latestWithoutCurrent.needUpdate, false); - expect(latestWithoutCurrent.latestVersion, packageInfo.version); - expect( - latestWithoutCurrent.latestVersion, - packageInfo.latest.version, - ); - expect(latestWithoutCurrent.packageInfo.name, packageName); - - final latestNeedUpdate = - await client.checkLatest(packageName, currentVersion: '1.0.0'); - - expect(latestNeedUpdate.needUpdate, true); - - final latestCurrent = await client.checkLatest(packageName, - currentVersion: packageInfo.version); - - expect(latestCurrent.needUpdate, false); - }); }); }