diff --git a/packages/shorebird_code_push_protocol/lib/src/models/models.dart b/packages/shorebird_code_push_protocol/lib/src/models/models.dart index 9528d002..6c74306c 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/models.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/models.dart @@ -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'; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/artifact.dart b/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.dart similarity index 64% rename from packages/shorebird_code_push_protocol/lib/src/models/artifact.dart rename to packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.dart index 8e6bdaf4..c8d642ba 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/artifact.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.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 to a [Artifact] - factory Artifact.fromJson(Map json) => - _$ArtifactFromJson(json); + /// Converts a Map to a [PatchArtifact] + factory PatchArtifact.fromJson(Map json) => + _$PatchArtifactFromJson(json); - /// Converts a [Artifact] to a Map - Map toJson() => _$ArtifactToJson(this); + /// Converts a [PatchArtifact] to a Map + Map toJson() => _$PatchArtifactToJson(this); /// The ID of the artifact; final int id; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/artifact.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart similarity index 80% rename from packages/shorebird_code_push_protocol/lib/src/models/artifact.g.dart rename to packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart index 3129697a..576e351f 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/artifact.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/patch_artifact.g.dart @@ -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 json) => $checkedCreate( - 'Artifact', +PatchArtifact _$PatchArtifactFromJson(Map 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 json) => $checkedCreate( fieldKeyMap: const {'patchId': 'patch_id'}, ); -Map _$ArtifactToJson(Artifact instance) => { +Map _$PatchArtifactToJson(PatchArtifact instance) => + { 'id': instance.id, 'patch_id': instance.patchId, 'arch': instance.arch, diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.dart b/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.dart new file mode 100644 index 00000000..d4984df1 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.dart @@ -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 to a [ReleaseArtifact] + factory ReleaseArtifact.fromJson(Map json) => + _$ReleaseArtifactFromJson(json); + + /// Converts a [ReleaseArtifact] to a Map + Map 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; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart new file mode 100644 index 00000000..7e112326 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/release_artifact.g.dart @@ -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 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 _$ReleaseArtifactToJson(ReleaseArtifact instance) => + { + 'id': instance.id, + 'release_id': instance.releaseId, + 'arch': instance.arch, + 'platform': instance.platform, + 'hash': instance.hash, + 'size': instance.size, + 'url': instance.url, + }; diff --git a/packages/shorebird_code_push_protocol/test/src/models/artifact_test.dart b/packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart similarity index 77% rename from packages/shorebird_code_push_protocol/test/src/models/artifact_test.dart rename to packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart index 8e1e47f6..385d01e9 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/artifact_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart @@ -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()), ); }); diff --git a/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart b/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart new file mode 100644 index 00000000..a4cfb3fb --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart @@ -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()), + ); + }); + }); +}