feat(shorebird_code_push_protocol): add RecordPatchInstallRequest type (#826)

This commit is contained in:
Bryan Oltman
2023-08-09 16:39:44 -04:00
committed by GitHub
parent b249d76237
commit 03fec3ff4f
5 changed files with 119 additions and 0 deletions
@@ -5,6 +5,7 @@ export 'create_app_collaborator/create_app_collaborator.dart';
export 'create_channel/create_channel.dart';
export 'create_patch/create_patch.dart';
export 'create_patch_artifact/create_patch_artifact.dart';
export 'record_patch_install/record_patch_install.dart';
export 'create_payment_link/create_payment_link.dart';
export 'create_release/create_release.dart';
export 'create_release_artifact/create_release_artifact.dart';
@@ -0,0 +1 @@
export 'record_patch_install_request.dart';
@@ -0,0 +1,45 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
part 'record_patch_install_request.g.dart';
/// {@template record_patch_install_request}
/// Request to record a patch install.
/// {@endtemplate}
@JsonSerializable()
class RecordPatchInstallRequest {
/// {@macro record_patch_install_request}
RecordPatchInstallRequest({
required this.clientId,
required this.appId,
required this.releaseVersion,
required this.patchNumber,
required this.platform,
required this.arch,
});
/// Converts a Map<String, dynamic> to a [RecordPatchInstallRequest]
factory RecordPatchInstallRequest.fromJson(Map<String, dynamic> json) =>
_$RecordPatchInstallRequestFromJson(json);
/// Converts a [RecordPatchInstallRequest] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$RecordPatchInstallRequestToJson(this);
/// The client id of the device being updated.
final String clientId;
/// The id of the app being updated.
final String appId;
/// The id of the app being updated.
final String releaseVersion;
/// The patch number being installed.
final int patchNumber;
/// The platform of the device being updated.
final ReleasePlatform platform;
/// The architecture of the device being updated.
final String arch;
}
@@ -0,0 +1,51 @@
// 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 'record_patch_install_request.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
RecordPatchInstallRequest _$RecordPatchInstallRequestFromJson(
Map<String, dynamic> json) =>
$checkedCreate(
'RecordPatchInstallRequest',
json,
($checkedConvert) {
final val = RecordPatchInstallRequest(
clientId: $checkedConvert('client_id', (v) => v as String),
appId: $checkedConvert('app_id', (v) => v as String),
releaseVersion:
$checkedConvert('release_version', (v) => v as String),
patchNumber: $checkedConvert('patch_number', (v) => v as int),
platform: $checkedConvert(
'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)),
arch: $checkedConvert('arch', (v) => v as String),
);
return val;
},
fieldKeyMap: const {
'clientId': 'client_id',
'appId': 'app_id',
'releaseVersion': 'release_version',
'patchNumber': 'patch_number'
},
);
Map<String, dynamic> _$RecordPatchInstallRequestToJson(
RecordPatchInstallRequest instance) =>
<String, dynamic>{
'client_id': instance.clientId,
'app_id': instance.appId,
'release_version': instance.releaseVersion,
'patch_number': instance.patchNumber,
'platform': _$ReleasePlatformEnumMap[instance.platform]!,
'arch': instance.arch,
};
const _$ReleasePlatformEnumMap = {
ReleasePlatform.android: 'android',
ReleasePlatform.ios: 'ios',
};
@@ -0,0 +1,21 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group(RecordPatchInstallRequest, () {
test('can be (de)serialized', () {
final response = RecordPatchInstallRequest(
clientId: 'some-client-id',
appId: 'some-app-id',
patchNumber: 2,
arch: 'arm64',
platform: ReleasePlatform.android,
releaseVersion: '1.0.0',
);
expect(
RecordPatchInstallRequest.fromJson(response.toJson()).toJson(),
equals(response.toJson()),
);
});
});
}