@@ -10,8 +10,8 @@ import gleam/result
10
10
import gleam/set
11
11
import gleam/string
12
12
13
- import json_rpc
14
- import json_rpc /message
13
+ import fiber
14
+ import fiber /message
15
15
16
16
fn stop_on_error ( result : Result ( a, b) , state : d) -> actor . Next ( c, d) {
17
17
case result {
@@ -21,54 +21,54 @@ fn stop_on_error(result: Result(a, b), state: d) -> actor.Next(c, d) {
21
21
}
22
22
23
23
fn add_waiting (
24
- connection : json_rpc . RpcConnection ( a, b) ,
24
+ connection : fiber . RpcConnection ( a, b) ,
25
25
id : message . Id ,
26
26
reply : process . Subject ( Result ( Dynamic , message . ErrorData ( Dynamic ) ) ) ,
27
- ) -> json_rpc . RpcConnection ( a, b) {
28
- json_rpc . RpcConnection (
27
+ ) -> fiber . RpcConnection ( a, b) {
28
+ fiber . RpcConnection (
29
29
.. connection ,
30
30
waiting : connection . waiting |> dict . insert ( id , reply ) ,
31
31
)
32
32
}
33
33
34
34
fn add_waiting_batch (
35
- connection : json_rpc . RpcConnection ( a, b) ,
35
+ connection : fiber . RpcConnection ( a, b) ,
36
36
ids : set . Set ( message . Id ) ,
37
37
reply : process . Subject (
38
38
Dict ( message . Id , Result ( Dynamic , message . ErrorData ( Dynamic ) ) ) ,
39
39
) ,
40
- ) -> json_rpc . RpcConnection ( a, b) {
41
- json_rpc . RpcConnection (
40
+ ) -> fiber . RpcConnection ( a, b) {
41
+ fiber . RpcConnection (
42
42
.. connection ,
43
43
waiting_batches : connection . waiting_batches |> dict . insert ( ids , reply ) ,
44
44
)
45
45
}
46
46
47
47
fn remove_waiting (
48
- connection : json_rpc . RpcConnection ( a, b) ,
48
+ connection : fiber . RpcConnection ( a, b) ,
49
49
id : message . Id ,
50
- ) -> json_rpc . RpcConnection ( a, b) {
51
- json_rpc . RpcConnection (
50
+ ) -> fiber . RpcConnection ( a, b) {
51
+ fiber . RpcConnection (
52
52
.. connection ,
53
53
waiting : connection . waiting |> dict . delete ( id ) ,
54
54
)
55
55
}
56
56
57
57
fn remove_waiting_batch (
58
- connection : json_rpc . RpcConnection ( a, b) ,
58
+ connection : fiber . RpcConnection ( a, b) ,
59
59
ids : set . Set ( message . Id ) ,
60
- ) -> json_rpc . RpcConnection ( a, b) {
61
- json_rpc . RpcConnection (
60
+ ) -> fiber . RpcConnection ( a, b) {
61
+ fiber . RpcConnection (
62
62
.. connection ,
63
63
waiting_batches : connection . waiting_batches |> dict . delete ( ids ) ,
64
64
)
65
65
}
66
66
67
67
pub fn handle_text (
68
- rpc : json_rpc . RpcConnection ( a, b) ,
68
+ rpc : fiber . RpcConnection ( a, b) ,
69
69
conn : a,
70
70
message text : String ,
71
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
71
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
72
72
case message . decode ( text ) {
73
73
Error ( error ) -> {
74
74
case error {
@@ -111,28 +111,28 @@ pub fn handle_text(
111
111
}
112
112
113
113
pub fn handle_rpc_message (
114
- rpc : json_rpc . RpcConnection ( a, b) ,
114
+ rpc : fiber . RpcConnection ( a, b) ,
115
115
conn : a,
116
- message rpc_message : json_rpc . RpcMessage ,
117
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
116
+ message rpc_message : fiber . RpcMessage ,
117
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
118
118
case rpc_message {
119
- json_rpc . RpcRequest ( method , params , id , reply_subject ) -> {
119
+ fiber . RpcRequest ( method , params , id , reply_subject ) -> {
120
120
message . Request ( params , method , id )
121
121
|> message . RequestMessage
122
122
|> message . encode
123
123
|> json . to_string
124
124
|> rpc . send ( conn , _)
125
125
|> stop_on_error ( rpc |> add_waiting ( id , reply_subject ) )
126
126
}
127
- json_rpc . RpcNotification ( method , params ) -> {
127
+ fiber . RpcNotification ( method , params ) -> {
128
128
message . Notification ( params , method )
129
129
|> message . RequestMessage
130
130
|> message . encode
131
131
|> json . to_string
132
132
|> rpc . send ( conn , _)
133
133
|> stop_on_error ( rpc )
134
134
}
135
- json_rpc . RpcBatch ( batch , ids , reply_subject ) -> {
135
+ fiber . RpcBatch ( batch , ids , reply_subject ) -> {
136
136
batch
137
137
|> list . map ( fn ( request ) {
138
138
let # ( method , params , id ) = request
@@ -147,18 +147,18 @@ pub fn handle_rpc_message(
147
147
|> rpc . send ( conn , _)
148
148
|> stop_on_error ( rpc |> add_waiting_batch ( ids , reply_subject ) )
149
149
}
150
- json_rpc . RpcRemoveWaiting ( id ) -> actor . continue ( rpc |> remove_waiting ( id ) )
151
- json_rpc . RpcRemoveWaitingBatch ( ids ) ->
150
+ fiber . RpcRemoveWaiting ( id ) -> actor . continue ( rpc |> remove_waiting ( id ) )
151
+ fiber . RpcRemoveWaitingBatch ( ids ) ->
152
152
actor . continue ( rpc |> remove_waiting_batch ( ids ) )
153
- json_rpc . Close -> actor . Stop ( process . Normal )
153
+ fiber . Close -> actor . Stop ( process . Normal )
154
154
}
155
155
}
156
156
157
157
pub fn handle_binary (
158
- rpc : json_rpc . RpcConnection ( a, b) ,
158
+ rpc : fiber . RpcConnection ( a, b) ,
159
159
conn : a,
160
160
message _binary : BitArray ,
161
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
161
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
162
162
message . ErrorData (
163
163
code : - 32_700,
164
164
message : "Parse error" ,
@@ -172,21 +172,21 @@ pub fn handle_binary(
172
172
}
173
173
174
174
fn handle_request_callback_result (
175
- result : Result ( Json , json_rpc . RpcError ) ,
175
+ result : Result ( Json , fiber . RpcError ) ,
176
176
id : message . Id ,
177
177
) -> message . Response ( Json ) {
178
178
case result {
179
- Error ( json_rpc . InvalidParams ) -> {
179
+ Error ( fiber . InvalidParams ) -> {
180
180
option . None
181
181
|> message . ErrorData ( code : - 32_602, message : "Invalid params" )
182
182
|> message . ErrorResponse ( id : )
183
183
}
184
- Error ( json_rpc . InternalError ) -> {
184
+ Error ( fiber . InternalError ) -> {
185
185
option . None
186
186
|> message . ErrorData ( code : - 32_603, message : "Internal error" )
187
187
|> message . ErrorResponse ( id : )
188
188
}
189
- Error ( json_rpc . CustomError ( error ) ) -> {
189
+ Error ( fiber . CustomError ( error ) ) -> {
190
190
error
191
191
|> message . ErrorResponse ( id : )
192
192
}
@@ -198,7 +198,7 @@ fn handle_request_callback_result(
198
198
}
199
199
200
200
fn process_request (
201
- rpc : json_rpc . RpcConnection ( conn, send_error) ,
201
+ rpc : fiber . RpcConnection ( conn, send_error) ,
202
202
request : message . Request ( Dynamic ) ,
203
203
) -> Result ( message . Response ( Json ) , Nil ) {
204
204
case request {
@@ -237,10 +237,10 @@ fn process_request(
237
237
}
238
238
239
239
fn handle_request (
240
- rpc : json_rpc . RpcConnection ( a, b) ,
240
+ rpc : fiber . RpcConnection ( a, b) ,
241
241
conn : a,
242
242
request : message . Request ( Dynamic ) ,
243
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
243
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
244
244
case process_request ( rpc , request ) {
245
245
Error ( Nil ) -> actor . continue ( rpc )
246
246
Ok ( response ) ->
@@ -254,10 +254,10 @@ fn handle_request(
254
254
}
255
255
256
256
fn handle_response (
257
- rpc : json_rpc . RpcConnection ( a, b) ,
257
+ rpc : fiber . RpcConnection ( a, b) ,
258
258
_conn : a,
259
259
response : message . Response ( Dynamic ) ,
260
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
260
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
261
261
case response {
262
262
message . ErrorResponse ( error , id ) ->
263
263
case rpc . waiting |> dict . get ( id ) {
@@ -301,10 +301,10 @@ fn handle_response(
301
301
}
302
302
303
303
fn handle_batch_request (
304
- rpc : json_rpc . RpcConnection ( a, b) ,
304
+ rpc : fiber . RpcConnection ( a, b) ,
305
305
conn : a,
306
306
batch : List ( message . Request ( Dynamic ) ) ,
307
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
307
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
308
308
batch
309
309
|> list . map ( process_request ( rpc , _) )
310
310
|> result . values
@@ -316,10 +316,10 @@ fn handle_batch_request(
316
316
}
317
317
318
318
fn handle_batch_response (
319
- rpc : json_rpc . RpcConnection ( a, b) ,
319
+ rpc : fiber . RpcConnection ( a, b) ,
320
320
_conn : a,
321
321
batch : List ( message . Response ( Dynamic ) ) ,
322
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
322
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
323
323
let ids =
324
324
batch
325
325
|> list . map ( fn ( response ) {
@@ -357,11 +357,11 @@ fn handle_batch_response(
357
357
}
358
358
359
359
fn handle_message (
360
- rpc : json_rpc . RpcConnection ( a, b) ,
360
+ rpc : fiber . RpcConnection ( a, b) ,
361
361
conn : a,
362
- message json_rpc_message : message . Message ( Dynamic ) ,
363
- ) -> actor . Next ( json_rpc . RpcMessage , json_rpc . RpcConnection ( a, b) ) {
364
- case json_rpc_message {
362
+ message fiber_message : message . Message ( Dynamic ) ,
363
+ ) -> actor . Next ( fiber . RpcMessage , fiber . RpcConnection ( a, b) ) {
364
+ case fiber_message {
365
365
message . BatchRequestMessage ( batch ) -> handle_batch_request ( rpc , conn , batch )
366
366
message . BatchResponseMessage ( batch ) ->
367
367
handle_batch_response ( rpc , conn , batch )
0 commit comments