Skip to content

Commit

Permalink
chore: Improving formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisebas committed Sep 11, 2024
1 parent 1903145 commit 518a53e
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ extension CognitoIdentityProviderClientTypes.CodeDeliveryDetailsType: Decodable
let container = try decoder.container(keyedBy: CodingKeys.self)
try self.init(
attributeName: container.decodeIfPresent(String.self, forKey: .attributeName),
deliveryMedium: container.decodeIfPresent(CognitoIdentityProviderClientTypes.DeliveryMediumType.self, forKey: .deliveryMedium),
deliveryMedium: container.decodeIfPresent(
CognitoIdentityProviderClientTypes.DeliveryMediumType.self,
forKey: .deliveryMedium
),
destination: container.decodeIfPresent(String.self, forKey: .destination)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ extension CognitoIdentityProviderClientTypes.AuthenticationResultType: Decodable
accessToken: container.decodeIfPresent(String.self, forKey: .accessToken),
expiresIn: container.decode(Int.self, forKey: .expiresIn),
idToken: container.decodeIfPresent(String.self, forKey: .idToken),
newDeviceMetadata: container.decodeIfPresent(CognitoIdentityProviderClientTypes.NewDeviceMetadataType.self, forKey: .newDeviceMetadata),
newDeviceMetadata: container.decodeIfPresent(
CognitoIdentityProviderClientTypes.NewDeviceMetadataType.self,
forKey: .newDeviceMetadata
),
refreshToken: container.decodeIfPresent(String.self, forKey: .refreshToken),
tokenType: container.decodeIfPresent(String.self, forKey: .tokenType)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import AWSPinpoint
import Foundation

extension PinpointClientTypes.EndpointLocation: Codable, Equatable {
private enum CodingKeys: CodingKey {
Expand All @@ -18,7 +18,10 @@ extension PinpointClientTypes.EndpointLocation: Codable, Equatable {
case region
}

public static func == (lhs: PinpointClientTypes.EndpointLocation, rhs: PinpointClientTypes.EndpointLocation) -> Bool {
public static func == (
lhs: PinpointClientTypes.EndpointLocation,
rhs: PinpointClientTypes.EndpointLocation
) -> Bool {
return lhs.city == rhs.city
&& lhs.country == rhs.country
&& lhs.latitude == rhs.latitude
Expand Down Expand Up @@ -62,7 +65,10 @@ extension PinpointClientTypes.EndpointDemographic: Codable, Equatable {
case timezone
}

public static func == (lhs: PinpointClientTypes.EndpointDemographic, rhs: PinpointClientTypes.EndpointDemographic) -> Bool {
public static func == (
lhs: PinpointClientTypes.EndpointDemographic,
rhs: PinpointClientTypes.EndpointDemographic
) -> Bool {
return lhs.appVersion == rhs.appVersion
&& lhs.locale == rhs.locale
&& lhs.make == rhs.make
Expand Down Expand Up @@ -97,7 +103,6 @@ extension PinpointClientTypes.EndpointDemographic: Codable, Equatable {
try container.encodeIfPresent(platform, forKey: .platform)
try container.encodeIfPresent(platformVersion, forKey: .platformVersion)
try container.encodeIfPresent(timezone, forKey: .timezone)

}
}

Expand All @@ -107,7 +112,10 @@ extension PinpointClientTypes.EndpointUser: Codable, Equatable {
case userId
}

public static func == (lhs: PinpointClientTypes.EndpointUser, rhs: PinpointClientTypes.EndpointUser) -> Bool {
public static func == (
lhs: PinpointClientTypes.EndpointUser,
rhs: PinpointClientTypes.EndpointUser
) -> Bool {
return lhs.userAttributes == rhs.userAttributes
&& lhs.userId == rhs.userId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@

import Foundation

/// Conforming to this protocol automatically adds support to "prettify" the type when printing its value.
protocol AmplifyStringConvertible: CustomStringConvertible {}

extension AmplifyStringConvertible {
public var description: String {
return prettyDescription(for: self)
}

private func prettyDescription(for object: Any, level: UInt = 1) -> String {
private func prettyDescription(
for object: Any,
level: UInt = 1
) -> String {
return prettyDescription(for: object, level: level) { result, indentation in
switch object {
case let dictionary as Dictionary<AnyHashable, Any>:
// Dictionaries follow the format: "<key>": <value>
for (key, value) in dictionary {
result.append(contentsOf: "\n\(indentation)\"\(key)\": \(description(for: value, withLevel: level)),")
result.append(
contentsOf: "\n\(indentation)\"\(key)\": \(description(for: value, withLevel: level)),"
)
}
case let collection as any Collection:
// Other collections follow the format: <value_1>, <value_2>, ..., <value_n>
Expand All @@ -31,13 +37,19 @@ extension AmplifyStringConvertible {
// Other objects follow the format: <attribute>: <value>
for child in Mirror(reflecting: object).children {
guard let label = child.label else { continue }
result.append(contentsOf: "\n\(indentation)\(label): \(description(for: child.value, withLevel: level)),")
result.append(
contentsOf: "\n\(indentation)\(label): \(description(for: child.value, withLevel: level)),"
)
}
}
}
}

private func prettyDescription(for object: Any, level: UInt = 1, contentsBuilder: (_ result: inout String, _ indentation: String) -> Void) -> String {
private func prettyDescription(
for object: Any,
level: UInt = 1,
contentsBuilder: (_ result: inout String, _ indentation: String) -> Void
) -> String {
var contents = ""
contentsBuilder(&contents, indentation(forLevel: level))
if contents.isEmpty {
Expand All @@ -52,8 +64,11 @@ extension AmplifyStringConvertible {
)
}

private func description(for value: Any, withLevel level: UInt) -> String {
let unwrappedValue = unwrappedValue(from: value) // This is to prevent Optionals from printing with the <Optional> prefix
private func description(
for value: Any,
withLevel level: UInt
) -> String {
let unwrappedValue = unwrappedValue(from: value)
switch unwrappedValue {
case let stringValue as String:
return stringValue.quoted
Expand Down Expand Up @@ -100,7 +115,11 @@ extension AmplifyStringConvertible {
}
}

private func appendClosingTag(_ tag: String, to value: String, currentLevel level: UInt) -> String {
private func appendClosingTag(
_ tag: String,
to value: String,
currentLevel level: UInt
) -> String {
// Remove the last comma
let result = value.hasSuffix(",") ? String(value.dropLast()) : value
// As we're adding a closing tag, reduce one indentation level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import AWSTranscribeStreaming
import Foundation

extension TranscribeStreamingClientTypes.TranscriptEvent: Decodable {
private enum CodingKeys: String, CodingKey {
Expand All @@ -16,7 +16,10 @@ extension TranscribeStreamingClientTypes.TranscriptEvent: Decodable {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
try self.init(
transcript: container.decode(TranscribeStreamingClientTypes.Transcript.self, forKey: .transcript)
transcript: container.decode(
TranscribeStreamingClientTypes.Transcript.self,
forKey: .transcript
)
)
}
}
Expand Down Expand Up @@ -49,12 +52,21 @@ extension TranscribeStreamingClientTypes.Result: Decodable {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
try self.init(
alternatives: container.decodeIfPresent([TranscribeStreamingClientTypes.Alternative].self, forKey: .alternatives),
alternatives: container.decodeIfPresent(
[TranscribeStreamingClientTypes.Alternative].self,
forKey: .alternatives
),
channelId: container.decodeIfPresent(String.self, forKey: .channelId),
endTime: container.decode(Double.self, forKey: .endTime),
isPartial: container.decode(Bool.self, forKey: .isPartial),
languageCode: container.decodeIfPresent(TranscribeStreamingClientTypes.LanguageCode.self, forKey: .languageCode),
languageIdentification: container.decodeIfPresent([TranscribeStreamingClientTypes.LanguageWithScore].self, forKey: .languageIdentification),
languageCode: container.decodeIfPresent(
TranscribeStreamingClientTypes.LanguageCode.self,
forKey: .languageCode
),
languageIdentification: container.decodeIfPresent(
[TranscribeStreamingClientTypes.LanguageWithScore].self,
forKey: .languageIdentification
),
resultId: container.decodeIfPresent(String.self, forKey: .resultId),
startTime: container.decode(Double.self, forKey: .startTime)
)
Expand All @@ -71,8 +83,14 @@ extension TranscribeStreamingClientTypes.Alternative: Decodable {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
try self.init(
entities: container.decodeIfPresent([TranscribeStreamingClientTypes.Entity].self, forKey: .entities),
items: container.decodeIfPresent([TranscribeStreamingClientTypes.Item].self, forKey: .items),
entities: container.decodeIfPresent(
[TranscribeStreamingClientTypes.Entity].self,
forKey: .entities
),
items: container.decodeIfPresent(
[TranscribeStreamingClientTypes.Item].self,
forKey: .items
),
transcript: container.decodeIfPresent(String.self, forKey: .transcript)
)
}
Expand Down Expand Up @@ -137,7 +155,10 @@ extension TranscribeStreamingClientTypes.LanguageWithScore: Decodable {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
try self.init(
languageCode: container.decodeIfPresent(TranscribeStreamingClientTypes.LanguageCode.self, forKey: .languageCode),
languageCode: container.decodeIfPresent(
TranscribeStreamingClientTypes.LanguageCode.self,
forKey: .languageCode
),
score: container.decode(Double.self, forKey: .score)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import SmithyRetries
// swiftlint:disable identifier_name
// swiftlint:disable line_length
extension UploadPartInput {
public func customPresignURL(config: S3Client.S3ClientConfiguration, expiration: Foundation.TimeInterval) async throws -> Foundation.URL? {
func customPresignURL(
config: S3Client.S3ClientConfiguration,
expiration: Foundation.TimeInterval
) async throws -> Foundation.URL? {
let serviceName = "S3"
let input = self
let client: (SmithyHTTPAPI.HTTPRequest, Smithy.Context) async throws -> SmithyHTTPAPI.HTTPResponse = { (_, _) in
Expand Down Expand Up @@ -86,7 +89,11 @@ struct UploadPartPresignedMiddleware: Smithy.RequestMessageSerializer {

let id: Swift.String = "UploadPartPresignedMiddleware"

func apply(input: InputType, builder: SmithyHTTPAPI.HTTPRequestBuilder, attributes: Smithy.Context) throws {
func apply(
input: InputType,
builder: SmithyHTTPAPI.HTTPRequestBuilder,
attributes: Smithy.Context
) throws {
builder.withQueryItem(.init(
name: "x-id",
value: "UploadPart")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class StorageMultipartUploadSession {
private let onEvent: AWSS3StorageServiceBehavior.StorageServiceMultiPartUploadEventHandler

private let transferTask: StorageTransferTask
private var cancelationFailure: (any Error)?
private var cancelationError: (any Error)? = nil

init(client: StorageMultipartUploadClient,
bucket: String,
Expand Down Expand Up @@ -247,14 +247,10 @@ class StorageMultipartUploadSession {
case .completed:
onEvent(.completed(()))
case .aborting(_, let error):
cancelationFailure = error
cancelationError = error
try abort()
case .aborted(_, let error):
if let cancelationFailure {
onEvent(.failed(StorageError(error: cancelationFailure)))
} else {
onEvent(.failed(StorageError.unknown("Unable to upload", error)))
}
onEvent(.failed(StorageError.unknown("Unable to upload", cancelationError ?? error)))
case .failed(_, _, let error):
onEvent(.failed(StorageError(error: error)))
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate {
if response.isErrorRetriable {
logURLSessionActivity("Task can be retried.")
}
// For multipart uploads, we need to handle the upload part failure

// For multipart uploads, we need to handle the upload part failure when the session is not aborted
if case .multiPartUploadPart(let uploadId, let partNumber) = transferTask.transferType,
let multipartUploadSession = storageService.findMultipartUploadSession(uploadId: uploadId),
!multipartUploadSession.isAborted {
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ let predictionsTargets: [Target] = [
name: "AWSPredictionsPluginUnitTests",
dependencies: ["AWSPredictionsPlugin"],
path: "AmplifyPlugins/Predictions/Tests/AWSPredictionsPluginUnitTests",
resources: [.copy("TestResources/TestImages")]
resources: [.copy("TestResources/TestImages") ]
),
.target(
name: "CoreMLPredictionsPlugin",
Expand Down

0 comments on commit 518a53e

Please sign in to comment.