refactor(code_push_protocol): add PatchArtifact (#89)

This commit is contained in:
Felix Angelov
2023-03-17 12:13:14 -05:00
committed by GitHub
parent 894559d8b5
commit 1cf8aa9662
8 changed files with 88 additions and 90 deletions
@@ -1,39 +0,0 @@
import 'package:json_annotation/json_annotation.dart';
part 'artifact.g.dart';
/// {@template artifact}
/// An artifact represents the contents of an update (patch) for a specific
/// platform and architecture.
/// {@endtemplate}
@JsonSerializable()
class Artifact {
/// {@macro artifact}
const Artifact({
required this.arch,
required this.platform,
required this.url,
required this.hash,
});
/// Converts a Map<String, dynamic> to an [Artifact]
factory Artifact.fromJson(Map<String, dynamic> json) =>
_$ArtifactFromJson(json);
/// Converts an [Artifact] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$ArtifactToJson(this);
/// The architecture of the artifact.
/// e.g. arm64, x86_64
final String arch;
/// The platform of the artifact.
/// e.g. android, ios
final String platform;
/// The URL of the artifact.
final String url;
/// The hash of the artifact.
final String hash;
}
@@ -1,30 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
part of 'artifact.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Artifact _$ArtifactFromJson(Map<String, dynamic> json) => $checkedCreate(
'Artifact',
json,
($checkedConvert) {
final val = Artifact(
arch: $checkedConvert('arch', (v) => v as String),
platform: $checkedConvert('platform', (v) => v as String),
url: $checkedConvert('url', (v) => v as String),
hash: $checkedConvert('hash', (v) => v as String),
);
return val;
},
);
Map<String, dynamic> _$ArtifactToJson(Artifact instance) => <String, dynamic>{
'arch': instance.arch,
'platform': instance.platform,
'url': instance.url,
'hash': instance.hash,
};
@@ -1,4 +1,4 @@
export 'app.dart';
export 'artifact.dart';
export 'patch.dart';
export 'patch_artifact.dart';
export 'user.dart';
@@ -19,6 +19,7 @@ class Patch {
/// The unique patch identifier.
final int id;
/// The patch number (newer patches are larger).
/// The patch number.
/// A larger number equates to a newer patch.
final int number;
}
@@ -0,0 +1,33 @@
import 'package:json_annotation/json_annotation.dart';
part 'patch_artifact.g.dart';
/// {@template patch_artifact}
/// A patch artifact represents the contents of an update (patch) for a specific
/// platform and architecture.
/// {@endtemplate}
@JsonSerializable()
class PatchArtifact {
/// {@macro patch_PatchArtifact}
const PatchArtifact({
required this.patchNumber,
required this.downloadUrl,
required this.hash,
});
/// Converts a Map<String, dynamic> to an [PatchArtifact]
factory PatchArtifact.fromJson(Map<String, dynamic> json) =>
_$PatchArtifactFromJson(json);
/// Converts an [PatchArtifact] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$PatchArtifactToJson(this);
/// The patch number associated with the artifact.
final int patchNumber;
/// The URL of the artifact.
final String downloadUrl;
/// The hash of the artifact.
final String hash;
}
@@ -0,0 +1,34 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
part of 'patch_artifact.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
PatchArtifact _$PatchArtifactFromJson(Map<String, dynamic> json) =>
$checkedCreate(
'PatchArtifact',
json,
($checkedConvert) {
final val = PatchArtifact(
patchNumber: $checkedConvert('patch_number', (v) => v as int),
downloadUrl: $checkedConvert('download_url', (v) => v as String),
hash: $checkedConvert('hash', (v) => v as String),
);
return val;
},
fieldKeyMap: const {
'patchNumber': 'patch_number',
'downloadUrl': 'download_url'
},
);
Map<String, dynamic> _$PatchArtifactToJson(PatchArtifact instance) =>
<String, dynamic>{
'patch_number': instance.patchNumber,
'download_url': instance.downloadUrl,
'hash': instance.hash,
};
@@ -1,19 +0,0 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group('Artifact', () {
test('can be (de)serialized', () {
const artifact = Artifact(
arch: 'aarm64',
platform: 'android',
url: 'https://example.com',
hash: '#',
);
expect(
Artifact.fromJson(artifact.toJson()).toJson(),
equals(artifact.toJson()),
);
});
});
}
@@ -0,0 +1,18 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group('PatchArtifact', () {
test('can be (de)serialized', () {
const patchArtifact = PatchArtifact(
patchNumber: 1,
downloadUrl: 'https://example.com',
hash: '#',
);
expect(
PatchArtifact.fromJson(patchArtifact.toJson()).toJson(),
equals(patchArtifact.toJson()),
);
});
});
}