-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPC.mli
More file actions
340 lines (275 loc) · 8.82 KB
/
Copy pathRPC.mli
File metadata and controls
340 lines (275 loc) · 8.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
(** Typed RPC services: definition, binding and dispatch. *)
(** Typed path argument. *)
module Arg : sig
type 'a arg
val make:
?descr:string ->
name:string ->
destruct:(string -> ('a, string) result) ->
construct:('a -> string) ->
unit -> 'a arg
type descr = {
name: string ;
descr: string option ;
}
val descr: 'a arg -> descr
val int: int arg
val int32: int32 arg
val int64: int64 arg
val float: float arg
end
(** Parametrized path to services. *)
module Path : sig
type ('prefix, 'params) path
type 'prefix context = ('prefix, 'prefix) path
val root: 'a context
val add_suffix:
('prefix, 'params) path -> string -> ('prefix, 'params) path
val (/):
('prefix, 'params) path -> string -> ('prefix, 'params) path
val add_arg:
('prefix, 'params) path -> 'a Arg.arg -> ('prefix, 'params * 'a) path
val (/:):
('prefix, 'params) path -> 'a Arg.arg -> ('prefix, 'params * 'a) path
val prefix:
('prefix, 'a) path -> ('a, 'params) path -> ('prefix, 'params) path
val map:
('a -> 'b) -> ('b -> 'a) -> ('prefix, 'a) path -> ('prefix, 'b) path
end
(** HTTP methods as defined in Cohttp.Code *)
type meth = [
| `GET
| `POST
| `HEAD
| `DELETE
| `PATCH
| `PUT
| `OPTIONS
| `TRACE
| `CONNECT
| `Other of string
]
val string_of_method : meth -> string
(** Services. *)
type ('prefix, 'params, 'input, 'output) service
val service:
?meth: meth ->
?description: string ->
input: 'input Data_encoding.t ->
output: 'output Data_encoding.t ->
('prefix, 'params) Path.path ->
('prefix, 'params, 'input, 'output) service
val get_service:
?description: string ->
output: 'output Data_encoding.t ->
('prefix, 'params) Path.path ->
('prefix, 'params, unit, 'output) service
val head_service:
?description: string ->
('prefix, 'params) Path.path ->
('prefix, 'params, unit, unit) service
val post_service:
?description: string ->
input: 'input Data_encoding.t ->
output: 'output Data_encoding.t ->
('prefix, 'params) Path.path ->
('prefix, 'params, 'input, 'output) service
val put_service:
?description: string ->
input: 'input Data_encoding.t ->
output: 'output Data_encoding.t ->
('prefix, 'params) Path.path ->
('prefix, 'params, 'input, 'output) service
val delete_service:
?description: string ->
input: 'input Data_encoding.t ->
output: 'output Data_encoding.t ->
('prefix, 'params) Path.path ->
('prefix, 'params, 'input, 'output) service
val prefix:
('prefix, 'inner_prefix) Path.path ->
('inner_prefix, 'params, 'input, 'output) service ->
('prefix, 'params, 'input, 'output) service
val forge_request:
(unit, 'params, 'input, 'output) service ->
'params -> 'input -> meth * string list * Data_encoding.json
val read_answer:
(unit, 'params, 'input, 'output) service ->
Data_encoding.json -> ('output, string) result
(** Service directory description *)
module Description : sig
type service_descr = {
description: string option ;
input: Json_schema.schema ;
output: Json_schema.schema ;
}
type directory_descr =
| Static of static_directory_descr
| Dynamic of string option
and static_directory_descr = {
service: service_descr option ;
subdirs: static_subdirectories_descr option ;
}
and static_subdirectories_descr =
| Suffixes of directory_descr Map.Make(String).t
| Arg of Arg.descr * directory_descr
val service:
?meth: meth ->
?description:string ->
('prefix, 'params) Path.path ->
('prefix, 'params, bool option, directory_descr) service
val pp_print_directory_descr:
Format.formatter -> directory_descr -> unit
end
module Answer : sig
(** Return type for service handler *)
type 'a answer =
{ code : int ;
body : 'a output ;
}
and 'a output =
| Empty
| Single of 'a
| Stream of 'a stream
and 'a stream = {
next: unit -> 'a option Lwt.t ;
shutdown: unit -> unit ;
}
val ok: 'a -> 'a answer
val answer: ?code:int -> 'a -> 'a answer
val return: ?code:int -> 'a -> 'a answer Lwt.t
val return_stream: 'a stream -> 'a answer Lwt.t
end
(** Dispatch tree *)
type 'prefix directory
(** Empty list of dispatch trees *)
val empty: 'prefix directory
val map: ('a -> 'b) -> 'b directory -> 'a directory
val prefix: ('pr, 'p) Path.path -> 'p directory -> 'pr directory
val merge: 'a directory -> 'a directory -> 'a directory
(** Possible error while registring services. *)
type step =
| Static of string
| Dynamic of Arg.descr
type conflict =
| CService | CDir | CBuilder | CCustom
| CTypes of Arg.descr *
Arg.descr
| CType of Arg.descr * string list
exception Conflict of step list * conflict
(** Registring handler in service tree. *)
val register:
'prefix directory ->
('prefix, 'params, 'input, 'output) service ->
('params -> 'input -> 'output Answer.answer Lwt.t) ->
'prefix directory
(** Registring handler in service tree. Curryfied variant. *)
val register0:
unit directory ->
(unit, unit, 'i, 'o) service ->
('i -> 'o Answer.answer Lwt.t) ->
unit directory
val register1:
'prefix directory ->
('prefix, unit * 'a, 'i, 'o) service ->
('a -> 'i -> 'o Answer.answer Lwt.t) ->
'prefix directory
val register2:
'prefix directory ->
('prefix, (unit * 'a) * 'b, 'i, 'o) service ->
('a -> 'b -> 'i -> 'o Answer.answer Lwt.t) ->
'prefix directory
val register3:
'prefix directory ->
('prefix, ((unit * 'a) * 'b) * 'c, 'i, 'o) service ->
('a -> 'b -> 'c -> 'i -> 'o Answer.answer Lwt.t) ->
'prefix directory
val register4:
'prefix directory ->
('prefix, (((unit * 'a) * 'b) * 'c) * 'd, 'i, 'o) service ->
('a -> 'b -> 'c -> 'd -> 'i -> 'o Answer.answer Lwt.t) ->
'prefix directory
val register5:
'prefix directory ->
('prefix, ((((unit * 'a) * 'b) * 'c) * 'd) * 'e, 'i, 'o) service ->
('a -> 'b -> 'c -> 'd -> 'e -> 'i -> 'o Answer.answer Lwt.t) ->
'prefix directory
(** Registring dynamic subtree. *)
val register_dynamic_directory:
?meths:meth list ->
?descr:string ->
'prefix directory ->
('prefix, 'a) Path.path ->
('a -> 'a directory Lwt.t) ->
'prefix directory
(** Registring dynamic subtree. (Curryfied variant) *)
val register_dynamic_directory1:
?descr:string ->
'prefix directory ->
('prefix, unit * 'a) Path.path ->
('a -> (unit * 'a) directory Lwt.t) ->
'prefix directory
val register_dynamic_directory2:
?descr:string ->
'prefix directory ->
('prefix, (unit * 'a) * 'b) Path.path ->
('a -> 'b -> ((unit * 'a) * 'b) directory Lwt.t) ->
'prefix directory
val register_dynamic_directory3:
?descr:string ->
'prefix directory ->
('prefix, ((unit * 'a) * 'b) * 'c) Path.path ->
('a -> 'b -> 'c -> (((unit * 'a) * 'b) * 'c) directory Lwt.t) ->
'prefix directory
(** Registring custom directory lookup. *)
type custom_lookup = RestoDirectory.custom_lookup
(* | CustomService of Description.service_descr * *)
(* ( Data_encoding.json option -> *)
(* Data_encoding.json Answer.answer Lwt.t ) *)
(* | CustomDirectory of Description.directory_descr *)
val register_custom_lookup:
?meth:meth ->
?descr:string ->
'prefix directory ->
('prefix, 'params) Path.path ->
('params -> string list -> custom_lookup Lwt.t) ->
'prefix directory
val register_custom_lookup1:
?meth:meth ->
?descr:string ->
'prefix directory ->
('prefix, unit * 'a) Path.path ->
('a -> string list -> custom_lookup Lwt.t) ->
'prefix directory
val register_custom_lookup2:
?meth:meth ->
?descr:string ->
'prefix directory ->
('prefix, (unit * 'a) * 'b) Path.path ->
('a -> 'b -> string list -> custom_lookup Lwt.t) ->
'prefix directory
val register_custom_lookup3:
?meth:meth ->
?descr:string ->
'prefix directory ->
('prefix, ((unit * 'a) * 'b) * 'c) Path.path ->
('a -> 'b -> 'c -> string list -> custom_lookup Lwt.t) ->
'prefix directory
(** Registring a description service. *)
val register_describe_directory_service:
'prefix directory ->
('prefix, 'prefix, bool option, Description.directory_descr) service ->
'prefix directory
exception Cannot_parse of Arg.descr * string * string list
(** Resolve a service. *)
val lookup:
'prefix directory -> ?meth:meth -> 'prefix -> string list ->
(Data_encoding.json option -> Data_encoding.json Answer.answer Lwt.t) Lwt.t