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!: Conceal serde types with Swift SPI #805

Merged
merged 11 commits into from
Sep 3, 2024
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let package = Package(
),
.target(
name: "SmithyReadWrite",
dependencies: ["SmithyTimestamps"]
dependencies: ["Smithy", "SmithyTimestamps"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ByteStream is now in the Smithy module, SmithyReadWrite takes a dependency on Smithy and provides its own read-write implementation for ByteStream.

),
.target(
name: "SmithyXML",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import class SmithyHTTPAPI.HTTPResponse
Copy link
Contributor Author

@jbelkins jbelkins Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below you will see that many declarations and imports of those declarations are tagged with @_spi(...) to prevent them from showing up as public API.

I will not comment on the rest of these type of changes below.

import enum Smithy.ByteStream
import protocol SmithyReadWrite.WireDataProviding
@_spi(SmithyReadWrite) import protocol SmithyReadWrite.WireDataProviding
import struct Foundation.Data

@_spi(SmithyReadWrite)
extension HTTPResponse: WireDataProviding {

public func data() async throws -> Data {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SmithyHTTPAPI
import SmithyReadWrite
@_spi(SmithyReadWrite) import SmithyReadWrite
import class Foundation.DateFormatter
import struct Foundation.Locale
import struct Foundation.TimeInterval
Expand All @@ -15,6 +15,7 @@ import struct Foundation.UUID
import class Smithy.Context
import protocol Smithy.ResponseMessageDeserializer

@_spi(SmithyReadWrite)
public struct DeserializeMiddleware<OperationStackOutput> {
public var id: String = "Deserialize"
let wireResponseClosure: WireResponseOutputClosure<HTTPResponse, OperationStackOutput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import Smithy
import SmithyHTTPAPI
import struct Foundation.Data
import protocol SmithyReadWrite.SmithyWriter
import typealias SmithyReadWrite.WritingClosure
@_spi(SmithyReadWrite) import protocol SmithyReadWrite.SmithyWriter
@_spi(SmithyReadWrite) import typealias SmithyReadWrite.WritingClosure

@_spi(SmithyReadWrite)
public struct BodyMiddleware<OperationStackInput,
OperationStackOutput,
Writer: SmithyWriter> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SmithyEventStreams
import SmithyEventStreamsAPI
import SmithyEventStreamsAuthAPI
import struct Foundation.Data
import typealias SmithyReadWrite.WritingClosure
@_spi(SmithyReadWrite) import typealias SmithyReadWrite.WritingClosure
import SmithyHTTPAPI

public struct EventStreamBodyMiddleware<OperationStackInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import enum Smithy.ClientError
import protocol Smithy.RequestMessageSerializer
import class Smithy.Context
import struct Foundation.Data
import protocol SmithyReadWrite.SmithyWriter
import typealias SmithyReadWrite.WritingClosure
@_spi(SmithyReadWrite) import protocol SmithyReadWrite.SmithyWriter
@_spi(SmithyReadWrite) import typealias SmithyReadWrite.WritingClosure
import SmithyHTTPAPI

@_spi(SmithyReadWrite)
public struct PayloadBodyMiddleware<OperationStackInput,
OperationStackOutput,
OperationStackInputPayload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
// SPDX-License-Identifier: Apache-2.0
//

import struct SmithyTimestamps.TimestampFormatter
import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import struct SmithyTimestamps.TimestampFormatter
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat

@_spi(SmithyTimestamps)
public typealias TimestampFormatter = SmithyTimestamps.TimestampFormatter

@_spi(SmithyTimestamps)
public typealias TimestampFormat = SmithyTimestamps.TimestampFormat

This file was deleted.

7 changes: 4 additions & 3 deletions Sources/SmithyFormURL/Writer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol SmithyReadWrite.SmithyWriter
@_spi(SmithyReadWrite) import protocol SmithyReadWrite.SmithyWriter
import enum SmithyReadWrite.Document
import enum SmithyTimestamps.TimestampFormat
import struct SmithyTimestamps.TimestampFormatter
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import struct SmithyTimestamps.TimestampFormatter
import struct Foundation.Data
import struct Foundation.Date
import struct Foundation.CharacterSet

@_spi(SmithyReadWrite)
public final class Writer: SmithyWriter {
public typealias NodeInfo = SmithyFormURL.NodeInfo

Expand Down
7 changes: 4 additions & 3 deletions Sources/SmithyJSON/Reader/Reader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol SmithyReadWrite.SmithyReader
@_spi(SmithyReadWrite) import protocol SmithyReadWrite.SmithyReader
import enum SmithyReadWrite.Document
import typealias SmithyReadWrite.ReadingClosure
import enum SmithyReadWrite.ReaderError
import enum SmithyTimestamps.TimestampFormat
import struct SmithyTimestamps.TimestampFormatter
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import struct SmithyTimestamps.TimestampFormatter
import struct Foundation.Data
import struct Foundation.Date
import class Foundation.NSNull
import class Foundation.NSNumber
import func CoreFoundation.CFGetTypeID
import func CoreFoundation.CFBooleanGetTypeID

@_spi(SmithyReadWrite)
public final class Reader: SmithyReader {
public typealias NodeInfo = SmithyJSON.NodeInfo

Expand Down
7 changes: 4 additions & 3 deletions Sources/SmithyJSON/Writer/Writer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol SmithyReadWrite.SmithyWriter
@_spi(SmithyReadWrite) import protocol SmithyReadWrite.SmithyWriter
import enum SmithyReadWrite.Document
import enum SmithyTimestamps.TimestampFormat
import struct SmithyTimestamps.TimestampFormatter
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import struct SmithyTimestamps.TimestampFormatter
import struct Foundation.Data
import struct Foundation.Date
import class Foundation.NSNumber

@_spi(SmithyReadWrite)
public final class Writer: SmithyWriter {
public typealias NodeInfo = SmithyJSON.NodeInfo

Expand Down
1 change: 1 addition & 0 deletions Sources/SmithyReadWrite/DataProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import struct Foundation.Data

@_spi(SmithyReadWrite)
public protocol WireDataProviding: AnyObject {

func data() async throws -> Data
Expand Down
12 changes: 11 additions & 1 deletion Sources/SmithyReadWrite/ReadingClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import struct Foundation.Data
import struct Foundation.Date
import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat

@_spi(SmithyReadWrite)
public typealias ReadingClosure<T, Reader> = (Reader) throws -> T

@_spi(SmithyReadWrite)
public func mapReadingClosure<T, Reader: SmithyReader>(
valueReadingClosure: @escaping ReadingClosure<T, Reader>,
keyNodeInfo: Reader.NodeInfo,
Expand All @@ -27,6 +29,7 @@ public func mapReadingClosure<T, Reader: SmithyReader>(
}
}

@_spi(SmithyReadWrite)
public func mapReadingClosure<T, Reader: SmithyReader>(
valueReadingClosure: @escaping ReadingClosure<T, Reader>,
keyNodeInfo: Reader.NodeInfo,
Expand All @@ -43,6 +46,7 @@ public func mapReadingClosure<T, Reader: SmithyReader>(
}
}

@_spi(SmithyReadWrite)
public func listReadingClosure<T, Reader: SmithyReader>(
memberReadingClosure: @escaping ReadingClosure<T, Reader>,
memberNodeInfo: Reader.NodeInfo,
Expand All @@ -57,6 +61,7 @@ public func listReadingClosure<T, Reader: SmithyReader>(
}
}

@_spi(SmithyReadWrite)
public func listReadingClosure<T, Reader: SmithyReader>(
memberReadingClosure: @escaping ReadingClosure<T, Reader>,
memberNodeInfo: Reader.NodeInfo,
Expand All @@ -71,18 +76,21 @@ public func listReadingClosure<T, Reader: SmithyReader>(
}
}

@_spi(SmithyReadWrite)
public func timestampReadingClosure<Reader: SmithyReader>(format: TimestampFormat) -> ReadingClosure<Date, Reader> {
return { reader in
try reader.readTimestamp(format: format)
}
}

@_spi(SmithyReadWrite)
public func timestampReadingClosure<Reader: SmithyReader>(format: TimestampFormat) -> ReadingClosure<Date?, Reader> {
return { reader in
try reader.readTimestampIfPresent(format: format)
}
}

@_spi(SmithyReadWrite)
public struct ReadingClosureBox<Value: RawRepresentable> {

public init() {}
Expand All @@ -104,6 +112,7 @@ public struct ReadingClosureBox<Value: RawRepresentable> {
}
}

@_spi(SmithyReadWrite)
public enum ReadingClosures {

public static func readString<Reader: SmithyReader>(from reader: Reader) throws -> String {
Expand Down Expand Up @@ -163,6 +172,7 @@ public enum ReadingClosures {
}
}

@_spi(SmithyReadWrite)
public func optionalFormOf<T, Reader: SmithyReader>(
readingClosure: @escaping ReadingClosure<T, Reader>
) -> ReadingClosure<T?, Reader> {
Expand Down
3 changes: 2 additions & 1 deletion Sources/SmithyReadWrite/SmithyReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import struct Foundation.Data
import struct Foundation.Date
import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat

@_spi(SmithyReadWrite)
public protocol SmithyReader: AnyObject {
associatedtype NodeInfo

Expand Down
15 changes: 14 additions & 1 deletion Sources/SmithyReadWrite/SmithyWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import struct Foundation.Data
import struct Foundation.Date
import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat
import enum Smithy.ByteStream

@_spi(SmithyReadWrite)
public protocol SmithyWriter: AnyObject {
associatedtype NodeInfo

Expand Down Expand Up @@ -47,6 +49,17 @@ public protocol SmithyWriter: AnyObject {

public extension SmithyWriter {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function below was moved here from ClientRuntime since ByteStream now resides in Smithy module.

func write(_ value: ByteStream?) throws {
// This serialization will never be performed in practice, since
// a ByteStream will never be a part of
// a XML body - if there is a streaming member in a restXml
// input shape, the rest of the input members must all be bound
// to HTML components outside the body.
//
// This empty implementation is only provided to quiet the
// compiler when a structure with a ByteSteam is code-generated.
}

static func write<T>(
_ value: T,
rootNodeInfo: NodeInfo,
Expand Down
1 change: 1 addition & 0 deletions Sources/SmithyReadWrite/WireResponseErrorClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
//

/// Defines a closure that can be used to convert a wire response to a Swift `Error`.
@_spi(SmithyReadWrite)
public typealias WireResponseErrorClosure<WireResponse> = (WireResponse) async throws -> Error
1 change: 1 addition & 0 deletions Sources/SmithyReadWrite/WireResponseOutputClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
//

/// Defines a closure that can be used to convert a wire response to an output value.
@_spi(SmithyReadWrite)
public typealias WireResponseOutputClosure<WireResponse, OperationStackOutput> =
(WireResponse) async throws -> OperationStackOutput
9 changes: 8 additions & 1 deletion Sources/SmithyReadWrite/WritingClosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import struct Foundation.Data
import struct Foundation.Date
import enum SmithyTimestamps.TimestampFormat
@_spi(SmithyTimestamps) import enum SmithyTimestamps.TimestampFormat

@_spi(SmithyReadWrite)
public typealias WritingClosure<T, Writer> = (T, Writer) throws -> Void

@_spi(SmithyReadWrite)
public func mapWritingClosure<T, Writer: SmithyWriter>(
valueWritingClosure: @escaping WritingClosure<T, Writer>,
keyNodeInfo: Writer.NodeInfo,
Expand All @@ -28,6 +30,7 @@ public func mapWritingClosure<T, Writer: SmithyWriter>(
}
}

@_spi(SmithyReadWrite)
public func listWritingClosure<T, Writer: SmithyWriter>(
memberWritingClosure: @escaping WritingClosure<T, Writer>,
memberNodeInfo: Writer.NodeInfo,
Expand All @@ -43,12 +46,14 @@ public func listWritingClosure<T, Writer: SmithyWriter>(
}
}

@_spi(SmithyReadWrite)
public func timestampWritingClosure<Writer: SmithyWriter>(format: TimestampFormat) -> WritingClosure<Date, Writer> {
return { date, writer in
try writer.writeTimestamp(date, format: format)
}
}

@_spi(SmithyReadWrite)
public struct WritingClosureBox<Value: RawRepresentable> {

public init() {}
Expand All @@ -62,6 +67,7 @@ public struct WritingClosureBox<Value: RawRepresentable> {
}
}

@_spi(SmithyReadWrite)
public enum WritingClosures {

public static func writeString<Writer: SmithyWriter>(value: String?, to writer: Writer) throws {
Expand Down Expand Up @@ -101,6 +107,7 @@ public enum WritingClosures {
}
}

@_spi(SmithyReadWrite)
public func sparseFormOf<T, Writer: SmithyWriter>(
writingClosure: @escaping WritingClosure<T?, Writer>
) -> WritingClosure<T?, Writer> {
Expand Down
3 changes: 2 additions & 1 deletion Sources/SmithyTestUtil/Errors/TestBaseError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import protocol ClientRuntime.BaseError
import enum ClientRuntime.BaseErrorDecodeError
import class SmithyHTTPAPI.HTTPResponse
import class SmithyJSON.Reader
@_spi(SmithyReadWrite) import class SmithyJSON.Reader

@_spi(SmithyReadWrite)
public struct TestBaseError: BaseError {
public let code: String
public let message: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import Smithy
import SmithyHTTPAPI
import SmithyReadWrite
@_spi(SmithyReadWrite) import SmithyReadWrite
import ClientRuntime

@_spi(SmithyReadWrite)
public struct MockDeserializeMiddleware<OperationStackOutput> {
public var id: String
let responseClosure: WireResponseOutputClosure<HTTPResponse, OperationStackOutput>
Expand Down
Loading
Loading