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

feat(Core): Updating to AWS SDK for Swift 1.0.0 #3858

Merged
merged 11 commits into from
Sep 18, 2024
Prev Previous commit
Next Next commit
chore: Improving formatting
sebaland committed Sep 17, 2024

Verified

This commit was signed with the committer’s verified signature.
khaneliman Austin Horstman
commit 1e40bdac6993a576945bf239e9985a15b630fc3f
Original file line number Diff line number Diff line change
@@ -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)
)
}
Original file line number Diff line number Diff line change
@@ -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)
)
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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
@@ -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
@@ -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)

}
}

@@ -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
}
Original file line number Diff line number Diff line change
@@ -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>
@@ -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 {
@@ -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
@@ -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
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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
)
)
}
}
@@ -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)
)
@@ -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)
)
}
@@ -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)
)
}
Original file line number Diff line number Diff line change
@@ -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
@@ -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")
Original file line number Diff line number Diff line change
@@ -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,
@@ -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:
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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",