From eb545110f24e5404d0aaee5ae26abe1aa1a27c49 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 11 Jul 2023 15:02:27 -0400 Subject: [PATCH] chore: use int as Money transport type, expose money2 dependency from shorebird_code_push_protocol (#827) --- packages/shorebird_cli/pubspec.yaml | 1 - packages/shorebird_code_push_client/pubspec.yaml | 1 - .../lib/shorebird_code_push_protocol.dart | 1 + .../lib/src/converters/money_converter.dart | 10 ++++++---- .../src/messages/get_usage/get_usage_response.g.dart | 2 +- .../lib/src/models/shorebird_plan.g.dart | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/shorebird_cli/pubspec.yaml b/packages/shorebird_cli/pubspec.yaml index b0b0029d..0bf3d66d 100644 --- a/packages/shorebird_cli/pubspec.yaml +++ b/packages/shorebird_cli/pubspec.yaml @@ -23,7 +23,6 @@ dependencies: json_annotation: ^4.8.0 mason_logger: ^0.2.4 meta: ^1.9.0 - money2: ^3.4.1 path: ^1.8.3 platform: ^3.1.0 propertylistserialization: ^1.3.0 diff --git a/packages/shorebird_code_push_client/pubspec.yaml b/packages/shorebird_code_push_client/pubspec.yaml index a894497b..9445397a 100644 --- a/packages/shorebird_code_push_client/pubspec.yaml +++ b/packages/shorebird_code_push_client/pubspec.yaml @@ -10,7 +10,6 @@ environment: dependencies: http: ^1.0.0 - money2: ^3.4.1 shorebird_code_push_protocol: path: ../shorebird_code_push_protocol diff --git a/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart b/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart index 4e50b37c..ef127e20 100644 --- a/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart +++ b/packages/shorebird_code_push_protocol/lib/shorebird_code_push_protocol.dart @@ -1,6 +1,7 @@ /// The Shorebird CodePush Protocol library shorebird_code_push_protocol; +export 'package:money2/money2.dart' show Currency, Money; export 'src/converters/converters.dart'; export 'src/messages/messages.dart'; export 'src/models/models.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart b/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart index 129ddcd4..c0d404a4 100644 --- a/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart +++ b/packages/shorebird_code_push_protocol/lib/src/converters/money_converter.dart @@ -5,15 +5,17 @@ import 'package:money2/money2.dart'; Currency get usd => Currency.create('USD', 2); /// {@template money_converter} -/// Converts between [Money] and [String]. +/// Converts between [Money] and [int]. /// {@endtemplate} -class MoneyConverter implements JsonConverter { +// TODO(bryanoltman): change this to use String as the transport type the next +// time we make a breaking change to the API. +class MoneyConverter implements JsonConverter { /// {@macro money_converter} const MoneyConverter(); @override - Money fromJson(String cents) => Money.parseWithCurrency(cents, usd); + Money fromJson(int cents) => Money.fromIntWithCurrency(cents, usd); @override - String toJson(Money money) => money.minorUnits.toString(); + int toJson(Money money) => money.minorUnits.toInt(); } diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/get_usage/get_usage_response.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/get_usage/get_usage_response.g.dart index 088d7faa..170bfd72 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/get_usage/get_usage_response.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/get_usage/get_usage_response.g.dart @@ -26,7 +26,7 @@ GetUsageResponse _$GetUsageResponseFromJson(Map json) => currentPeriodEnd: $checkedConvert( 'current_period_end', (v) => DateTime.parse(v as String)), currentPeriodCost: $checkedConvert('current_period_cost', - (v) => const MoneyConverter().fromJson(v as String)), + (v) => const MoneyConverter().fromJson(v as int)), patchInstallLimit: $checkedConvert('patch_install_limit', (v) => v as int?), ); diff --git a/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart index 5edf378e..8180cf53 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/shorebird_plan.g.dart @@ -15,8 +15,8 @@ ShorebirdPlan _$ShorebirdPlanFromJson(Map json) => ($checkedConvert) { final val = ShorebirdPlan( name: $checkedConvert('name', (v) => v as String), - monthlyCost: $checkedConvert('monthly_cost', - (v) => const MoneyConverter().fromJson(v as String)), + monthlyCost: $checkedConvert( + 'monthly_cost', (v) => const MoneyConverter().fromJson(v as int)), patchInstallLimit: $checkedConvert('patch_install_limit', (v) => v as int?), maxTeamSize: $checkedConvert('max_team_size', (v) => v as int?),