Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(shorebird_code_push_protocol): Move response and request models into the protocol package #310

Merged
merged 6 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/shorebird_code_push_protocol/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:very_good_analysis/analysis_options.4.0.0.yaml
analyzer:
exclude:
- build/**
- lib/**.g.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/// The Shorebird CodePush Protocol
library shorebird_code_push_protocol;

export 'src/converters/converters.dart';
export 'src/messages/messages.dart';
export 'src/models/models.dart';

/// Parsed JSON data.
typedef Json = Map<String, dynamic>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'timestamp_converter.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:json_annotation/json_annotation.dart';

/// {@template timestamp_converter}
/// Converts between Unix timestamps and [DateTime].
/// {@endtemplate}
class TimestampConverter implements JsonConverter<DateTime, int> {
/// {@macro timestamp_converter}
const TimestampConverter();

@override
DateTime fromJson(int timestamp) =>
DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);

@override
int toJson(DateTime dateTime) => dateTime.millisecondsSinceEpoch ~/ 1000;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';

part 'cancel_subscription_response.g.dart';

/// {@template cancel_subscription_response}
/// The request body for DELETE /api/v1/subscriptions.
/// {@endtemplate}
@JsonSerializable()
class CancelSubscriptionResponse {
/// {@macro cancel_subscription_response}
CancelSubscriptionResponse({required this.expirationDate});

/// Converts a JSON object to a [CancelSubscriptionResponse].
factory CancelSubscriptionResponse.fromJson(Json json) =>
_$CancelSubscriptionResponseFromJson(json);

/// Converts a [CancelSubscriptionResponse] to a JSON object.
Json toJson() => _$CancelSubscriptionResponseToJson(this);

/// When this subscription will not longer be active.
@TimestampConverter()
final DateTime expirationDate;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'check_for_patches_request.dart';
export 'check_for_patches_response.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:json_annotation/json_annotation.dart';

part 'check_for_patches_request.g.dart';

/// {@template check_for_patches_request}
/// The request body for POST /api/v1/patches/check
/// {@endtemplate}
@JsonSerializable()
class CheckForPatchesRequest {
/// {@macro check_for_patches_request}
const CheckForPatchesRequest({
required this.releaseVersion,
required this.patchNumber,
required this.patchHash,
required this.platform,
required this.arch,
required this.appId,
required this.channel,
});

/// Converts a Map<String, dynamic> to a [CheckForPatchesRequest]
factory CheckForPatchesRequest.fromJson(Map<String, dynamic> json) =>
_$CheckForPatchesRequestFromJson(json);

/// Converts a [CheckForPatchesRequest] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$CheckForPatchesRequestToJson(this);

/// The release version of the app.
final String releaseVersion;

/// The current patch number of the app.
final int? patchNumber;

/// The current patch hash of the app.
final String? patchHash;

/// The platform of the app.
final String platform;

/// The architecture of the app.
final String arch;

/// The ID of the app.
final String appId;

/// The channel of the app.
final String channel;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:json_annotation/json_annotation.dart';

part 'check_for_patches_response.g.dart';

/// {@template check_for_patches_response}
/// The response body for POST /api/v1/patches/check
/// {@endtemplate}
@JsonSerializable(createFactory: false)
class CheckForPatchesResponse {
/// {@macro check_for_patches_response}
const CheckForPatchesResponse({required this.patchAvailable, this.patch});

/// Converts a [CheckForPatchesResponse] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$CheckForPatchesResponseToJson(this);

/// Whether a patch is available.
final bool patchAvailable;

/// The patch metadata.
final PatchMetadata? patch;
}

/// {@template patch_metadata}
/// Patch metadata represents the contents of an update (patch) for a specific
/// platform and architecture.
/// {@endtemplate}
@JsonSerializable(createFactory: false)
class PatchMetadata {
/// {@macro patch_metadata}
const PatchMetadata({
required this.number,
required this.downloadUrl,
required this.hash,
});

/// Converts an [PatchMetadata] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$PatchMetadataToJson(this);

/// The patch number associated with the artifact.
final int number;

/// The URL of the artifact.
final String downloadUrl;

/// The hash of the artifact.
final String hash;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'create_app_request.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:json_annotation/json_annotation.dart';

part 'create_app_request.g.dart';

/// {@template create_app_request}
/// The request body for POST /api/v1/apps
/// {@endtemplate}
@JsonSerializable()
class CreateAppRequest {
/// {@macro create_app_request}
const CreateAppRequest({required this.displayName});

/// Converts a Map<String, dynamic> to a [CreateAppRequest]
factory CreateAppRequest.fromJson(Map<String, dynamic> json) =>
_$CreateAppRequestFromJson(json);

/// Converts a [CreateAppRequest] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$CreateAppRequestToJson(this);

/// The display name of the app.
final String displayName;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'create_artifact_request.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';

part 'create_artifact_request.g.dart';

/// {@template create_artifact_request}
/// The request body for POST /api/v1/artifacts
/// {@endtemplate}
@JsonSerializable()
class CreateArtifactRequest {
/// {@macro create_artifact_request}
const CreateArtifactRequest({
required this.arch,
required this.platform,
required this.hash,
required this.size,
});

/// Converts a Map<String, dynamic> to a [CreateArtifactRequest]
factory CreateArtifactRequest.fromJson(Map<String, dynamic> json) =>
_$CreateArtifactRequestFromJson(json);

/// Converts a [CreateArtifactRequest] to a Map<String, dynamic>.
Json toJson() => _$CreateArtifactRequestToJson(this);

/// 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.
@JsonKey(fromJson: _parseStringToInt, toJson: _parseIntToString)
final int size;

static int _parseStringToInt(dynamic value) => int.parse(value as String);

static String _parseIntToString(dynamic value) => value.toString();
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading