feat(code_push_protocol): add Artifact, Channel, and Release (#145)
This commit is contained in:
committed by
Felix Angelov
parent
61dba615f9
commit
8640a26db2
@@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
part 'app.g.dart';
|
||||
|
||||
/// {@template app}
|
||||
/// A single app which contains zero or more releases.
|
||||
/// The application downloaded and run on various devices/platforms.
|
||||
/// {@endtemplate}
|
||||
@JsonSerializable()
|
||||
class App {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'artifact.g.dart';
|
||||
|
||||
/// {@template 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({
|
||||
required this.id,
|
||||
required this.patchId,
|
||||
required this.arch,
|
||||
required this.platform,
|
||||
required this.hash,
|
||||
required this.url,
|
||||
});
|
||||
|
||||
/// Converts a Map<String, dynamic> to a [Artifact]
|
||||
factory Artifact.fromJson(Map<String, dynamic> json) =>
|
||||
_$ArtifactFromJson(json);
|
||||
|
||||
/// Converts a [Artifact] to a Map<String, dynamic>
|
||||
Map<String, dynamic> toJson() => _$ArtifactToJson(this);
|
||||
|
||||
/// The ID of the artifact;
|
||||
final int id;
|
||||
|
||||
/// The ID of the patch.
|
||||
final int patchId;
|
||||
|
||||
/// 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 url of the artifact.
|
||||
final String url;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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(
|
||||
id: $checkedConvert('id', (v) => v as int),
|
||||
patchId: $checkedConvert('patch_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),
|
||||
url: $checkedConvert('url', (v) => v as String),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {'patchId': 'patch_id'},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ArtifactToJson(Artifact instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'patch_id': instance.patchId,
|
||||
'arch': instance.arch,
|
||||
'platform': instance.platform,
|
||||
'hash': instance.hash,
|
||||
'url': instance.url,
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'channel.g.dart';
|
||||
|
||||
/// {@template channel}
|
||||
/// A tag used to manage the subset of applications that receive a patch.
|
||||
/// By default, a "stable" channel is created and
|
||||
/// used by devices to query for available patches.
|
||||
/// {@endtemplate}
|
||||
@JsonSerializable()
|
||||
class Channel {
|
||||
/// {@macro channel}
|
||||
const Channel({required this.id, required this.appId, required this.name});
|
||||
|
||||
/// Converts a Map<String, dynamic> to a [Channel]
|
||||
factory Channel.fromJson(Map<String, dynamic> json) =>
|
||||
_$ChannelFromJson(json);
|
||||
|
||||
/// Converts a [Channel] to a Map<String, dynamic>
|
||||
Map<String, dynamic> toJson() => _$ChannelToJson(this);
|
||||
|
||||
/// The ID of the channel;
|
||||
final int id;
|
||||
|
||||
/// The ID of the app.
|
||||
final String appId;
|
||||
|
||||
/// The channel name.
|
||||
final String name;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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 'channel.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Channel _$ChannelFromJson(Map<String, dynamic> json) => $checkedCreate(
|
||||
'Channel',
|
||||
json,
|
||||
($checkedConvert) {
|
||||
final val = Channel(
|
||||
id: $checkedConvert('id', (v) => v as int),
|
||||
appId: $checkedConvert('app_id', (v) => v as String),
|
||||
name: $checkedConvert('name', (v) => v as String),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {'appId': 'app_id'},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ChannelToJson(Channel instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'app_id': instance.appId,
|
||||
'name': instance.name,
|
||||
};
|
||||
@@ -1,5 +1,8 @@
|
||||
export 'app.dart';
|
||||
export 'app_metadata.dart';
|
||||
export 'artifact.dart';
|
||||
export 'channel.dart';
|
||||
export 'error_response.dart';
|
||||
export 'patch.dart';
|
||||
export 'release.dart';
|
||||
export 'user.dart';
|
||||
|
||||
@@ -3,7 +3,9 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
part 'patch.g.dart';
|
||||
|
||||
/// {@template patch}
|
||||
/// A single patch which contains zero or more artifacts.
|
||||
/// An over the air update which is applied to a specific release.
|
||||
/// All patches have a patch number (auto-incrementing integer) and
|
||||
/// multiple patches can be published for a given app release version.
|
||||
/// {@endtemplate}
|
||||
@JsonSerializable()
|
||||
class Patch {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'release.g.dart';
|
||||
|
||||
/// {@template release}
|
||||
/// A release build of an application that is distributed to devices.
|
||||
/// A release can have zero or more patches applied to it.
|
||||
/// {@endtemplate}
|
||||
@JsonSerializable()
|
||||
class Release {
|
||||
/// {@macro release}
|
||||
const Release({
|
||||
required this.id,
|
||||
required this.appId,
|
||||
required this.version,
|
||||
required this.displayName,
|
||||
});
|
||||
|
||||
/// Converts a Map<String, dynamic> to a [Release]
|
||||
factory Release.fromJson(Map<String, dynamic> json) =>
|
||||
_$ReleaseFromJson(json);
|
||||
|
||||
/// Converts a [Release] to a Map<String, dynamic>
|
||||
Map<String, dynamic> toJson() => _$ReleaseToJson(this);
|
||||
|
||||
/// The ID of the release;
|
||||
final int id;
|
||||
|
||||
/// The ID of the app.
|
||||
final String appId;
|
||||
|
||||
/// The version of the release.
|
||||
final String version;
|
||||
|
||||
/// The display name for the release
|
||||
final String? displayName;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Release _$ReleaseFromJson(Map<String, dynamic> json) => $checkedCreate(
|
||||
'Release',
|
||||
json,
|
||||
($checkedConvert) {
|
||||
final val = Release(
|
||||
id: $checkedConvert('id', (v) => v as int),
|
||||
appId: $checkedConvert('app_id', (v) => v as String),
|
||||
version: $checkedConvert('version', (v) => v as String),
|
||||
displayName: $checkedConvert('display_name', (v) => v as String?),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {'appId': 'app_id', 'displayName': 'display_name'},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ReleaseToJson(Release instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'app_id': instance.appId,
|
||||
'version': instance.version,
|
||||
'display_name': instance.displayName,
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
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(
|
||||
id: 1,
|
||||
patchId: 1,
|
||||
arch: 'aarch64',
|
||||
platform: 'android',
|
||||
url: 'https://example.com',
|
||||
hash: 'sha256:1234567890',
|
||||
);
|
||||
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('Channel', () {
|
||||
test('can be (de)serialized', () {
|
||||
const channel = Channel(
|
||||
id: 1,
|
||||
appId: 'app-id',
|
||||
name: 'stable',
|
||||
);
|
||||
expect(
|
||||
Channel.fromJson(channel.toJson()).toJson(),
|
||||
equals(channel.toJson()),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Release', () {
|
||||
test('can be (de)serialized', () {
|
||||
const release = Release(
|
||||
id: 1,
|
||||
appId: 'app-id',
|
||||
version: '1.0.0',
|
||||
displayName: 'v1.0.0',
|
||||
);
|
||||
expect(
|
||||
Release.fromJson(release.toJson()).toJson(),
|
||||
equals(release.toJson()),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user