Skip to content

Commit 9cf1ae5

Browse files
committed
Rename target to operation
1 parent 07c68ed commit 9cf1ae5

File tree

4 files changed

+64
-60
lines changed

4 files changed

+64
-60
lines changed

Sources/GRPCCore/Call/Server/ServerInterceptor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// been returned from a service. They are typically used for cross-cutting concerns like filtering
2222
/// requests, validating messages, logging additional data, and tracing.
2323
///
24-
/// Interceptors are registered with the server via ``ServerInterceptorTarget``s.
24+
/// Interceptors can be registered with the server either directly or via ``ServerInterceptorOperation``s.
2525
/// You may register them for all services registered with a server, for RPCs directed to specific services, or
2626
/// for RPCs directed to specific methods. If you need to modify the behavior of an interceptor on a
2727
/// per-RPC basis in more detail, then you can use the ``ServerContext/descriptor`` to determine

Sources/GRPCCore/Call/Server/ServerInterceptorTarget.swift renamed to Sources/GRPCCore/Call/Server/ServerInterceptorOperation.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@
1414
* limitations under the License.
1515
*/
1616

17-
/// A `ServerInterceptorTarget` describes to which RPCs a server interceptor should be applied.
17+
/// A `ServerInterceptorOperation` describes to which RPCs a server interceptor should be applied.
1818
///
1919
/// You can configure a server interceptor to be applied to:
2020
/// - all RPCs and services;
2121
/// - requests directed only to specific services registered with your server; or
2222
/// - requests directed only to specific methods (of a specific service).
2323
///
2424
/// - SeeAlso: ``ServerInterceptor`` for more information on server interceptors, and
25-
/// ``ClientInterceptorTarget`` for the client-side version of this type.
26-
public struct ServerInterceptorTarget: Sendable {
25+
/// ``ClientInterceptorOperation`` for the client-side version of this type.
26+
public struct ServerInterceptorOperation: Sendable {
2727
internal enum Wrapped: Sendable {
2828
case allServices(interceptor: any ServerInterceptor)
2929
case serviceSpecific(interceptor: any ServerInterceptor, services: [String])
3030
case methodSpecific(interceptor: any ServerInterceptor, methods: [MethodDescriptor])
3131
}
3232

33-
/// A target specifying an interceptor that applies to all RPCs across all services registered with this server.
33+
/// An operation specifying an interceptor that applies to all RPCs across all services will be registered with this server.
3434
/// - Parameter interceptor: The interceptor to register with the server.
35-
/// - Returns: A ``ServerInterceptorTarget``.
36-
public static func allServices(
37-
interceptor: any ServerInterceptor
35+
/// - Returns: A ``ServerInterceptorOperation``.
36+
public static func applyToAllServices(
37+
_ interceptor: any ServerInterceptor
3838
) -> Self {
3939
Self(wrapped: .allServices(interceptor: interceptor))
4040
}
4141

42-
/// A target specifying an interceptor that applies to RPCs directed only to the specified services.
42+
/// An operation specifying an interceptor that will be applied only to RPCs directed to the specified services.
4343
/// - Parameters:
4444
/// - interceptor: The interceptor to register with the server.
4545
/// - services: The list of service names for which this interceptor should intercept RPCs.
46-
/// - Returns: A ``ServerInterceptorTarget``.
47-
public static func serviceSpecific(
48-
interceptor: any ServerInterceptor,
49-
services: [String]
46+
/// - Returns: A ``ServerInterceptorOperation``.
47+
public static func apply(
48+
_ interceptor: any ServerInterceptor,
49+
onlyToServices services: [String]
5050
) -> Self {
5151
Self(
5252
wrapped: .serviceSpecific(
@@ -56,14 +56,14 @@ public struct ServerInterceptorTarget: Sendable {
5656
)
5757
}
5858

59-
/// A target specifying an interceptor that applies to RPCs directed only to the specified service methods.
59+
/// An operation specifying an interceptor that will be applied only to RPCs directed to the specified service methods.
6060
/// - Parameters:
6161
/// - interceptor: The interceptor to register with the server.
6262
/// - services: The list of method descriptors for which this interceptor should intercept RPCs.
63-
/// - Returns: A ``ServerInterceptorTarget``.
64-
public static func methodSpecific(
65-
interceptor: any ServerInterceptor,
66-
methods: [MethodDescriptor]
63+
/// - Returns: A ``ServerInterceptorOperation``.
64+
public static func apply(
65+
_ interceptor: any ServerInterceptor,
66+
onlyToMethods methods: [MethodDescriptor]
6767
) -> Self {
6868
Self(
6969
wrapped: .methodSpecific(
@@ -79,7 +79,7 @@ public struct ServerInterceptorTarget: Sendable {
7979
self.wrapped = wrapped
8080
}
8181

82-
/// Get the ``ServerInterceptor`` associated with this ``ServerInterceptorTarget``.
82+
/// Get the ``ServerInterceptor`` associated with this ``ServerInterceptorOperation``.
8383
public var interceptor: any ServerInterceptor {
8484
switch self.wrapped {
8585
case .allServices(let interceptor):
@@ -91,7 +91,7 @@ public struct ServerInterceptorTarget: Sendable {
9191
}
9292
}
9393

94-
/// Returns whether this ``ServerInterceptorTarget`` applies to the given `descriptor`.
94+
/// Returns whether this ``ServerInterceptorOperation`` applies to the given `descriptor`.
9595
/// - Parameter descriptor: A ``MethodDescriptor`` for which to test whether this interceptor applies.
9696
/// - Returns: `true` if this interceptor applies to the given `descriptor`, or `false` otherwise.
9797
public func applies(to descriptor: MethodDescriptor) -> Bool {

Sources/GRPCCore/GRPCServer.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public final class GRPCServer: Sendable {
7878
/// The services registered which the server is serving.
7979
private let router: RPCRouter
8080

81-
/// A collection of ``ServerInterceptorTarget``s which may be applied to all accepted RPCs.
81+
/// A collection of ``ServerInterceptorOperation``s which may be applied to all accepted RPCs.
8282
///
8383
/// RPCs are intercepted in the order that interceptors are added. That is, a request received
8484
/// from the client will first be intercepted by the first added interceptor followed by the
8585
/// second, and so on.
86-
private let interceptors: [ServerInterceptorTarget]
86+
private let interceptors: [ServerInterceptorOperation]
8787

8888
/// The state of the server.
8989
private let state: Mutex<State>
@@ -156,7 +156,7 @@ public final class GRPCServer: Sendable {
156156
self.init(
157157
transport: transport,
158158
services: services,
159-
interceptors: interceptors.map { .allServices(interceptor: $0) }
159+
interceptorPipeline: interceptors.map { .applyToAllServices($0) }
160160
)
161161
}
162162

@@ -165,22 +165,26 @@ public final class GRPCServer: Sendable {
165165
/// - Parameters:
166166
/// - transport: The transport the server should listen on.
167167
/// - services: Services offered by the server.
168-
/// - interceptors: A collection of interceptors providing cross-cutting functionality to each
168+
/// - interceptorPipeline: A collection of interceptors providing cross-cutting functionality to each
169169
/// accepted RPC. The order in which interceptors are added reflects the order in which they
170170
/// are called. The first interceptor added will be the first interceptor to intercept each
171171
/// request. The last interceptor added will be the final interceptor to intercept each
172172
/// request before calling the appropriate handler.
173173
public convenience init(
174174
transport: any ServerTransport,
175175
services: [any RegistrableRPCService],
176-
interceptors: [ServerInterceptorTarget]
176+
interceptorPipeline: [ServerInterceptorOperation]
177177
) {
178178
var router = RPCRouter()
179179
for service in services {
180180
service.registerMethods(with: &router)
181181
}
182182

183-
self.init(transport: transport, router: router, interceptors: interceptors)
183+
self.init(
184+
transport: transport,
185+
router: router,
186+
interceptorPipeline: interceptorPipeline
187+
)
184188
}
185189

186190
/// Creates a new server with no resources.
@@ -201,7 +205,7 @@ public final class GRPCServer: Sendable {
201205
self.init(
202206
transport: transport,
203207
router: router,
204-
interceptors: interceptors.map { .allServices(interceptor: $0)}
208+
interceptorPipeline: interceptors.map { .applyToAllServices($0) }
205209
)
206210
}
207211

@@ -218,12 +222,12 @@ public final class GRPCServer: Sendable {
218222
public init(
219223
transport: any ServerTransport,
220224
router: RPCRouter,
221-
interceptors: [ServerInterceptorTarget]
225+
interceptorPipeline: [ServerInterceptorOperation]
222226
) {
223227
self.state = Mutex(.notStarted)
224228
self.transport = transport
225229
self.router = router
226-
self.interceptors = interceptors
230+
self.interceptors = interceptorPipeline
227231
}
228232

229233
/// Starts the server and runs until the registered transport has closed.

Tests/GRPCCoreTests/GRPCServerTests.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import XCTest
2222
final class GRPCServerTests: XCTestCase {
2323
func withInProcessClientConnectedToServer(
2424
services: [any RegistrableRPCService],
25-
interceptors: [ServerInterceptorTarget] = [],
25+
interceptorPipeline: [ServerInterceptorOperation] = [],
2626
_ body: (InProcessTransport.Client, GRPCServer) async throws -> Void
2727
) async throws {
2828
let inProcess = InProcessTransport()
2929
let server = GRPCServer(
3030
transport: inProcess.server,
3131
services: services,
32-
interceptors: interceptors
32+
interceptorPipeline: interceptorPipeline
3333
)
3434

3535
try await withThrowingTaskGroup(of: Void.self) { group in
@@ -220,10 +220,10 @@ final class GRPCServerTests: XCTestCase {
220220

221221
try await self.withInProcessClientConnectedToServer(
222222
services: [BinaryEcho()],
223-
interceptors: [
224-
.allServices(interceptor: .requestCounter(counter1)),
225-
.allServices(interceptor: .rejectAll(with: RPCError(code: .unavailable, message: ""))),
226-
.allServices(interceptor: .requestCounter(counter2)),
223+
interceptorPipeline: [
224+
.applyToAllServices(.requestCounter(counter1)),
225+
.applyToAllServices(.rejectAll(with: RPCError(code: .unavailable, message: ""))),
226+
.applyToAllServices(.requestCounter(counter2)),
227227
]
228228
) { client, _ in
229229
try await client.withStream(
@@ -249,7 +249,7 @@ final class GRPCServerTests: XCTestCase {
249249

250250
try await self.withInProcessClientConnectedToServer(
251251
services: [BinaryEcho()],
252-
interceptors: [.allServices(interceptor: .requestCounter(counter))]
252+
interceptorPipeline: [.applyToAllServices(.requestCounter(counter))]
253253
) { client, _ in
254254
try await client.withStream(
255255
descriptor: MethodDescriptor(service: "not", method: "implemented"),
@@ -387,19 +387,19 @@ struct ServerTests {
387387

388388
try await self.withInProcessClientConnectedToServer(
389389
services: [BinaryEcho(), HelloWorld()],
390-
interceptors: [
391-
.serviceSpecific(
392-
interceptor: .requestCounter(onlyBinaryEchoCounter),
393-
services: [BinaryEcho.serviceName]
390+
interceptorPipeline: [
391+
.apply(
392+
.requestCounter(onlyBinaryEchoCounter),
393+
onlyToServices: [BinaryEcho.serviceName]
394394
),
395-
.allServices(interceptor: .requestCounter(allServicesCounter)),
396-
.serviceSpecific(
397-
interceptor: .requestCounter(onlyHelloWorldCounter),
398-
services: [HelloWorld.serviceName]
395+
.applyToAllServices(.requestCounter(allServicesCounter)),
396+
.apply(
397+
.requestCounter(onlyHelloWorldCounter),
398+
onlyToServices: [HelloWorld.serviceName]
399399
),
400-
.serviceSpecific(
401-
interceptor: .requestCounter(bothServicesCounter),
402-
services: [BinaryEcho.serviceName, HelloWorld.serviceName]
400+
.apply(
401+
.requestCounter(bothServicesCounter),
402+
onlyToServices: [BinaryEcho.serviceName, HelloWorld.serviceName]
403403
),
404404
]
405405
) { client, _ in
@@ -474,19 +474,19 @@ struct ServerTests {
474474

475475
try await self.withInProcessClientConnectedToServer(
476476
services: [BinaryEcho()],
477-
interceptors: [
478-
.methodSpecific(
479-
interceptor: .requestCounter(onlyBinaryEchoGetCounter),
480-
methods: [BinaryEcho.Methods.get]
477+
interceptorPipeline: [
478+
.apply(
479+
.requestCounter(onlyBinaryEchoGetCounter),
480+
onlyToMethods: [BinaryEcho.Methods.get]
481481
),
482-
.allServices(interceptor: .requestCounter(allMethodsCounter)),
483-
.methodSpecific(
484-
interceptor: .requestCounter(onlyBinaryEchoCollectCounter),
485-
methods: [BinaryEcho.Methods.collect]
482+
.applyToAllServices(.requestCounter(allMethodsCounter)),
483+
.apply(
484+
.requestCounter(onlyBinaryEchoCollectCounter),
485+
onlyToMethods: [BinaryEcho.Methods.collect]
486486
),
487-
.methodSpecific(
488-
interceptor: .requestCounter(bothBinaryEchoMethodsCounter),
489-
methods: [BinaryEcho.Methods.get, BinaryEcho.Methods.collect]
487+
.apply(
488+
.requestCounter(bothBinaryEchoMethodsCounter),
489+
onlyToMethods: [BinaryEcho.Methods.get, BinaryEcho.Methods.collect]
490490
),
491491
]
492492
) { client, _ in
@@ -554,14 +554,14 @@ struct ServerTests {
554554

555555
func withInProcessClientConnectedToServer(
556556
services: [any RegistrableRPCService],
557-
interceptors: [ServerInterceptorTarget] = [],
557+
interceptorPipeline: [ServerInterceptorOperation] = [],
558558
_ body: (InProcessTransport.Client, GRPCServer) async throws -> Void
559559
) async throws {
560560
let inProcess = InProcessTransport()
561561
let server = GRPCServer(
562562
transport: inProcess.server,
563563
services: services,
564-
interceptors: interceptors
564+
interceptorPipeline: interceptorPipeline
565565
)
566566

567567
try await withThrowingTaskGroup(of: Void.self) { group in

0 commit comments

Comments
 (0)