9
9
package dev.restate.client.kotlin
10
10
11
11
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
14
15
import dev.restate.client.SendResponse
15
16
import dev.restate.common.Output
16
17
import dev.restate.common.Request
@@ -23,108 +24,117 @@ import kotlinx.coroutines.future.await
23
24
24
25
// Extension methods for the Client
25
26
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()
28
29
builder.init ()
29
30
return builder.build()
30
31
}
31
32
32
33
/* * 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 > {
34
35
return client.callSuspend(this )
35
36
}
36
37
37
38
/* * 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 > {
39
40
return this .callAsync(request).await()
40
41
}
41
42
42
43
/* * Shorthand for [sendSuspend] */
43
44
suspend fun <Req , Res > Request <Req , Res >.send (
44
45
client : Client ,
45
46
delay : Duration ? = null
46
- ): ClientResponse < SendResponse <Res > > {
47
+ ): SendResponse <Res > {
47
48
return client.sendSuspend(this , delay)
48
49
}
49
50
50
51
/* * Suspend version of [Client.sendAsync] */
51
52
suspend fun <Req , Res > Client.sendSuspend (
52
53
request : Request <Req , Res >,
53
54
delay : Duration ? = null
54
- ): ClientResponse < SendResponse <Res > > {
55
+ ): SendResponse <Res > {
55
56
return this .sendAsync(request, delay?.toJavaDuration()).await()
56
57
}
57
58
58
59
/* * Shorthand for [submitSuspend] */
59
60
suspend fun <Req , Res > WorkflowRequest <Req , Res >.submit (
60
61
client : Client ,
61
62
delay : Duration ? = null
62
- ): ClientResponse < SendResponse <Res > > {
63
+ ): SendResponse <Res > {
63
64
return client.submitSuspend(this , delay)
64
65
}
65
66
66
67
/* * Suspend version of [Client.submitAsync] */
67
68
suspend fun <Req , Res > Client.submitSuspend (
68
69
request : WorkflowRequest <Req , Res >,
69
70
delay : Duration ? = null
70
- ): ClientResponse < SendResponse <Res > > {
71
+ ): SendResponse <Res > {
71
72
return this .submitAsync(request, delay?.toJavaDuration()).await()
72
73
}
73
74
74
75
suspend fun <T : Any > Client.AwakeableHandle.resolveSuspend (
75
76
typeTag : TypeTag <T >,
76
77
payload : T ,
77
- options : ClientRequestOptions = ClientRequestOptions .DEFAULT
78
- ): ClientResponse <Void > {
78
+ options : RequestOptions = RequestOptions .DEFAULT
79
+ ): Response <Void > {
79
80
return this .resolveAsync(typeTag, payload, options).await()
80
81
}
81
82
82
83
suspend inline fun <reified T : Any > Client.AwakeableHandle.resolveSuspend (
83
84
payload : T ,
84
- options : ClientRequestOptions = ClientRequestOptions .DEFAULT
85
- ): ClientResponse <Void > {
85
+ options : RequestOptions = RequestOptions .DEFAULT
86
+ ): Response <Void > {
86
87
return this .resolveSuspend(typeTag<T >(), payload, options)
87
88
}
88
89
89
90
suspend fun Client.AwakeableHandle.rejectSuspend (
90
91
reason : String ,
91
- options : ClientRequestOptions = ClientRequestOptions .DEFAULT
92
- ): ClientResponse <Void > {
92
+ options : RequestOptions = RequestOptions .DEFAULT
93
+ ): Response <Void > {
93
94
return this .rejectAsync(reason, options).await()
94
95
}
95
96
96
97
suspend fun <T > Client.InvocationHandle<T>.attachSuspend (
97
- options : ClientRequestOptions = ClientRequestOptions .DEFAULT
98
- ): ClientResponse <T > {
98
+ options : RequestOptions = RequestOptions .DEFAULT
99
+ ): Response <T > {
99
100
return this .attachAsync(options).await()
100
101
}
101
102
102
103
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 >> {
105
106
return this .getOutputAsync(options).await()
106
107
}
107
108
108
109
suspend fun <T > Client.IdempotentInvocationHandle<T>.attachSuspend (
109
- options : ClientRequestOptions = ClientRequestOptions .DEFAULT
110
- ): ClientResponse <T > {
110
+ options : RequestOptions = RequestOptions .DEFAULT
111
+ ): Response <T > {
111
112
return this .attachAsync(options).await()
112
113
}
113
114
114
115
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 >> {
117
118
return this .getOutputAsync(options).await()
118
119
}
119
120
120
121
suspend fun <T > Client.WorkflowHandle<T>.attachSuspend (
121
- options : ClientRequestOptions = ClientRequestOptions .DEFAULT
122
- ): ClientResponse <T > {
122
+ options : RequestOptions = RequestOptions .DEFAULT
123
+ ): Response <T > {
123
124
return this .attachAsync(options).await()
124
125
}
125
126
126
127
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 >> {
129
130
return this .getOutputAsync(options).await()
130
131
}
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