-
Notifications
You must be signed in to change notification settings - Fork 31
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!: Closure-based reader-writer serde for JSON, FormURL #696
Changes from all commits
3ee7e8d
0a6cbb5
255be51
ef6afbc
1b71f03
1042248
e4958ba
b6ea1d8
e2d41a6
7bb92f5
9d8090f
c0be78e
70eb9c7
9049fbf
7766c88
d8511a3
ce56c31
a6f6a96
d8158b5
0d3ebf1
0cb4b04
6ada476
7655987
23248ea
19fb75d
77ac55f
8b4212f
efdabef
54498c3
73b1ae3
3ec9818
74051e3
ecd9c94
9b643b8
a76bed8
a2f8612
975c2d6
a3caac2
05ecd95
b1d6f94
9a2a983
7ca1ebf
70f18e1
12f1ed1
9ffbd39
8a4df3e
cf6b8ab
126195e
39e539b
c8c6aa2
84721ae
6eef981
05d6d33
3bd83cc
042b734
532977b
0a35bdf
3bd533a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,6 @@ public struct DefaultSDKRuntimeConfiguration<DefaultSDKRuntimeRetryStrategy: Ret | |
/// The name of the client this config configures. | ||
public var clientName: String | ||
|
||
/// The encoder to be used for encoding models. | ||
/// | ||
/// If none is provided, a default encoder will be used. | ||
public var encoder: RequestEncoder? | ||
|
||
/// The decoder to be used for decoding models. | ||
/// | ||
/// If none is provided, a default decoder will be used. | ||
public var decoder: ResponseDecoder? | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encoders/decoders are no longer used & are removed from config. |
||
/// The HTTP client to be used for HTTP connections. | ||
/// | ||
/// If none is provided, the AWS CRT HTTP client will be used. | ||
|
@@ -70,8 +60,6 @@ public struct DefaultSDKRuntimeConfiguration<DefaultSDKRuntimeRetryStrategy: Ret | |
) throws { | ||
self.serviceName = clientName | ||
self.clientName = clientName | ||
self.encoder = nil | ||
self.decoder = nil | ||
self.httpClientConfiguration = Self.defaultHttpClientConfiguration | ||
self.httpClientEngine = Self.makeClient(httpClientConfiguration: self.httpClientConfiguration) | ||
self.idempotencyTokenGenerator = Self.defaultIdempotencyTokenGenerator | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import struct Foundation.Data | |
|
||
extension EventStream { | ||
/// Stream adapter that encodes input into `Data` objects. | ||
public class DefaultMessageEncoderStream<Event: MessageMarshallable>: MessageEncoderStream, Stream { | ||
public class DefaultMessageEncoderStream<Event>: MessageEncoderStream, Stream { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
let stream: AsyncThrowingStream<Event, Error> | ||
let messageEncoder: MessageEncoder | ||
sichanyoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let messageSigner: MessageSigner | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,27 +5,4 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
/// Marshals an event stream event into a `Message`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
/// Codgegen generates a conformance to this protocol for each event stream event input. | ||
public protocol MessageMarshallable { | ||
/// Marshals a event stream event into a `Message`. | ||
/// - Parameters: | ||
/// - encoder: RequestEncoder to use to encode the event stream event. | ||
/// Note: event type may contain nested types that need to be encoded | ||
/// using the same encoder. | ||
/// - Returns: The marshalled `Message`. | ||
func marshall(encoder: RequestEncoder) throws -> EventStream.Message | ||
} | ||
|
||
public typealias MarshalClosure<T> = (T) throws -> (EventStream.Message) | ||
|
||
/// Provides a `MarshalClosure` for event payloads that are Swift `Encodable`. | ||
/// - Parameter requestEncoder: The Swift `Encoder` to be used for encoding this event payload. | ||
/// - Returns: A `MarshalClosure` that uses the provided encoder to encode event payloads. | ||
public func jsonMarshalClosure<T: MessageMarshallable>( | ||
requestEncoder: RequestEncoder | ||
) -> MarshalClosure<T> { | ||
return { eventStream in | ||
try eventStream.marshall(encoder: requestEncoder) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,4 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
/// Unmarshals a `Message` into a event stream event. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
/// Codgegen generates a conformance to this protocol for each event stream event output. | ||
public protocol MessageUnmarshallable { | ||
/// Unmarshals a `Message` into a event stream event. | ||
/// - Parameters: | ||
/// - message: The message to unmarshal. | ||
/// - decoder: ResponseDecoder to use to decode the event stream event. | ||
/// Note: event type may contain nested types that need to be decoded | ||
/// using the same decoder. | ||
init(message: EventStream.Message, decoder: ResponseDecoder) throws | ||
} | ||
|
||
public typealias UnmarshalClosure<T> = (EventStream.Message) throws -> T | ||
|
||
/// Provides an `UnmarshalClosure` for event payloads that are Swift `Decodable`. | ||
/// - Parameter responseDecoder: The Swift `Decoder` to be used for decoding this event payload. | ||
/// - Returns: An `UnmarshalClosure` that uses the provided decoder to decode event payloads. | ||
public func jsonUnmarshalClosure<T: MessageUnmarshallable>(responseDecoder: ResponseDecoder) -> UnmarshalClosure<T> { | ||
return { message in | ||
try T(message: message, decoder: responseDecoder) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
public protocol BaseError { | ||
var httpResponse: HttpResponse { get } | ||
var code: String { get } | ||
var message: String? { get } | ||
var requestID: String? { get } | ||
|
||
func customError() -> Error? | ||
} | ||
|
||
public extension BaseError { | ||
|
||
/// Returns a custom error from the error response, if any. | ||
/// | ||
/// By default, a `BaseError` returns no custom error unless | ||
/// the implementation provides its own implementation of this method. | ||
/// - Returns: Some custom `Error` or `nil` if none. | ||
func customError() -> Error? { nil } | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This protocol provides a way to expose info common to all service errors. Each AWS protocol provides a custom type that conforms to this protocol. There is also a "test" base error used by the WeatherSDK. |
||
|
||
public enum BaseErrorDecodeError: Error { | ||
case missingRequiredData | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,14 +37,6 @@ public class HttpContext: MiddlewareContext { | |
return attributes.get(key: AttributeKeys.isChunkedEligibleStream) | ||
} | ||
|
||
public func getDecoder() -> ResponseDecoder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encoders & decoders are no longer used, and removed from context objects. |
||
return attributes.get(key: AttributeKeys.decoder)! | ||
} | ||
|
||
public func getEncoder() -> RequestEncoder { | ||
return attributes.get(key: AttributeKeys.encoder)! | ||
} | ||
|
||
public func getExpiration() -> TimeInterval { | ||
return attributes.get(key: AttributeKeys.expiration) ?? 0 | ||
} | ||
|
@@ -178,18 +170,6 @@ public class HttpContextBuilder { | |
return self | ||
} | ||
|
||
@discardableResult | ||
public func withDecoder(value: ResponseDecoder) -> HttpContextBuilder { | ||
self.attributes.set(key: AttributeKeys.decoder, value: value) | ||
return self | ||
} | ||
|
||
@discardableResult | ||
public func withEncoder(value: RequestEncoder) -> HttpContextBuilder { | ||
self.attributes.set(key: AttributeKeys.encoder, value: value) | ||
return self | ||
} | ||
|
||
@discardableResult | ||
public func withExpiration(value: TimeInterval) -> HttpContextBuilder { | ||
self.attributes.set(key: AttributeKeys.expiration, value: value) | ||
|
@@ -329,8 +309,6 @@ public enum AttributeKeys { | |
public static let authSchemeResolver = AttributeKey<AuthSchemeResolver>(name: "AuthSchemeResolver") | ||
public static let authSchemes = AttributeKey<Attributes>(name: "AuthSchemes") | ||
public static let bidirectionalStreaming = AttributeKey<Bool>(name: "BidirectionalStreaming") | ||
public static let decoder = AttributeKey<ResponseDecoder>(name: "Decoder") | ||
public static let encoder = AttributeKey<RequestEncoder>(name: "Encoder") | ||
public static let flowType = AttributeKey<FlowType>(name: "FlowType") | ||
public static let host = AttributeKey<String>(name: "Host") | ||
public static let hostPrefix = AttributeKey<String>(name: "HostPrefix") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import protocol SmithyReadWrite.WireDataProviding | ||
import AwsCommonRuntimeKit | ||
|
||
public class HttpResponse: HttpUrlResponse, ResponseMessage { | ||
|
@@ -32,6 +36,15 @@ extension HttpResponse: CustomDebugStringConvertible { | |
} | ||
} | ||
|
||
extension HttpResponse: WireDataProviding { | ||
|
||
public func data() async throws -> Data { | ||
let data = try await body.readData() | ||
body = .data(data) | ||
return data ?? Data() | ||
} | ||
} | ||
|
||
extension ByteStream { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
// Convert the body stream to a ValidatingFileStream to check checksums | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create new Swift modules for the JSON and FormURL readers/writers.