Resto: minor simplification (remove RPC_service.map
)
This commit is contained in:
parent
f2b7897572
commit
c9822abab7
@ -28,9 +28,3 @@ val add_final_args:
|
|||||||
('prefix, 'params) path -> 'a RPC_arg.t -> ('prefix, 'params * 'a list) path
|
('prefix, 'params) path -> 'a RPC_arg.t -> ('prefix, 'params * 'a list) path
|
||||||
val (/:*):
|
val (/:*):
|
||||||
('prefix, 'params) path -> 'a RPC_arg.t -> ('prefix, 'params * 'a list) path
|
('prefix, 'params) path -> 'a RPC_arg.t -> ('prefix, 'params * 'a list) path
|
||||||
|
|
||||||
val prefix:
|
|
||||||
('prefix, 'a) path -> ('a, 'params) path -> ('prefix, 'params) path
|
|
||||||
|
|
||||||
val map:
|
|
||||||
('a -> 'b) -> ('b -> 'a) -> ('prefix, 'a) path -> ('prefix, 'b) path
|
|
||||||
|
@ -43,19 +43,6 @@ val error_encoding:
|
|||||||
('meth, 'prefix, 'params, 'query, 'input, 'output) service ->
|
('meth, 'prefix, 'params, 'query, 'input, 'output) service ->
|
||||||
unit Data_encoding.t
|
unit Data_encoding.t
|
||||||
|
|
||||||
val prefix:
|
|
||||||
('prefix, 'inner_prefix) RPC_path.t ->
|
|
||||||
('meth, 'inner_prefix, 'params, 'query,
|
|
||||||
'input, 'output) service ->
|
|
||||||
('meth, 'prefix, 'params,
|
|
||||||
'query, 'input, 'output) service
|
|
||||||
|
|
||||||
val map:
|
|
||||||
('a -> 'b) ->
|
|
||||||
('b -> 'a) ->
|
|
||||||
('meth, 'pr, 'a, 'q, 'i, 'o) service ->
|
|
||||||
('meth, 'pr, 'b, 'q, 'i, 'o) service
|
|
||||||
|
|
||||||
val get_service:
|
val get_service:
|
||||||
?description: string ->
|
?description: string ->
|
||||||
query: 'query RPC_query.t ->
|
query: 'query RPC_query.t ->
|
||||||
|
@ -26,7 +26,7 @@ let dir =
|
|||||||
(fun i j () () -> Lwt.return (`Ok (float_of_int i+.j)))
|
(fun i j () () -> Lwt.return (`Ok (float_of_int i+.j)))
|
||||||
let dir =
|
let dir =
|
||||||
register dir alternate_add_service'
|
register dir alternate_add_service'
|
||||||
(fun (i,j) () () -> Lwt.return (`Ok (i+j)))
|
(fun (((), i),j) () () -> Lwt.return (`Ok (i+ int_of_float j)))
|
||||||
let dir =
|
let dir =
|
||||||
register_describe_directory_service
|
register_describe_directory_service
|
||||||
dir describe_service
|
dir describe_service
|
||||||
|
@ -48,7 +48,7 @@ module Test(Request : sig
|
|||||||
assert (test repeat_service ((), 3) (`A []) (`A (repeat 3 (`A [])))) ;
|
assert (test repeat_service ((), 3) (`A []) (`A (repeat 3 (`A [])))) ;
|
||||||
assert (test add_service ((), 2) 3 5) ;
|
assert (test add_service ((), 2) 3 5) ;
|
||||||
assert (test alternate_add_service (((), 1), 2.5) () 3.5) ;
|
assert (test alternate_add_service (((), 1), 2.5) () 3.5) ;
|
||||||
assert (test alternate_add_service' (1, 2) () 3) ;
|
assert (test alternate_add_service' (((), 1), 2.) () 3) ;
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,10 +41,7 @@ let alternate_add_service' =
|
|||||||
~input:Json_encoding.null
|
~input:Json_encoding.null
|
||||||
~output:Json_encoding.int
|
~output:Json_encoding.int
|
||||||
~error:Json_encoding.empty
|
~error:Json_encoding.empty
|
||||||
Path.(map
|
Path.(root / "bar" /: Arg.int /: Arg.float / "add")
|
||||||
(fun (((),i),f) -> (i,int_of_float f))
|
|
||||||
(fun (i,f) -> (((),i),float_of_int f))
|
|
||||||
(root / "bar" /: Arg.int /: Arg.float / "add"))
|
|
||||||
|
|
||||||
let minus_service r =
|
let minus_service r =
|
||||||
post_service
|
post_service
|
||||||
|
1
vendors/ocplib-resto/lib_ezresto/ezResto.ml
vendored
1
vendors/ocplib-resto/lib_ezresto/ezResto.ml
vendored
@ -23,7 +23,6 @@ module Path = struct
|
|||||||
let add_arg = Path.add_arg
|
let add_arg = Path.add_arg
|
||||||
let (/) = add_suffix
|
let (/) = add_suffix
|
||||||
let (/:) = add_arg
|
let (/:) = add_arg
|
||||||
let map = Path.map
|
|
||||||
end
|
end
|
||||||
module Query = Query
|
module Query = Query
|
||||||
type ('meth, 'params, 'query, 'input, 'output, 'error) service =
|
type ('meth, 'params, 'query, 'input, 'output, 'error) service =
|
||||||
|
2
vendors/ocplib-resto/lib_ezresto/ezResto.mli
vendored
2
vendors/ocplib-resto/lib_ezresto/ezResto.mli
vendored
@ -49,8 +49,6 @@ module Path : sig
|
|||||||
val add_arg: 'params path -> 'a Arg.arg -> ('params * 'a) path
|
val add_arg: 'params path -> 'a Arg.arg -> ('params * 'a) path
|
||||||
val (/:): 'params path -> 'a Arg.arg -> ('params * 'a) path
|
val (/:): 'params path -> 'a Arg.arg -> ('params * 'a) path
|
||||||
|
|
||||||
val map: ('a -> 'b) -> ('b -> 'a) -> 'a path -> 'b path
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Query : sig
|
module Query : sig
|
||||||
|
@ -181,7 +181,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
: type p pr. (pr, p) Path.path -> p directory -> pr directory
|
: type p pr. (pr, p) Path.path -> p directory -> pr directory
|
||||||
= fun path dir ->
|
= fun path dir ->
|
||||||
let rec prefix
|
let rec prefix
|
||||||
: type k pr. (pr, k) Resto.Internal.rpath -> k directory -> pr directory
|
: type k pr. (pr, k) Resto.Internal.path -> k directory -> pr directory
|
||||||
= fun path dir ->
|
= fun path dir ->
|
||||||
match path with
|
match path with
|
||||||
| Root -> dir
|
| Root -> dir
|
||||||
@ -195,9 +195,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
services = MethMap.empty })
|
services = MethMap.empty })
|
||||||
| DynamicTail _ ->
|
| DynamicTail _ ->
|
||||||
invalid_arg "RestoDirectory.prefix" in
|
invalid_arg "RestoDirectory.prefix" in
|
||||||
match Resto.Internal.to_path path with
|
prefix (Resto.Internal.to_path path) dir
|
||||||
| Path path -> prefix path dir
|
|
||||||
| MappedPath (path, map, _) -> prefix path (map_directory map dir)
|
|
||||||
|
|
||||||
let conflict steps kind = raise (Conflict (steps, kind))
|
let conflict steps kind = raise (Conflict (steps, kind))
|
||||||
|
|
||||||
@ -431,7 +429,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
|
|
||||||
let rec transparent_resolve
|
let rec transparent_resolve
|
||||||
: type pr p.
|
: type pr p.
|
||||||
pr directory -> (pr, p) rpath -> p -> p directory option Lwt.t
|
pr directory -> (pr, p) path -> p -> p directory option Lwt.t
|
||||||
= fun dir path rargs ->
|
= fun dir path rargs ->
|
||||||
match path with
|
match path with
|
||||||
| Root -> Lwt.return_some dir
|
| Root -> Lwt.return_some dir
|
||||||
@ -488,16 +486,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
params -> query -> input -> (output, error) Answer.t Lwt.t =
|
params -> query -> input -> (output, error) Answer.t Lwt.t =
|
||||||
fun dir service params query body ->
|
fun dir service params query body ->
|
||||||
let service = Service.Internal.to_service service in
|
let service = Service.Internal.to_service service in
|
||||||
begin
|
transparent_resolve dir service.path params >>= function
|
||||||
match service.path with
|
|
||||||
| Service.Internal.Path p ->
|
|
||||||
transparent_resolve dir p params
|
|
||||||
| Service.Internal.MappedPath (p, _, f) -> begin
|
|
||||||
transparent_resolve dir p (f params) >>= function
|
|
||||||
| None -> Lwt.return_none
|
|
||||||
| Some dir -> Lwt.return_some (map f dir)
|
|
||||||
end
|
|
||||||
end >>= function
|
|
||||||
| None -> Lwt.return (`Not_found None)
|
| None -> Lwt.return (`Not_found None)
|
||||||
| Some (Static { services ; _ }) -> begin
|
| Some (Static { services ; _ }) -> begin
|
||||||
try
|
try
|
||||||
@ -522,7 +511,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
|
|
||||||
let rec describe_rpath
|
let rec describe_rpath
|
||||||
: type a b. Description.path_item list ->
|
: type a b. Description.path_item list ->
|
||||||
(a, b) rpath -> Description.path_item list
|
(a, b) path -> Description.path_item list
|
||||||
= fun acc path ->
|
= fun acc path ->
|
||||||
match path with
|
match path with
|
||||||
| Root -> acc
|
| Root -> acc
|
||||||
@ -538,7 +527,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
****************************************************************************)
|
****************************************************************************)
|
||||||
|
|
||||||
let rec step_of_path
|
let rec step_of_path
|
||||||
: type p rk. (rk, p) rpath -> step list -> step list
|
: type p rk. (rk, p) path -> step list -> step list
|
||||||
= fun path acc ->
|
= fun path acc ->
|
||||||
match path with
|
match path with
|
||||||
| Root -> acc
|
| Root -> acc
|
||||||
@ -551,7 +540,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
|
|
||||||
let rec insert
|
let rec insert
|
||||||
: type k rk.
|
: type k rk.
|
||||||
(rk, k) rpath -> rk directory -> k directory * (k directory -> rk directory)
|
(rk, k) path -> rk directory -> k directory * (k directory -> rk directory)
|
||||||
= fun path dir ->
|
= fun path dir ->
|
||||||
match path with
|
match path with
|
||||||
| Root -> dir, (fun x -> x)
|
| Root -> dir, (fun x -> x)
|
||||||
@ -629,7 +618,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
fun root s handler ->
|
fun root s handler ->
|
||||||
let s = Service.Internal.to_service s in
|
let s = Service.Internal.to_service s in
|
||||||
let register
|
let register
|
||||||
: type k. (pr, k) rpath -> (k -> q -> i -> (o, e) Answer.t Lwt.t) ->
|
: type k. (pr, k) path -> (k -> q -> i -> (o, e) Answer.t Lwt.t) ->
|
||||||
pr directory =
|
pr directory =
|
||||||
fun path handler ->
|
fun path handler ->
|
||||||
let dir, insert = insert path root in
|
let dir, insert = insert path root in
|
||||||
@ -662,9 +651,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
| Static _ -> conflict path (CService s.meth)
|
| Static _ -> conflict path (CService s.meth)
|
||||||
| Dynamic _ -> conflict path CBuilder
|
| Dynamic _ -> conflict path CBuilder
|
||||||
| DynamicTail _ -> conflict path CTail in
|
| DynamicTail _ -> conflict path CTail in
|
||||||
match s.path with
|
register s.path handler
|
||||||
| Path p -> register p handler
|
|
||||||
| MappedPath (p, map, _) -> register p (fun p i -> handler (map p) i)
|
|
||||||
|
|
||||||
let register =
|
let register =
|
||||||
(register
|
(register
|
||||||
@ -681,7 +668,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
fun ?descr root path builder ->
|
fun ?descr root path builder ->
|
||||||
let path = Resto.Internal.to_path path in
|
let path = Resto.Internal.to_path path in
|
||||||
let register
|
let register
|
||||||
: type k. (pr, k) rpath -> (k -> k directory Lwt.t) -> pr directory =
|
: type k. (pr, k) path -> (k -> k directory Lwt.t) -> pr directory =
|
||||||
fun path builder ->
|
fun path builder ->
|
||||||
let dir, insert = insert path root in
|
let dir, insert = insert path root in
|
||||||
match dir with
|
match dir with
|
||||||
@ -692,11 +679,7 @@ module Make (Encoding : ENCODING) = struct
|
|||||||
| Static ({ subdirs = Some _ ; _ }) -> conflict path CDir
|
| Static ({ subdirs = Some _ ; _ }) -> conflict path CDir
|
||||||
| Dynamic _ -> conflict path CBuilder
|
| Dynamic _ -> conflict path CBuilder
|
||||||
| DynamicTail _ -> conflict path CTail in
|
| DynamicTail _ -> conflict path CTail in
|
||||||
match path with
|
register path builder
|
||||||
| Path p -> register p builder
|
|
||||||
| MappedPath (p, map, _) ->
|
|
||||||
register p
|
|
||||||
(fun args -> builder (map args) >|= map_directory map)
|
|
||||||
|
|
||||||
let register_describe_directory_service
|
let register_describe_directory_service
|
||||||
: type pr.
|
: type pr.
|
||||||
|
@ -28,7 +28,7 @@ let dir =
|
|||||||
(fun i j () () -> Lwt.return (`Ok (float_of_int i+.j)))
|
(fun i j () () -> Lwt.return (`Ok (float_of_int i+.j)))
|
||||||
let dir =
|
let dir =
|
||||||
register dir alternate_add_service'
|
register dir alternate_add_service'
|
||||||
(fun (i,j) () () -> Lwt.return (`Ok (i+j)))
|
(fun (((),i),j) () () -> Lwt.return (`Ok (i+ int_of_float j)))
|
||||||
let dir =
|
let dir =
|
||||||
register dir dummy_service
|
register dir dummy_service
|
||||||
(fun ((((((((),_a), _b), _c), _d), _e), _f), _g) () () -> Lwt.return (`Ok ()))
|
(fun ((((((((),_a), _b), _c), _d), _e), _f), _g) () () -> Lwt.return (`Ok ()))
|
||||||
|
@ -69,7 +69,7 @@ module Test(Request : sig
|
|||||||
assert (test add_service ((), 2) 3 5) ;
|
assert (test add_service ((), 2) 3 5) ;
|
||||||
assert (test alternate_add_service (((), 1), 2.5) () 3.5) ;
|
assert (test alternate_add_service (((), 1), 2.5) () 3.5) ;
|
||||||
assert (test real_minus_service1 (((), 2.5), 1) () 1.5) ;
|
assert (test real_minus_service1 (((), 2.5), 1) () 1.5) ;
|
||||||
assert (test alternate_add_service' (1, 2) () 3) ;
|
assert (test alternate_add_service' (((), 1), 2.) () 3) ;
|
||||||
()
|
()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -43,10 +43,7 @@ let alternate_add_service' =
|
|||||||
~input:Json_encoding.null
|
~input:Json_encoding.null
|
||||||
~output:Json_encoding.int
|
~output:Json_encoding.int
|
||||||
~error:Json_encoding.empty
|
~error:Json_encoding.empty
|
||||||
Path.(map
|
Path.(root / "bar" /: Arg.int /: Arg.float / "add")
|
||||||
(fun (((),i),f) -> (i,int_of_float f))
|
|
||||||
(fun (i,f) -> (((),i),float_of_int f))
|
|
||||||
(root / "bar" /: Arg.int /: Arg.float / "add"))
|
|
||||||
|
|
||||||
let minus_service =
|
let minus_service =
|
||||||
post_service
|
post_service
|
||||||
|
117
vendors/ocplib-resto/lib_resto/resto.ml
vendored
117
vendors/ocplib-resto/lib_resto/resto.ml
vendored
@ -69,57 +69,35 @@ module Internal = struct
|
|||||||
let from_arg x = x
|
let from_arg x = x
|
||||||
let to_arg x = x
|
let to_arg x = x
|
||||||
|
|
||||||
type (_,_) rpath =
|
|
||||||
| Root : ('rkey, 'rkey) rpath
|
|
||||||
| Static : ('rkey, 'key) rpath * string -> ('rkey, 'key) rpath
|
|
||||||
| Dynamic : ('rkey, 'key) rpath * 'a arg -> ('rkey, 'key * 'a) rpath
|
|
||||||
| DynamicTail : ('rkey, 'key) rpath * 'a arg -> ('rkey, 'key * 'a list) rpath
|
|
||||||
|
|
||||||
type (_,_) path =
|
type (_,_) path =
|
||||||
| Path: ('prefix, 'params) rpath -> ('prefix, 'params) path
|
| Root : ('rkey, 'rkey) path
|
||||||
| MappedPath:
|
| Static : ('rkey, 'key) path * string -> ('rkey, 'key) path
|
||||||
('prefix, 'key) rpath * ('key -> 'params) * ('params -> 'key) ->
|
| Dynamic : ('rkey, 'key) path * 'a arg -> ('rkey, 'key * 'a) path
|
||||||
('prefix, 'params) path
|
| DynamicTail : ('rkey, 'key) path * 'a arg -> ('rkey, 'key * 'a list) path
|
||||||
|
|
||||||
let rec rsubst0 : type a b. (a, a) rpath -> (b, b) rpath = function
|
let rec subst0 : type a b. (a, a) path -> (b, b) path = function
|
||||||
| Root -> Root
|
| Root -> Root
|
||||||
| Static (rpath, name) -> Static (rsubst0 rpath, name)
|
| Static (path, name) -> Static (subst0 path, name)
|
||||||
| Dynamic (rpath, arg) -> assert false (* impossible *)
|
| Dynamic (path, arg) -> assert false (* impossible *)
|
||||||
| DynamicTail (rpath, arg) -> assert false (* impossible *)
|
| DynamicTail (path, arg) -> assert false (* impossible *)
|
||||||
|
|
||||||
let subst0 = function
|
let rec subst1 : type a b c. (a, a * c) path -> (b, b * c) path = function
|
||||||
| Path rpath -> Path (rsubst0 rpath)
|
|
||||||
| MappedPath _ -> invalid_arg "Resto.Path.subst0"
|
|
||||||
|
|
||||||
let rec rsubst1 : type a b c. (a, a * c) rpath -> (b, b * c) rpath = function
|
|
||||||
| Root -> assert false (* impossible *)
|
| Root -> assert false (* impossible *)
|
||||||
| Static (rpath, name) -> Static (rsubst1 rpath, name)
|
| Static (path, name) -> Static (subst1 path, name)
|
||||||
| Dynamic (rpath, arg) -> Dynamic (rsubst0 rpath, arg)
|
| Dynamic (path, arg) -> Dynamic (subst0 path, arg)
|
||||||
| DynamicTail (rpath, arg) -> DynamicTail (rsubst0 rpath, arg)
|
| DynamicTail (path, arg) -> DynamicTail (subst0 path, arg)
|
||||||
|
|
||||||
let subst1 = function
|
let rec subst2 : type a b c d. (a, (a * c) * d) path -> (b, (b * c) * d) path = function
|
||||||
| Path rpath -> Path (rsubst1 rpath)
|
|
||||||
| MappedPath _ -> invalid_arg "Resto.Path.subst1"
|
|
||||||
|
|
||||||
let rec rsubst2 : type a b c d. (a, (a * c) * d) rpath -> (b, (b * c) * d) rpath = function
|
|
||||||
| Root -> assert false (* impossible *)
|
| Root -> assert false (* impossible *)
|
||||||
| Static (rpath, name) -> Static (rsubst2 rpath, name)
|
| Static (path, name) -> Static (subst2 path, name)
|
||||||
| Dynamic (rpath, arg) -> Dynamic (rsubst1 rpath, arg)
|
| Dynamic (path, arg) -> Dynamic (subst1 path, arg)
|
||||||
| DynamicTail (rpath, arg) -> DynamicTail (rsubst1 rpath, arg)
|
| DynamicTail (path, arg) -> DynamicTail (subst1 path, arg)
|
||||||
|
|
||||||
let subst2 = function
|
let rec subst3 : type a b c d e. (a, ((a * c) * d) * e) path -> (b, ((b * c) * d) * e) path = function
|
||||||
| Path rpath -> Path (rsubst2 rpath)
|
|
||||||
| MappedPath _ -> invalid_arg "Resto.Path.subst2"
|
|
||||||
|
|
||||||
let rec rsubst3 : type a b c d e. (a, ((a * c) * d) * e) rpath -> (b, ((b * c) * d) * e) rpath = function
|
|
||||||
| Root -> assert false (* impossible *)
|
| Root -> assert false (* impossible *)
|
||||||
| Static (rpath, name) -> Static (rsubst3 rpath, name)
|
| Static (path, name) -> Static (subst3 path, name)
|
||||||
| Dynamic (rpath, arg) -> Dynamic (rsubst2 rpath, arg)
|
| Dynamic (path, arg) -> Dynamic (subst2 path, arg)
|
||||||
| DynamicTail (rpath, arg) -> DynamicTail (rsubst2 rpath, arg)
|
| DynamicTail (path, arg) -> DynamicTail (subst2 path, arg)
|
||||||
|
|
||||||
let subst3 = function
|
|
||||||
| Path rpath -> Path (rsubst3 rpath)
|
|
||||||
| MappedPath _ -> invalid_arg "Resto.Path.subst3"
|
|
||||||
|
|
||||||
let from_path x = x
|
let from_path x = x
|
||||||
let to_path x = x
|
let to_path x = x
|
||||||
@ -245,52 +223,33 @@ module Path = struct
|
|||||||
|
|
||||||
type ('a, 'b) t = ('a, 'b) Internal.path
|
type ('a, 'b) t = ('a, 'b) Internal.path
|
||||||
type ('a, 'b) path = ('a, 'b) Internal.path
|
type ('a, 'b) path = ('a, 'b) Internal.path
|
||||||
type ('a, 'b) rpath = ('a, 'b) Internal.rpath
|
|
||||||
|
|
||||||
type 'prefix context = ('prefix, 'prefix) path
|
type 'prefix context = ('prefix, 'prefix) path
|
||||||
|
|
||||||
let root = Path Root
|
let root = Root
|
||||||
let open_root = Path Root
|
let open_root = Root
|
||||||
|
|
||||||
let add_suffix (type p pr) (path : (p, pr) path) name =
|
let add_suffix (type p pr) (path : (p, pr) path) name =
|
||||||
match path with
|
match path with
|
||||||
| Path (DynamicTail _) -> invalid_arg "Resto.Path.add_suffix"
|
| DynamicTail _ -> invalid_arg "Resto.Path.add_suffix"
|
||||||
| MappedPath (DynamicTail _, _, _) -> invalid_arg "Resto.Path.add_suffix"
|
| path -> Static (path, name)
|
||||||
| Path path -> Path (Static (path, name))
|
|
||||||
| MappedPath (path, map, rmap) ->
|
|
||||||
MappedPath (Static (path, name), map, rmap)
|
|
||||||
|
|
||||||
let add_arg (type p pr) (path : (p, pr) path) arg =
|
let add_arg (type p pr) (path : (p, pr) path) arg =
|
||||||
match path with
|
match path with
|
||||||
| Path (DynamicTail _) -> invalid_arg "Resto.Path.add_arg"
|
| DynamicTail _ -> invalid_arg "Resto.Path.add_arg"
|
||||||
| MappedPath (DynamicTail _, _, _) -> invalid_arg "Resto.Path.add_arg"
|
| path -> Dynamic (path, arg)
|
||||||
| Path path -> Path (Dynamic (path, arg))
|
|
||||||
| MappedPath (path, map, rmap) ->
|
|
||||||
MappedPath (Dynamic (path, arg),
|
|
||||||
(fun (x, y) -> (map x, y)),
|
|
||||||
(fun (x, y) -> (rmap x, y)))
|
|
||||||
|
|
||||||
let add_final_args (type p pr) (path : (p, pr) path) arg =
|
let add_final_args (type p pr) (path : (p, pr) path) arg =
|
||||||
match path with
|
match path with
|
||||||
| Path (DynamicTail _) -> invalid_arg "Resto.Path.add_final_arg"
|
| DynamicTail _ -> invalid_arg "Resto.Path.add_final_arg"
|
||||||
| MappedPath (DynamicTail _, _, _) -> invalid_arg "Resto.Path.add_final_arg"
|
| path -> DynamicTail (path, arg)
|
||||||
| Path path -> Path (DynamicTail (path, arg))
|
|
||||||
| MappedPath (path, map, rmap) ->
|
|
||||||
MappedPath (DynamicTail (path, arg),
|
|
||||||
(fun (x, y) -> (map x, y)),
|
|
||||||
(fun (x, y) -> (rmap x, y)))
|
|
||||||
|
|
||||||
let map map rmap = function
|
|
||||||
| Path p -> MappedPath (p, map, rmap)
|
|
||||||
| MappedPath (p, map', rmap') ->
|
|
||||||
MappedPath (p, (fun x -> map (map' x)), (fun x -> rmap' (rmap x)))
|
|
||||||
|
|
||||||
let prefix
|
let prefix
|
||||||
: type p pr a. (pr, a) path -> (a, p) path -> (pr, p) path
|
: type p pr a. (pr, a) path -> (a, p) path -> (pr, p) path
|
||||||
= fun p1 p2 ->
|
= fun p1 p2 ->
|
||||||
let rec prefix
|
let rec prefix
|
||||||
: type pr a k.
|
: type pr a k.
|
||||||
(pr, a) path -> (a, k) rpath -> (pr, k) path
|
(pr, a) path -> (a, k) path -> (pr, k) path
|
||||||
= fun p1 p2 ->
|
= fun p1 p2 ->
|
||||||
match p2 with
|
match p2 with
|
||||||
| Root -> p1
|
| Root -> p1
|
||||||
@ -299,12 +258,8 @@ module Path = struct
|
|||||||
| DynamicTail (path, arg) -> add_final_args (prefix p1 path) arg
|
| DynamicTail (path, arg) -> add_final_args (prefix p1 path) arg
|
||||||
in
|
in
|
||||||
match p1 with
|
match p1 with
|
||||||
| Path (DynamicTail _) -> invalid_arg "Resto.Path.prefix"
|
| DynamicTail _ -> invalid_arg "Resto.Path.prefix"
|
||||||
| MappedPath (DynamicTail _, _, _) -> invalid_arg "Resto.Path.prefix"
|
| _ -> prefix p1 p2
|
||||||
| _ ->
|
|
||||||
match p2 with
|
|
||||||
| Path p2 -> prefix p1 p2
|
|
||||||
| MappedPath (p2, m, rm) -> map m rm (prefix p1 p2)
|
|
||||||
|
|
||||||
let (/) = add_suffix
|
let (/) = add_suffix
|
||||||
let (/:) = add_arg
|
let (/:) = add_arg
|
||||||
@ -658,10 +613,6 @@ module MakeService(Encoding : ENCODING) = struct
|
|||||||
let subst2 s = { s with path = Internal.subst2 s.path }
|
let subst2 s = { s with path = Internal.subst2 s.path }
|
||||||
let subst3 s = { s with path = Internal.subst3 s.path }
|
let subst3 s = { s with path = Internal.subst3 s.path }
|
||||||
|
|
||||||
let map f g (s : (_,_,_,_,_,_,_) service) =
|
|
||||||
{ s with path = Path.map f g s.path }
|
|
||||||
|
|
||||||
|
|
||||||
let meth = fun { meth } -> meth
|
let meth = fun { meth } -> meth
|
||||||
|
|
||||||
let query
|
let query
|
||||||
@ -711,7 +662,7 @@ module MakeService(Encoding : ENCODING) = struct
|
|||||||
: type pr p. (pr, p) path -> p -> string list
|
: type pr p. (pr, p) path -> p -> string list
|
||||||
= fun path args ->
|
= fun path args ->
|
||||||
let rec forge_request_args
|
let rec forge_request_args
|
||||||
: type k. (pr, k) rpath -> k -> string list -> string list
|
: type k. (pr, k) path -> k -> string list -> string list
|
||||||
= fun path args acc ->
|
= fun path args acc ->
|
||||||
match path, args with
|
match path, args with
|
||||||
| Root, _ ->
|
| Root, _ ->
|
||||||
@ -723,9 +674,7 @@ module MakeService(Encoding : ENCODING) = struct
|
|||||||
| DynamicTail (path, arg), (args, xs) ->
|
| DynamicTail (path, arg), (args, xs) ->
|
||||||
forge_request_args path args
|
forge_request_args path args
|
||||||
(List.fold_right (fun x acc -> arg.construct x :: acc) xs acc) in
|
(List.fold_right (fun x acc -> arg.construct x :: acc) xs acc) in
|
||||||
match path with
|
forge_request_args path args []
|
||||||
| Path path -> forge_request_args path args []
|
|
||||||
| MappedPath (path, _, rmap) -> forge_request_args path (rmap args) []
|
|
||||||
|
|
||||||
let forge_request_query
|
let forge_request_query
|
||||||
: type q. q query -> q -> (string * string) list
|
: type q. q query -> q -> (string * string) list
|
||||||
|
23
vendors/ocplib-resto/lib_resto/resto.mli
vendored
23
vendors/ocplib-resto/lib_resto/resto.mli
vendored
@ -75,9 +75,6 @@ module Path : sig
|
|||||||
val prefix:
|
val prefix:
|
||||||
('prefix, 'a) path -> ('a, 'params) path -> ('prefix, 'params) path
|
('prefix, 'a) path -> ('a, 'params) path -> ('prefix, 'params) path
|
||||||
|
|
||||||
val map:
|
|
||||||
('a -> 'b) -> ('b -> 'a) -> ('prefix, 'a) path -> ('prefix, 'b) path
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Service directory description *)
|
(** Service directory description *)
|
||||||
@ -192,17 +189,11 @@ module Internal : sig
|
|||||||
val from_arg : 'a arg -> 'a Arg.t
|
val from_arg : 'a arg -> 'a Arg.t
|
||||||
val to_arg : 'a Arg.t -> 'a arg
|
val to_arg : 'a Arg.t -> 'a arg
|
||||||
|
|
||||||
type (_, _) rpath =
|
|
||||||
| Root : ('rkey, 'rkey) rpath
|
|
||||||
| Static : ('rkey, 'key) rpath * string -> ('rkey, 'key) rpath
|
|
||||||
| Dynamic : ('rkey, 'key) rpath * 'a arg -> ('rkey, 'key * 'a) rpath
|
|
||||||
| DynamicTail : ('rkey, 'key) rpath * 'a arg -> ('rkey, 'key * 'a list) rpath
|
|
||||||
|
|
||||||
type (_, _) path =
|
type (_, _) path =
|
||||||
| Path: ('prefix, 'params) rpath -> ('prefix, 'params) path
|
| Root : ('rkey, 'rkey) path
|
||||||
| MappedPath:
|
| Static : ('rkey, 'key) path * string -> ('rkey, 'key) path
|
||||||
('prefix, 'key) rpath * ('key -> 'params) * ('params -> 'key) ->
|
| Dynamic : ('rkey, 'key) path * 'a arg -> ('rkey, 'key * 'a) path
|
||||||
('prefix, 'params) path
|
| DynamicTail : ('rkey, 'key) path * 'a arg -> ('rkey, 'key * 'a list) path
|
||||||
|
|
||||||
val from_path : ('a, 'b) path -> ('a, 'b) Path.t
|
val from_path : ('a, 'b) path -> ('a, 'b) Path.t
|
||||||
val to_path : ('a, 'b) Path.t -> ('a, 'b) path
|
val to_path : ('a, 'b) Path.t -> ('a, 'b) path
|
||||||
@ -338,12 +329,6 @@ module MakeService(Encoding : ENCODING) : sig
|
|||||||
('meth, 'prefix, 'params,
|
('meth, 'prefix, 'params,
|
||||||
'query, 'input, 'output, 'error) service
|
'query, 'input, 'output, 'error) service
|
||||||
|
|
||||||
val map:
|
|
||||||
('a -> 'b) ->
|
|
||||||
('b -> 'a) ->
|
|
||||||
('meth, 'pr, 'a, 'q, 'i, 'o, 'e) service ->
|
|
||||||
('meth, 'pr, 'b, 'q, 'i, 'o, 'e) service
|
|
||||||
|
|
||||||
val subst0:
|
val subst0:
|
||||||
([< meth ] as 'm, 'p, 'p, 'q, 'i, 'o, 'e) service ->
|
([< meth ] as 'm, 'p, 'p, 'q, 'i, 'o, 'e) service ->
|
||||||
('m, 'p2, 'p2, 'q, 'i, 'o, 'e) service
|
('m, 'p2, 'p2, 'q, 'i, 'o, 'e) service
|
||||||
|
Loading…
Reference in New Issue
Block a user