|
@@ -25,7 +25,9 @@ extension Generator {
|
|
|
self.println()
|
|
self.println()
|
|
|
self.printClientProtocolExtension()
|
|
self.printClientProtocolExtension()
|
|
|
self.println()
|
|
self.println()
|
|
|
- self.printServiceClientImplementation()
|
|
|
|
|
|
|
+ self.printClassBackedServiceClientImplementation()
|
|
|
|
|
+ self.println()
|
|
|
|
|
+ self.printStructBackedServiceClientImplementation()
|
|
|
self.println()
|
|
self.println()
|
|
|
self.printIfCompilerGuardForAsyncAwait()
|
|
self.printIfCompilerGuardForAsyncAwait()
|
|
|
self.printAsyncServiceClientProtocol()
|
|
self.printAsyncServiceClientProtocol()
|
|
@@ -157,7 +159,7 @@ extension Generator {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func printServiceClientInterceptorFactoryProtocol() {
|
|
private func printServiceClientInterceptorFactoryProtocol() {
|
|
|
- self.println("\(self.access) protocol \(self.clientInterceptorProtocolName) {")
|
|
|
|
|
|
|
+ self.println("\(self.access) protocol \(self.clientInterceptorProtocolName): GRPCSendable {")
|
|
|
self.withIndentation {
|
|
self.withIndentation {
|
|
|
// Method specific interceptors.
|
|
// Method specific interceptors.
|
|
|
for method in service.methods {
|
|
for method in service.methods {
|
|
@@ -186,10 +188,62 @@ extension Generator {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private func printServiceClientImplementation() {
|
|
|
|
|
|
|
+ private func printClassBackedServiceClientImplementation() {
|
|
|
|
|
+ self.printIfCompilerGuardForAsyncAwait()
|
|
|
|
|
+ self.println("@available(*, deprecated)")
|
|
|
|
|
+ self.println("extension \(clientClassName): @unchecked Sendable {}")
|
|
|
|
|
+ self.printEndCompilerGuardForAsyncAwait()
|
|
|
|
|
+ self.println()
|
|
|
|
|
+ self.println("@available(*, deprecated, renamed: \"\(clientStructName)\")")
|
|
|
println("\(access) final class \(clientClassName): \(clientProtocolName) {")
|
|
println("\(access) final class \(clientClassName): \(clientProtocolName) {")
|
|
|
self.withIndentation {
|
|
self.withIndentation {
|
|
|
|
|
+ println("private let lock = Lock()")
|
|
|
|
|
+ println("private var _defaultCallOptions: CallOptions")
|
|
|
|
|
+ println("private var _interceptors: \(clientInterceptorProtocolName)?")
|
|
|
|
|
+
|
|
|
println("\(access) let channel: GRPCChannel")
|
|
println("\(access) let channel: GRPCChannel")
|
|
|
|
|
+ println("\(access) var defaultCallOptions: CallOptions {")
|
|
|
|
|
+ self.withIndentation {
|
|
|
|
|
+ println("get { self.lock.withLock { return self._defaultCallOptions } }")
|
|
|
|
|
+ println("set { self.lock.withLockVoid { self._defaultCallOptions = newValue } }")
|
|
|
|
|
+ }
|
|
|
|
|
+ self.println("}")
|
|
|
|
|
+ println("\(access) var interceptors: \(clientInterceptorProtocolName)? {")
|
|
|
|
|
+ self.withIndentation {
|
|
|
|
|
+ println("get { self.lock.withLock { return self._interceptors } }")
|
|
|
|
|
+ println("set { self.lock.withLockVoid { self._interceptors = newValue } }")
|
|
|
|
|
+ }
|
|
|
|
|
+ println("}")
|
|
|
|
|
+ println()
|
|
|
|
|
+ println("/// Creates a client for the \(servicePath) service.")
|
|
|
|
|
+ println("///")
|
|
|
|
|
+ self.printParameters()
|
|
|
|
|
+ println("/// - channel: `GRPCChannel` to the service host.")
|
|
|
|
|
+ println(
|
|
|
|
|
+ "/// - defaultCallOptions: Options to use for each service call if the user doesn't provide them."
|
|
|
|
|
+ )
|
|
|
|
|
+ println("/// - interceptors: A factory providing interceptors for each RPC.")
|
|
|
|
|
+ println("\(access) init(")
|
|
|
|
|
+ self.withIndentation {
|
|
|
|
|
+ println("channel: GRPCChannel,")
|
|
|
|
|
+ println("defaultCallOptions: CallOptions = CallOptions(),")
|
|
|
|
|
+ println("interceptors: \(clientInterceptorProtocolName)? = nil")
|
|
|
|
|
+ }
|
|
|
|
|
+ self.println(") {")
|
|
|
|
|
+ self.withIndentation {
|
|
|
|
|
+ println("self.channel = channel")
|
|
|
|
|
+ println("self._defaultCallOptions = defaultCallOptions")
|
|
|
|
|
+ println("self._interceptors = interceptors")
|
|
|
|
|
+ }
|
|
|
|
|
+ self.println("}")
|
|
|
|
|
+ }
|
|
|
|
|
+ println("}")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func printStructBackedServiceClientImplementation() {
|
|
|
|
|
+ println("\(access) struct \(clientStructName): \(clientProtocolName) {")
|
|
|
|
|
+ self.withIndentation {
|
|
|
|
|
+ println("\(access) var channel: GRPCChannel")
|
|
|
println("\(access) var defaultCallOptions: CallOptions")
|
|
println("\(access) var defaultCallOptions: CallOptions")
|
|
|
println("\(access) var interceptors: \(clientInterceptorProtocolName)?")
|
|
println("\(access) var interceptors: \(clientInterceptorProtocolName)?")
|
|
|
println()
|
|
println()
|
|
@@ -480,15 +534,23 @@ extension Generator {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func printTestClient() {
|
|
private func printTestClient() {
|
|
|
- self
|
|
|
|
|
- .println(
|
|
|
|
|
- "\(self.access) final class \(self.testClientClassName): \(self.clientProtocolName) {"
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ self.printIfCompilerGuardForAsyncAwait()
|
|
|
|
|
+ self.println("@available(swift, deprecated: 5.6)")
|
|
|
|
|
+ self.println("extension \(self.testClientClassName): @unchecked Sendable {}")
|
|
|
|
|
+ self.printEndCompilerGuardForAsyncAwait()
|
|
|
|
|
+ self.println()
|
|
|
|
|
+ self.println(
|
|
|
|
|
+ "@available(swift, deprecated: 5.6, message: \"Test clients are not Sendable "
|
|
|
|
|
+ + "but the 'GRPCClient' API requires clients to be Sendable. Using a localhost client and "
|
|
|
|
|
+ + "server is the recommended alternative.\")"
|
|
|
|
|
+ )
|
|
|
|
|
+ self.println(
|
|
|
|
|
+ "\(self.access) final class \(self.testClientClassName): \(self.clientProtocolName) {"
|
|
|
|
|
+ )
|
|
|
self.withIndentation {
|
|
self.withIndentation {
|
|
|
self.println("private let fakeChannel: FakeChannel")
|
|
self.println("private let fakeChannel: FakeChannel")
|
|
|
- self.println("\(self.access) var defaultCallOptions: CallOptions")
|
|
|
|
|
- self.println("\(self.access) var interceptors: \(self.clientInterceptorProtocolName)?")
|
|
|
|
|
-
|
|
|
|
|
|
|
+ self.println("\(access) var defaultCallOptions: CallOptions")
|
|
|
|
|
+ self.println("\(access) var interceptors: \(clientInterceptorProtocolName)?")
|
|
|
self.println()
|
|
self.println()
|
|
|
self.println("\(self.access) var channel: GRPCChannel {")
|
|
self.println("\(self.access) var channel: GRPCChannel {")
|
|
|
self.withIndentation {
|
|
self.withIndentation {
|