Skip to content
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
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ modifier_order:
- dynamic
- convenience
deployment_target:
iOS_deployment_target: 13.0
iOS_deployment_target: 12.0

custom_rules:
newline_after_brace:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ internal protocol Buf_Connect_Demo_Eliza_V1_ElizaServiceClientInterface {

/// Say is a unary request demo. This method should allow for a one sentence
/// response given a one sentence request.
@available(iOS 13, *)
func `say`(request: Buf_Connect_Demo_Eliza_V1_SayRequest, headers: Connect.Headers) async -> ResponseMessage<Buf_Connect_Demo_Eliza_V1_SayResponse>

/// Converse is a bi-directional streaming request demo. This method should allow for
/// many requests and many responses.
@available(iOS 13, *)
func `converse`(headers: Connect.Headers) -> any Connect.BidirectionalAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_ConverseRequest, Buf_Connect_Demo_Eliza_V1_ConverseResponse>

/// Introduce is a server-streaming request demo. This method allows for a single request that will return a series
/// of responses
@available(iOS 13, *)
func `introduce`(headers: Connect.Headers) -> any Connect.ServerOnlyAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_IntroduceRequest, Buf_Connect_Demo_Eliza_V1_IntroduceResponse>
}

Expand All @@ -36,14 +39,17 @@ internal final class Buf_Connect_Demo_Eliza_V1_ElizaServiceClient: Buf_Connect_D
self.client = client
}

@available(iOS 13, *)
internal func `say`(request: Buf_Connect_Demo_Eliza_V1_SayRequest, headers: Connect.Headers = [:]) async -> ResponseMessage<Buf_Connect_Demo_Eliza_V1_SayResponse> {
return await self.client.unary(path: "buf.connect.demo.eliza.v1.ElizaService/Say", request: request, headers: headers)
}

@available(iOS 13, *)
internal func `converse`(headers: Connect.Headers = [:]) -> any Connect.BidirectionalAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_ConverseRequest, Buf_Connect_Demo_Eliza_V1_ConverseResponse> {
return self.client.bidirectionalStream(path: "buf.connect.demo.eliza.v1.ElizaService/Converse", headers: headers)
}

@available(iOS 13, *)
internal func `introduce`(headers: Connect.Headers = [:]) -> any Connect.ServerOnlyAsyncStreamInterface<Buf_Connect_Demo_Eliza_V1_IntroduceRequest, Buf_Connect_Demo_Eliza_V1_IntroduceResponse> {
return self.client.serverOnlyStream(path: "buf.connect.demo.eliza.v1.ElizaService/Introduce", headers: headers)
}
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Connect/Implementation/ProtocolClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extension ProtocolClient: ProtocolClientInterface {

// MARK: - Async/await

@available(iOS 13, *)
public func unary<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand All @@ -173,6 +174,7 @@ extension ProtocolClient: ProtocolClientInterface {
}.send()
}

@available(iOS 13, *)
public func bidirectionalStream<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand All @@ -186,6 +188,7 @@ extension ProtocolClient: ProtocolClientInterface {
return bidirectionalAsync.configureForSending(with: callbacks)
}

@available(iOS 13, *)
public func clientOnlyStream<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand All @@ -199,6 +202,7 @@ extension ProtocolClient: ProtocolClientInterface {
return bidirectionalAsync.configureForSending(with: callbacks)
}

@available(iOS 13, *)
public func serverOnlyStream<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SwiftProtobuf
/// Concrete implementation of `BidirectionalAsyncStreamInterface`.
/// Provides the necessary wiring to bridge from closures/callbacks to Swift's `AsyncStream`
/// to work with async/await.
@available(iOS 13, *)
final class BidirectionalAsyncStream<Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message> {
/// The underlying async stream that will be exposed to the consumer.
/// Force unwrapped because it captures `self` on `init`.
Expand Down Expand Up @@ -81,6 +82,7 @@ final class BidirectionalAsyncStream<Input: SwiftProtobuf.Message, Output: Swift
}
}

@available(iOS 13, *)
extension BidirectionalAsyncStream: BidirectionalAsyncStreamInterface {
@discardableResult
func send(_ input: Input) throws -> Self {
Expand All @@ -102,4 +104,5 @@ extension BidirectionalAsyncStream: BidirectionalAsyncStreamInterface {
}

// Conforms to the client-only interface since it matches exactly and the implementation is internal
@available(iOS 13, *)
extension BidirectionalAsyncStream: ClientOnlyAsyncStreamInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import SwiftProtobuf

/// Concrete implementation of `ServerOnlyAsyncStreamInterface`.
@available(iOS 13, *)
final class ServerOnlyAsyncStream<Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message> {
private let bidirectionalStream: BidirectionalAsyncStream<Input, Output>

Expand All @@ -23,6 +24,7 @@ final class ServerOnlyAsyncStream<Input: SwiftProtobuf.Message, Output: SwiftPro
}
}

@available(iOS 13, *)
extension ServerOnlyAsyncStream: ServerOnlyAsyncStreamInterface {
func send(_ input: Input) throws {
try self.bidirectionalStream.send(input)
Expand Down
1 change: 1 addition & 0 deletions Libraries/Connect/Implementation/UnaryAsyncWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import SwiftProtobuf
/// For discussions on why this is necessary, see:
/// https://forums.swift.org/t/how-to-use-withtaskcancellationhandler-properly/54341/37
/// https://stackoverflow.com/q/71898080
@available(iOS 13, *)
actor UnaryAsyncWrapper<Output: SwiftProtobuf.Message> {
private var cancelable: Cancelable?
private let sendUnary: PerformClosure
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Connect/Interfaces/ProtocolClientInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public protocol ProtocolClientInterface {
/// - parameter headers: The outbound request headers to include.
///
/// - returns: The response which is returned asynchronously.
@available(iOS 13, *)
func unary<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand All @@ -134,6 +135,7 @@ public protocol ProtocolClientInterface {
/// - parameter headers: The outbound request headers to include.
///
/// - returns: An interface for sending and receiving data over the stream using async/await.
@available(iOS 13, *)
func bidirectionalStream<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand All @@ -153,6 +155,7 @@ public protocol ProtocolClientInterface {
/// - parameter headers: The outbound request headers to include.
///
/// - returns: An interface for sending and receiving data over the stream using async/await.
@available(iOS 13, *)
func clientOnlyStream<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand All @@ -172,6 +175,7 @@ public protocol ProtocolClientInterface {
/// - parameter headers: The outbound request headers to include.
///
/// - returns: An interface for sending and receiving data over the stream using async/await.
@available(iOS 13, *)
func serverOnlyStream<
Input: SwiftProtobuf.Message, Output: SwiftProtobuf.Message
>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import SwiftProtobuf

/// Represents a bidirectional stream that can be interacted with using async/await.
@available(iOS 13, *)
public protocol BidirectionalAsyncStreamInterface<Input, Output> {
/// The input (request) message type.
associatedtype Input: SwiftProtobuf.Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SwiftProtobuf

/// Represents a client-only stream (a stream where the client streams data to the server and
/// eventually receives a response) that can be interacted with using async/await.
@available(iOS 13, *)
public protocol ClientOnlyAsyncStreamInterface<Input, Output> {
/// The input (request) message type.
associatedtype Input: SwiftProtobuf.Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SwiftProtobuf

/// Represents a server-only stream (a stream where the server streams data to the client after
/// receiving an initial request) that can be interacted with using async/await.
@available(iOS 13, *)
public protocol ServerOnlyAsyncStreamInterface<Input, Output> {
/// The input (request) message type.
associatedtype Input: SwiftProtobuf.Message
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import PackageDescription
let package = Package(
name: "Connect",
platforms: [
.iOS(.v14),
.iOS(.v12),
.macOS(.v10_15),
],
products: [
Expand Down
2 changes: 2 additions & 0 deletions Plugins/ConnectMocksPlugin/ConnectMockGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ final class ConnectMockGenerator: Generator {
self.printLine(
"/// Mocked for async calls to `\(method.name(using: self.options))()`."
)
self.printLine("@available(iOS 13, *)")
self.printLine(
"""
\(self.propertyVisibility) var \(method.asyncAwaitMockPropertyName()) = \
Expand Down Expand Up @@ -143,6 +144,7 @@ final class ConnectMockGenerator: Generator {
private func printAsyncAwaitMethodMockImplementation(for method: MethodDescriptor) {
self.printLine()

self.printLine("@available(iOS 13, *)")
self.printLine(
"\(self.typeVisibility) "
+ method.asyncAwaitSignature(
Expand Down
2 changes: 2 additions & 0 deletions Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ final class ConnectClientGenerator: Generator {
private func printAsyncAwaitMethodInterface(for method: MethodDescriptor) {
self.printLine()
self.printCommentsIfNeeded(for: method)
self.printLine("@available(iOS 13, *)")
self.printLine(
method.asyncAwaitSignature(
using: self.namer, includeDefaults: false, options: self.options
Expand Down Expand Up @@ -159,6 +160,7 @@ final class ConnectClientGenerator: Generator {

private func printAsyncAwaitMethodImplementation(for method: MethodDescriptor) {
self.printLine()
self.printLine("@available(iOS 13, *)")
self.printLine(
"\(self.visibility) "
+ method.asyncAwaitSignature(
Expand Down
Loading