Skip to content

Commit

Permalink
Merge pull request #48 from leoafarias/chore/update-schema
Browse files Browse the repository at this point in the history
Updated schema
  • Loading branch information
leoafarias authored Mar 8, 2024
2 parents ceb15e1 + 6b42745 commit 6d6ed7e
Show file tree
Hide file tree
Showing 26 changed files with 3,549 additions and 498 deletions.
5 changes: 2 additions & 3 deletions lib/src/endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'models/search_order.dart';

/// Pub.dev api Endpoints
class Endpoint {
static const defaultBaseUrl =
'https://pub.dartlang.org'; // Use pub.dev instead?
static const defaultBaseUrl = 'https://pub.dev';

final String baseUrl;
late final String apiUrl;
Expand Down Expand Up @@ -60,7 +59,7 @@ class Endpoint {
int page,
SearchOrder sort,
) =>
'$searchUrl?q=$query&page=$page&sort=${sort.value}';
'$searchUrl?q=$query&page=$page&sort=${sort.name}';

/// Next search page
String nextPage(String nextPageUrl) =>
Expand Down
3 changes: 3 additions & 0 deletions lib/src/models/barrel.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export 'package:pub_api_client/src/models/latest_version_model.dart';
export 'package:pub_api_client/src/models/package_documentation_model.dart';
export 'package:pub_api_client/src/models/package_like_model.dart';
export 'package:pub_api_client/src/models/package_metrics_model.dart';
export 'package:pub_api_client/src/models/package_options_model.dart';
export 'package:pub_api_client/src/models/package_publisher_model.dart';
export 'package:pub_api_client/src/models/package_score_card.dart';
export 'package:pub_api_client/src/models/package_score_model.dart';
export 'package:pub_api_client/src/models/pub_package_model.dart';
export 'package:pub_api_client/src/models/search_order.dart';
Expand Down
28 changes: 9 additions & 19 deletions lib/src/models/latest_version_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import 'pub_package_model.dart';
import 'package:dart_mappable/dart_mappable.dart';

import '../../pub_api_client.dart';

part 'latest_version_model.mapper.dart';

/// Latest Version update for package
class LatestVersion {
@MappableClass()
class LatestVersion with LatestVersionMappable {
final bool needUpdate;
final String latestVersion;
final PubPackage packageInfo;
Expand All @@ -13,21 +18,6 @@ class LatestVersion {
required this.packageInfo,
});

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is LatestVersion &&
other.needUpdate == needUpdate &&
other.latestVersion == latestVersion &&
other.packageInfo == packageInfo;
}

@override
int get hashCode =>
needUpdate.hashCode ^ latestVersion.hashCode ^ packageInfo.hashCode;

@override
String toString() =>
'''LatestVersion(needUpdate: $needUpdate, latestVersion: $latestVersion, packageInfo: $packageInfo)''';
static const fromMap = LatestVersionMapper.fromMap;
static const fromJson = LatestVersionMapper.fromJson;
}
136 changes: 136 additions & 0 deletions lib/src/models/latest_version_model.mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, unnecessary_cast
// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter

part of 'latest_version_model.dart';

class LatestVersionMapper extends ClassMapperBase<LatestVersion> {
LatestVersionMapper._();

static LatestVersionMapper? _instance;
static LatestVersionMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = LatestVersionMapper._());
PubPackageMapper.ensureInitialized();
}
return _instance!;
}

@override
final String id = 'LatestVersion';

static bool _$needUpdate(LatestVersion v) => v.needUpdate;
static const Field<LatestVersion, bool> _f$needUpdate =
Field('needUpdate', _$needUpdate);
static String _$latestVersion(LatestVersion v) => v.latestVersion;
static const Field<LatestVersion, String> _f$latestVersion =
Field('latestVersion', _$latestVersion);
static PubPackage _$packageInfo(LatestVersion v) => v.packageInfo;
static const Field<LatestVersion, PubPackage> _f$packageInfo =
Field('packageInfo', _$packageInfo);

@override
final MappableFields<LatestVersion> fields = const {
#needUpdate: _f$needUpdate,
#latestVersion: _f$latestVersion,
#packageInfo: _f$packageInfo,
};

static LatestVersion _instantiate(DecodingData data) {
return LatestVersion(
needUpdate: data.dec(_f$needUpdate),
latestVersion: data.dec(_f$latestVersion),
packageInfo: data.dec(_f$packageInfo));
}

@override
final Function instantiate = _instantiate;

static LatestVersion fromMap(Map<String, dynamic> map) {
return ensureInitialized().decodeMap<LatestVersion>(map);
}

static LatestVersion fromJson(String json) {
return ensureInitialized().decodeJson<LatestVersion>(json);
}
}

mixin LatestVersionMappable {
String toJson() {
return LatestVersionMapper.ensureInitialized()
.encodeJson<LatestVersion>(this as LatestVersion);
}

Map<String, dynamic> toMap() {
return LatestVersionMapper.ensureInitialized()
.encodeMap<LatestVersion>(this as LatestVersion);
}

LatestVersionCopyWith<LatestVersion, LatestVersion, LatestVersion>
get copyWith => _LatestVersionCopyWithImpl(
this as LatestVersion, $identity, $identity);
@override
String toString() {
return LatestVersionMapper.ensureInitialized()
.stringifyValue(this as LatestVersion);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(runtimeType == other.runtimeType &&
LatestVersionMapper.ensureInitialized()
.isValueEqual(this as LatestVersion, other));
}

@override
int get hashCode {
return LatestVersionMapper.ensureInitialized()
.hashValue(this as LatestVersion);
}
}

extension LatestVersionValueCopy<$R, $Out>
on ObjectCopyWith<$R, LatestVersion, $Out> {
LatestVersionCopyWith<$R, LatestVersion, $Out> get $asLatestVersion =>
$base.as((v, t, t2) => _LatestVersionCopyWithImpl(v, t, t2));
}

abstract class LatestVersionCopyWith<$R, $In extends LatestVersion, $Out>
implements ClassCopyWith<$R, $In, $Out> {
PubPackageCopyWith<$R, PubPackage, PubPackage> get packageInfo;
$R call({bool? needUpdate, String? latestVersion, PubPackage? packageInfo});
LatestVersionCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}

class _LatestVersionCopyWithImpl<$R, $Out>
extends ClassCopyWithBase<$R, LatestVersion, $Out>
implements LatestVersionCopyWith<$R, LatestVersion, $Out> {
_LatestVersionCopyWithImpl(super.value, super.then, super.then2);

@override
late final ClassMapperBase<LatestVersion> $mapper =
LatestVersionMapper.ensureInitialized();
@override
PubPackageCopyWith<$R, PubPackage, PubPackage> get packageInfo =>
$value.packageInfo.copyWith.$chain((v) => call(packageInfo: v));
@override
$R call({bool? needUpdate, String? latestVersion, PubPackage? packageInfo}) =>
$apply(FieldCopyWithData({
if (needUpdate != null) #needUpdate: needUpdate,
if (latestVersion != null) #latestVersion: latestVersion,
if (packageInfo != null) #packageInfo: packageInfo
}));
@override
LatestVersion $make(CopyWithData data) => LatestVersion(
needUpdate: data.get(#needUpdate, or: $value.needUpdate),
latestVersion: data.get(#latestVersion, or: $value.latestVersion),
packageInfo: data.get(#packageInfo, or: $value.packageInfo));

@override
LatestVersionCopyWith<$R2, LatestVersion, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t) =>
_LatestVersionCopyWithImpl($value, $cast, t);
}
88 changes: 10 additions & 78 deletions lib/src/models/package_documentation_model.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:convert';
import 'package:dart_mappable/dart_mappable.dart';

import 'package:collection/collection.dart';
part 'package_documentation_model.mapper.dart';

/// Package Documentation Model
class PackageDocumentation {
@MappableClass()
class PackageDocumentation with PackageDocumentationMappable {
final String name;
final List<PackageDocumentationVersion> versions;

Expand All @@ -13,47 +13,13 @@ class PackageDocumentation {
this.versions = const [],
});

Map<String, dynamic> toMap() => {
'name': name,
'versions': versions.map((x) => x.toMap()).toList(),
};

factory PackageDocumentation.fromMap(Map<String, dynamic> map) {
final versionMap = map['versions'] as List<dynamic>? ?? [];

return PackageDocumentation(
name: map['name'] as String? ?? '',
versions: versionMap
.map((x) =>
PackageDocumentationVersion.fromMap(x as Map<String, dynamic>))
.toList(),
);
}
String toJson() => json.encode(toMap());

factory PackageDocumentation.fromJson(String source) =>
PackageDocumentation.fromMap(json.decode(source) as Map<String, dynamic>);

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
final listEquals = const DeepCollectionEquality().equals;

return other is PackageDocumentation &&
other.name == name &&
listEquals(other.versions, versions);
}

@override
int get hashCode => name.hashCode ^ versions.hashCode;

@override
String toString() => 'PackageDocumentation(name: $name, versions: $versions)';
static const fromMap = PackageDocumentationMapper.fromMap;
static const fromJson = PackageDocumentationMapper.fromJson;
}

/// Package Documentation Version Model
class PackageDocumentationVersion {
@MappableClass()
class PackageDocumentationVersion with PackageDocumentationVersionMappable {
final String version;
final String status;
final bool hasDocumentation;
Expand All @@ -63,40 +29,6 @@ class PackageDocumentationVersion {
required this.hasDocumentation,
});

Map<String, dynamic> toMap() => {
'version': version,
'status': status,
'hasDocumentation': hasDocumentation,
};

factory PackageDocumentationVersion.fromMap(Map<String, dynamic> map) =>
PackageDocumentationVersion(
version: map['version'] as String? ?? '',
status: map['status'] as String? ?? '',
hasDocumentation: map['hasDocumentation'] as bool? ?? false,
);

String toJson() => json.encode(toMap());

factory PackageDocumentationVersion.fromJson(String source) =>
PackageDocumentationVersion.fromMap(
json.decode(source) as Map<String, dynamic>);

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is PackageDocumentationVersion &&
other.version == version &&
other.status == status &&
other.hasDocumentation == hasDocumentation;
}

@override
int get hashCode =>
version.hashCode ^ status.hashCode ^ hasDocumentation.hashCode;

@override
String toString() =>
'''PackageDocumentationVersion(version: $version, status: $status, hasDocumentation: $hasDocumentation)''';
static const fromMap = PackageDocumentationVersionMapper.fromMap;
static const fromJson = PackageDocumentationVersionMapper.fromJson;
}
Loading

0 comments on commit 6d6ed7e

Please sign in to comment.