diff --git a/packages/shorebird_code_push_protocol/lib/src/models/account.dart b/packages/shorebird_code_push_protocol/lib/src/models/account.dart deleted file mode 100644 index 96e83266..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/account.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; - -part 'account.g.dart'; - -/// {@template account} -/// A user account which contains zero or more apps. -/// {@endtemplate} -@JsonSerializable() -class Account { - /// {@macro account} - Account({required this.apiKey, List? apps}) : apps = apps ?? []; - - /// Converts a Map to a [Account] - factory Account.fromJson(Map json) => - _$AccountFromJson(json); - - /// Converts a [Account] to a Map - Map toJson() => _$AccountToJson(this); - - /// List of apps associated with this account. - final List apps; - - /// The api key associated with this account. - final String apiKey; -} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/account.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/account.g.dart deleted file mode 100644 index 17a0fccb..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/account.g.dart +++ /dev/null @@ -1,31 +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 'account.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Account _$AccountFromJson(Map json) => $checkedCreate( - 'Account', - json, - ($checkedConvert) { - final val = Account( - apiKey: $checkedConvert('api_key', (v) => v as String), - apps: $checkedConvert( - 'apps', - (v) => (v as List?) - ?.map((e) => App.fromJson(e as Map)) - .toList()), - ); - return val; - }, - fieldKeyMap: const {'apiKey': 'api_key'}, - ); - -Map _$AccountToJson(Account instance) => { - 'apps': instance.apps.map((e) => e.toJson()).toList(), - 'api_key': instance.apiKey, - }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/app.dart b/packages/shorebird_code_push_protocol/lib/src/models/app.dart index beaffc8e..62ffd4ab 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/app.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/app.dart @@ -1,5 +1,4 @@ import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; part 'app.g.dart'; @@ -9,8 +8,11 @@ part 'app.g.dart'; @JsonSerializable() class App { /// {@macro app} - App({required this.appId, List? releases}) - : releases = releases ?? []; + const App({ + required this.appId, + this.latestReleaseVersion, + this.latestPatchNumber, + }); /// Converts a Map to an [App] factory App.fromJson(Map json) => _$AppFromJson(json); @@ -21,6 +23,9 @@ class App { /// The ID of the app. final String appId; - /// List of releases associated with this app. - final List releases; + /// The latest release version of the app. + final String? latestReleaseVersion; + + /// The latest patch number of the app. + final int? latestPatchNumber; } diff --git a/packages/shorebird_code_push_protocol/lib/src/models/app.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/app.g.dart index 23f841fe..987defd0 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/app.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/app.g.dart @@ -14,18 +14,22 @@ App _$AppFromJson(Map json) => $checkedCreate( ($checkedConvert) { final val = App( appId: $checkedConvert('app_id', (v) => v as String), - releases: $checkedConvert( - 'releases', - (v) => (v as List?) - ?.map((e) => Release.fromJson(e as Map)) - .toList()), + latestReleaseVersion: + $checkedConvert('latest_release_version', (v) => v as String?), + latestPatchNumber: + $checkedConvert('latest_patch_number', (v) => v as int?), ); return val; }, - fieldKeyMap: const {'appId': 'app_id'}, + fieldKeyMap: const { + 'appId': 'app_id', + 'latestReleaseVersion': 'latest_release_version', + 'latestPatchNumber': 'latest_patch_number' + }, ); Map _$AppToJson(App instance) => { 'app_id': instance.appId, - 'releases': instance.releases.map((e) => e.toJson()).toList(), + 'latest_release_version': instance.latestReleaseVersion, + 'latest_patch_number': instance.latestPatchNumber, }; 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 161678c3..07882afe 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/models.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/models.dart @@ -1,6 +1,4 @@ -export 'account.dart'; export 'app.dart'; export 'artifact.dart'; export 'patch.dart'; -export 'registry.dart'; -export 'release.dart'; +export 'user.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/patch.dart b/packages/shorebird_code_push_protocol/lib/src/models/patch.dart index d5ebf35b..e00a3fe5 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/patch.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/patch.dart @@ -1,5 +1,4 @@ import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; part 'patch.g.dart'; @@ -9,11 +8,7 @@ part 'patch.g.dart'; @JsonSerializable() class Patch { /// {@macro patch} - const Patch({ - required this.number, - this.artifacts = const [], - this.channels = const [], - }); + const Patch({required this.id, required this.number}); /// Converts a Map to a [Patch] factory Patch.fromJson(Map json) => _$PatchFromJson(json); @@ -21,12 +16,9 @@ class Patch { /// Converts a [Patch] to a Map Map toJson() => _$PatchToJson(this); + /// The unique patch identifier. + final int id; + /// The patch number (newer patches are larger). final int number; - - /// The list of channels associated with this patch. - final List channels; - - /// List of artifacts associated with this patch. - final List artifacts; } diff --git a/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart index 7b942887..3f04be68 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/patch.g.dart @@ -13,26 +13,14 @@ Patch _$PatchFromJson(Map json) => $checkedCreate( json, ($checkedConvert) { final val = Patch( + id: $checkedConvert('id', (v) => v as int), number: $checkedConvert('number', (v) => v as int), - artifacts: $checkedConvert( - 'artifacts', - (v) => - (v as List?) - ?.map((e) => Artifact.fromJson(e as Map)) - .toList() ?? - const []), - channels: $checkedConvert( - 'channels', - (v) => - (v as List?)?.map((e) => e as String).toList() ?? - const []), ); return val; }, ); Map _$PatchToJson(Patch instance) => { + 'id': instance.id, 'number': instance.number, - 'channels': instance.channels, - 'artifacts': instance.artifacts.map((e) => e.toJson()).toList(), }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/registry.dart b/packages/shorebird_code_push_protocol/lib/src/models/registry.dart deleted file mode 100644 index c6568ac3..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/registry.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; - -part 'registry.g.dart'; - -/// {@template registry} -/// A collection of accounts and their respective apps -/// {@endtemplate} -@JsonSerializable() -class Registry { - /// {@macro registry} - const Registry({this.accounts = const []}); - - /// Converts a Map to a [Registry] - factory Registry.fromJson(Map json) => - _$RegistryFromJson(json); - - /// Converts a [Registry] to a Map - Map toJson() => _$RegistryToJson(this); - - /// List of accounts associated with this registry. - final List accounts; -} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/registry.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/registry.g.dart deleted file mode 100644 index 70b6fa89..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/registry.g.dart +++ /dev/null @@ -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 'registry.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Registry _$RegistryFromJson(Map json) => $checkedCreate( - 'Registry', - json, - ($checkedConvert) { - final val = Registry( - accounts: $checkedConvert( - 'accounts', - (v) => - (v as List?) - ?.map((e) => Account.fromJson(e as Map)) - .toList() ?? - const []), - ); - return val; - }, - ); - -Map _$RegistryToJson(Registry instance) => { - 'accounts': instance.accounts.map((e) => e.toJson()).toList(), - }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release.dart b/packages/shorebird_code_push_protocol/lib/src/models/release.dart deleted file mode 100644 index 6f32d02a..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/release.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; - -part 'release.g.dart'; - -/// {@template release} -/// A single release which contains zero or more patches. -/// {@endtemplate} -@JsonSerializable() -class Release { - /// {@macro release} - Release({required this.version, List? patches}) - : patches = patches ?? []; - - /// Converts a Map to a [Release] - factory Release.fromJson(Map json) => - _$ReleaseFromJson(json); - - /// Converts a [Release] to a Map - Map toJson() => _$ReleaseToJson(this); - - /// The version of the release. - final String version; - - /// List of patches associated with this release. - final List patches; -} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart deleted file mode 100644 index 4a24ffc8..00000000 --- a/packages/shorebird_code_push_protocol/lib/src/models/release.g.dart +++ /dev/null @@ -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 'release.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Release _$ReleaseFromJson(Map json) => $checkedCreate( - 'Release', - json, - ($checkedConvert) { - final val = Release( - version: $checkedConvert('version', (v) => v as String), - patches: $checkedConvert( - 'patches', - (v) => (v as List?) - ?.map((e) => Patch.fromJson(e as Map)) - .toList()), - ); - return val; - }, - ); - -Map _$ReleaseToJson(Release instance) => { - 'version': instance.version, - 'patches': instance.patches.map((e) => e.toJson()).toList(), - }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/user.dart b/packages/shorebird_code_push_protocol/lib/src/models/user.dart new file mode 100644 index 00000000..a6a0c4f9 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/user.dart @@ -0,0 +1,21 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'user.g.dart'; + +/// {@template user} +/// A user account which contains zero or more apps. +/// {@endtemplate} +@JsonSerializable() +class User { + /// {@macro user} + const User({required this.id}); + + /// Converts a Map to a [User] + factory User.fromJson(Map json) => _$UserFromJson(json); + + /// Converts a [User] to a Map + Map toJson() => _$UserToJson(this); + + /// The unique user identifier. + final int id; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart new file mode 100644 index 00000000..46c852fc --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart @@ -0,0 +1,24 @@ +// 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 'user.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +User _$UserFromJson(Map json) => $checkedCreate( + 'User', + json, + ($checkedConvert) { + final val = User( + id: $checkedConvert('id', (v) => v as int), + ); + return val; + }, + ); + +Map _$UserToJson(User instance) => { + 'id': instance.id, + }; diff --git a/packages/shorebird_code_push_protocol/test/src/models/app_test.dart b/packages/shorebird_code_push_protocol/test/src/models/app_test.dart new file mode 100644 index 00000000..a31c47bd --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/app_test.dart @@ -0,0 +1,15 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group('App', () { + test('can be (de)serialized', () { + const app = App( + appId: 'my_app', + latestReleaseVersion: '1.0.0', + latestPatchNumber: 1, + ); + expect(App.fromJson(app.toJson()).toJson(), equals(app.toJson())); + }); + }); +} diff --git a/packages/shorebird_code_push_protocol/test/src/models/artifact_test.dart b/packages/shorebird_code_push_protocol/test/src/models/artifact_test.dart new file mode 100644 index 00000000..91efeaf2 --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/artifact_test.dart @@ -0,0 +1,19 @@ +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()), + ); + }); + }); +} diff --git a/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart b/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart new file mode 100644 index 00000000..e8ceeb7f --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart @@ -0,0 +1,14 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group('Patch', () { + test('can be (de)serialized', () { + const patch = Patch(id: 1, number: 2); + expect( + Patch.fromJson(patch.toJson()).toJson(), + equals(patch.toJson()), + ); + }); + }); +} diff --git a/packages/shorebird_code_push_protocol/test/src/models/registry_test.dart b/packages/shorebird_code_push_protocol/test/src/models/registry_test.dart deleted file mode 100644 index 86e1f6c9..00000000 --- a/packages/shorebird_code_push_protocol/test/src/models/registry_test.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; -import 'package:test/test.dart'; - -void main() { - group('Registry', () { - test('can be (de)serialized', () { - final registry = Registry( - accounts: [ - Account( - apiKey: 'api_key1', - apps: [ - App( - appId: 'app1', - releases: [ - Release( - version: '1.0.0', - patches: [ - const Patch( - number: 1, - artifacts: [ - Artifact( - arch: 'aarm64', - platform: 'android', - url: 'localhost', - hash: '#', - ) - ], - channels: ['stable'], - ), - const Patch( - number: 2, - artifacts: [ - Artifact( - arch: 'aarm64', - platform: 'android', - url: 'localhost', - hash: '#', - ) - ], - channels: ['stable'], - ) - ], - ), - Release(version: '1.0.1'), - ], - ), - App(appId: 'app2'), - ], - ), - Account( - apiKey: 'api_key2', - apps: [ - App( - appId: 'app2', - releases: [ - Release( - version: '1.0.0', - patches: [ - const Patch( - number: 1, - artifacts: [ - Artifact( - arch: 'aarm64', - platform: 'android', - url: 'localhost', - hash: '#', - ) - ], - channels: ['stable'], - ), - const Patch( - number: 2, - artifacts: [ - Artifact( - arch: 'aarm64', - platform: 'android', - url: 'localhost', - hash: '#', - ) - ], - channels: ['stable'], - ) - ], - ), - Release(version: '2.0.0'), - ], - ), - ], - ), - ], - ); - - expect( - Registry.fromJson(registry.toJson()).toJson(), - equals(registry.toJson()), - ); - }); - }); -} diff --git a/packages/shorebird_code_push_protocol/test/src/models/user_test.dart b/packages/shorebird_code_push_protocol/test/src/models/user_test.dart new file mode 100644 index 00000000..a0f2653c --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/user_test.dart @@ -0,0 +1,14 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group('User', () { + test('can be (de)serialized', () { + const user = User(id: 1); + expect( + User.fromJson(user.toJson()).toJson(), + equals(user.toJson()), + ); + }); + }); +}