Skip to content

Commit 755e166

Browse files
Client cosmetics (#489)
1 parent 20970d2 commit 755e166

File tree

22 files changed

+365
-204
lines changed

22 files changed

+365
-204
lines changed

client-kotlin/src/main/kotlin/dev/restate/client/kotlin/ingress.kt

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
package dev.restate.client.kotlin
1010

1111
import dev.restate.client.Client
12-
import dev.restate.client.ClientRequestOptions
13-
import dev.restate.client.ClientResponse
12+
import dev.restate.client.RequestOptions
13+
import dev.restate.client.Response
14+
import dev.restate.client.ResponseHead
1415
import dev.restate.client.SendResponse
1516
import dev.restate.common.Output
1617
import dev.restate.common.Request
@@ -23,108 +24,117 @@ import kotlinx.coroutines.future.await
2324

2425
// Extension methods for the Client
2526

26-
fun clientRequestOptions(init: ClientRequestOptions.Builder.() -> Unit): ClientRequestOptions {
27-
val builder = ClientRequestOptions.builder()
27+
fun requestOptions(init: RequestOptions.Builder.() -> Unit): RequestOptions {
28+
val builder = RequestOptions.builder()
2829
builder.init()
2930
return builder.build()
3031
}
3132

3233
/** Shorthand for [callSuspend] */
33-
suspend fun <Req, Res> Request<Req, Res>.call(client: Client): ClientResponse<Res> {
34+
suspend fun <Req, Res> Request<Req, Res>.call(client: Client): Response<Res> {
3435
return client.callSuspend(this)
3536
}
3637

3738
/** Suspend version of [Client.callAsync] */
38-
suspend fun <Req, Res> Client.callSuspend(request: Request<Req, Res>): ClientResponse<Res> {
39+
suspend fun <Req, Res> Client.callSuspend(request: Request<Req, Res>): Response<Res> {
3940
return this.callAsync(request).await()
4041
}
4142

4243
/** Shorthand for [sendSuspend] */
4344
suspend fun <Req, Res> Request<Req, Res>.send(
4445
client: Client,
4546
delay: Duration? = null
46-
): ClientResponse<SendResponse<Res>> {
47+
): SendResponse<Res> {
4748
return client.sendSuspend(this, delay)
4849
}
4950

5051
/** Suspend version of [Client.sendAsync] */
5152
suspend fun <Req, Res> Client.sendSuspend(
5253
request: Request<Req, Res>,
5354
delay: Duration? = null
54-
): ClientResponse<SendResponse<Res>> {
55+
): SendResponse<Res> {
5556
return this.sendAsync(request, delay?.toJavaDuration()).await()
5657
}
5758

5859
/** Shorthand for [submitSuspend] */
5960
suspend fun <Req, Res> WorkflowRequest<Req, Res>.submit(
6061
client: Client,
6162
delay: Duration? = null
62-
): ClientResponse<SendResponse<Res>> {
63+
): SendResponse<Res> {
6364
return client.submitSuspend(this, delay)
6465
}
6566

6667
/** Suspend version of [Client.submitAsync] */
6768
suspend fun <Req, Res> Client.submitSuspend(
6869
request: WorkflowRequest<Req, Res>,
6970
delay: Duration? = null
70-
): ClientResponse<SendResponse<Res>> {
71+
): SendResponse<Res> {
7172
return this.submitAsync(request, delay?.toJavaDuration()).await()
7273
}
7374

7475
suspend fun <T : Any> Client.AwakeableHandle.resolveSuspend(
7576
typeTag: TypeTag<T>,
7677
payload: T,
77-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
78-
): ClientResponse<Void> {
78+
options: RequestOptions = RequestOptions.DEFAULT
79+
): Response<Void> {
7980
return this.resolveAsync(typeTag, payload, options).await()
8081
}
8182

8283
suspend inline fun <reified T : Any> Client.AwakeableHandle.resolveSuspend(
8384
payload: T,
84-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
85-
): ClientResponse<Void> {
85+
options: RequestOptions = RequestOptions.DEFAULT
86+
): Response<Void> {
8687
return this.resolveSuspend(typeTag<T>(), payload, options)
8788
}
8889

8990
suspend fun Client.AwakeableHandle.rejectSuspend(
9091
reason: String,
91-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
92-
): ClientResponse<Void> {
92+
options: RequestOptions = RequestOptions.DEFAULT
93+
): Response<Void> {
9394
return this.rejectAsync(reason, options).await()
9495
}
9596

9697
suspend fun <T> Client.InvocationHandle<T>.attachSuspend(
97-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
98-
): ClientResponse<T> {
98+
options: RequestOptions = RequestOptions.DEFAULT
99+
): Response<T> {
99100
return this.attachAsync(options).await()
100101
}
101102

102103
suspend fun <T : Any?> Client.InvocationHandle<T>.getOutputSuspend(
103-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
104-
): ClientResponse<Output<T>> {
104+
options: RequestOptions = RequestOptions.DEFAULT
105+
): Response<Output<T>> {
105106
return this.getOutputAsync(options).await()
106107
}
107108

108109
suspend fun <T> Client.IdempotentInvocationHandle<T>.attachSuspend(
109-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
110-
): ClientResponse<T> {
110+
options: RequestOptions = RequestOptions.DEFAULT
111+
): Response<T> {
111112
return this.attachAsync(options).await()
112113
}
113114

114115
suspend fun <T> Client.IdempotentInvocationHandle<T>.getOutputSuspend(
115-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
116-
): ClientResponse<Output<T>> {
116+
options: RequestOptions = RequestOptions.DEFAULT
117+
): Response<Output<T>> {
117118
return this.getOutputAsync(options).await()
118119
}
119120

120121
suspend fun <T> Client.WorkflowHandle<T>.attachSuspend(
121-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
122-
): ClientResponse<T> {
122+
options: RequestOptions = RequestOptions.DEFAULT
123+
): Response<T> {
123124
return this.attachAsync(options).await()
124125
}
125126

126127
suspend fun <T> Client.WorkflowHandle<T>.getOutputSuspend(
127-
options: ClientRequestOptions = ClientRequestOptions.DEFAULT
128-
): ClientResponse<Output<T>> {
128+
options: RequestOptions = RequestOptions.DEFAULT
129+
): Response<Output<T>> {
129130
return this.getOutputAsync(options).await()
130131
}
132+
133+
val ResponseHead.status: Int
134+
get() = this.statusCode()
135+
val ResponseHead.headers: ResponseHead.Headers
136+
get() = this.headers()
137+
val <Res> Response<Res>.response: Res
138+
get() = this.response()
139+
val <Res> SendResponse<Res>.sendStatus: SendResponse.SendStatus
140+
get() = this.sendStatus()

0 commit comments

Comments
 (0)