feat(code_push_protocol): add ReleaseArtifact (#183)

This commit is contained in:
Felix Angelov
2023-03-28 13:00:14 -05:00
committed by GitHub
parent a1033d79fa
commit 93ab8d47c2
7 changed files with 132 additions and 19 deletions
@@ -1,8 +1,9 @@
export 'app.dart';
export 'app_metadata.dart';
export 'artifact.dart';
export 'channel.dart';
export 'error_response.dart';
export 'patch.dart';
export 'patch_artifact.dart';
export 'release.dart';
export 'release_artifact.dart';
export 'user.dart';
@@ -1,15 +1,15 @@
import 'package:json_annotation/json_annotation.dart';
part 'artifact.g.dart';
part 'patch_artifact.g.dart';
/// {@template artifact}
/// {@template patch_artifact}
/// An artifact contains metadata about the contents of a specific patch
/// for a specific platform and architecture.
/// {@endtemplate}
@JsonSerializable()
class Artifact {
/// {@macro artifact}
const Artifact({
class PatchArtifact {
/// {@macro patch_artifact}
const PatchArtifact({
required this.id,
required this.patchId,
required this.arch,
@@ -19,12 +19,12 @@ class Artifact {
required this.url,
});
/// Converts a Map<String, dynamic> to a [Artifact]
factory Artifact.fromJson(Map<String, dynamic> json) =>
_$ArtifactFromJson(json);
/// Converts a Map<String, dynamic> to a [PatchArtifact]
factory PatchArtifact.fromJson(Map<String, dynamic> json) =>
_$PatchArtifactFromJson(json);
/// Converts a [Artifact] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$ArtifactToJson(this);
/// Converts a [PatchArtifact] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$PatchArtifactToJson(this);
/// The ID of the artifact;
final int id;
@@ -2,17 +2,18 @@
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
part of 'artifact.dart';
part of 'patch_artifact.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Artifact _$ArtifactFromJson(Map<String, dynamic> json) => $checkedCreate(
'Artifact',
PatchArtifact _$PatchArtifactFromJson(Map<String, dynamic> json) =>
$checkedCreate(
'PatchArtifact',
json,
($checkedConvert) {
final val = Artifact(
final val = PatchArtifact(
id: $checkedConvert('id', (v) => v as int),
patchId: $checkedConvert('patch_id', (v) => v as int),
arch: $checkedConvert('arch', (v) => v as String),
@@ -26,7 +27,8 @@ Artifact _$ArtifactFromJson(Map<String, dynamic> json) => $checkedCreate(
fieldKeyMap: const {'patchId': 'patch_id'},
);
Map<String, dynamic> _$ArtifactToJson(Artifact instance) => <String, dynamic>{
Map<String, dynamic> _$PatchArtifactToJson(PatchArtifact instance) =>
<String, dynamic>{
'id': instance.id,
'patch_id': instance.patchId,
'arch': instance.arch,
@@ -0,0 +1,49 @@
import 'package:json_annotation/json_annotation.dart';
part 'release_artifact.g.dart';
/// {@template release_artifact}
/// An artifact contains metadata about the contents of a specific release
/// for a specific platform and architecture.
/// {@endtemplate}
@JsonSerializable()
class ReleaseArtifact {
/// {@macro release_artifact}
const ReleaseArtifact({
required this.id,
required this.releaseId,
required this.arch,
required this.platform,
required this.hash,
required this.size,
required this.url,
});
/// Converts a Map<String, dynamic> to a [ReleaseArtifact]
factory ReleaseArtifact.fromJson(Map<String, dynamic> json) =>
_$ReleaseArtifactFromJson(json);
/// Converts a [ReleaseArtifact] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$ReleaseArtifactToJson(this);
/// The ID of the artifact;
final int id;
/// The ID of the release.
final int releaseId;
/// The arch of the artifact.
final String arch;
/// The platform of the artifact.
final String platform;
/// The hash of the artifact.
final String hash;
/// The size of the artifact in bytes.
final int size;
/// The url of the artifact.
final String url;
}
@@ -0,0 +1,39 @@
// 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 'release_artifact.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
ReleaseArtifact _$ReleaseArtifactFromJson(Map<String, dynamic> json) =>
$checkedCreate(
'ReleaseArtifact',
json,
($checkedConvert) {
final val = ReleaseArtifact(
id: $checkedConvert('id', (v) => v as int),
releaseId: $checkedConvert('release_id', (v) => v as int),
arch: $checkedConvert('arch', (v) => v as String),
platform: $checkedConvert('platform', (v) => v as String),
hash: $checkedConvert('hash', (v) => v as String),
size: $checkedConvert('size', (v) => v as int),
url: $checkedConvert('url', (v) => v as String),
);
return val;
},
fieldKeyMap: const {'releaseId': 'release_id'},
);
Map<String, dynamic> _$ReleaseArtifactToJson(ReleaseArtifact instance) =>
<String, dynamic>{
'id': instance.id,
'release_id': instance.releaseId,
'arch': instance.arch,
'platform': instance.platform,
'hash': instance.hash,
'size': instance.size,
'url': instance.url,
};
@@ -2,9 +2,9 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group('Artifact', () {
group('PatchArtifact', () {
test('can be (de)serialized', () {
const artifact = Artifact(
const artifact = PatchArtifact(
id: 1,
patchId: 1,
arch: 'aarch64',
@@ -14,7 +14,7 @@ void main() {
hash: 'sha256:1234567890',
);
expect(
Artifact.fromJson(artifact.toJson()).toJson(),
PatchArtifact.fromJson(artifact.toJson()).toJson(),
equals(artifact.toJson()),
);
});
@@ -0,0 +1,22 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group('ReleaseArtifact', () {
test('can be (de)serialized', () {
const artifact = ReleaseArtifact(
id: 1,
releaseId: 1,
arch: 'aarch64',
platform: 'android',
url: 'https://example.com',
size: 42,
hash: 'sha256:1234567890',
);
expect(
ReleaseArtifact.fromJson(artifact.toJson()).toJson(),
equals(artifact.toJson()),
);
});
});
}