2019-09-05 17:21:01 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
|
|
|
(* copy of this software and associated documentation files (the "Software"),*)
|
|
|
|
(* to deal in the Software without restriction, including without limitation *)
|
|
|
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
|
|
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
|
|
|
(* Software is furnished to do so, subject to the following conditions: *)
|
|
|
|
(* *)
|
|
|
|
(* The above copyright notice and this permission notice shall be included *)
|
|
|
|
(* in all copies or substantial portions of the Software. *)
|
|
|
|
(* *)
|
|
|
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
|
|
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
|
|
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
|
|
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
|
|
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
|
|
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
|
|
|
(* DEALINGS IN THE SOFTWARE. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
|
|
|
|
|
|
|
(** Typed description of the key-value context. *)
|
|
|
|
type 'key t
|
|
|
|
|
|
|
|
(** Trivial display of the key-value context layout. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val pp : Format.formatter -> 'key t -> unit
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Export an RPC hierarchy for querying the context. There is one service
|
|
|
|
by possible path in the context. Services for "directory" are able to
|
|
|
|
aggregate in one JSON object the whole subtree. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val build_directory : 'key t -> 'key RPC_directory.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Create a empty context description,
|
|
|
|
keys will be registred by side effects. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val create : unit -> 'key t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Register a single key accessor at a given path. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val register_value :
|
2019-09-05 17:21:01 +04:00
|
|
|
'key t ->
|
|
|
|
get:('key -> 'a option tzresult Lwt.t) ->
|
2020-02-12 20:40:17 +04:00
|
|
|
'a Data_encoding.t ->
|
|
|
|
unit
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Return a description for a prefixed fragment of the given context.
|
|
|
|
All keys registred in the subcontext will be shared by the external
|
|
|
|
context *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val register_named_subcontext : 'key t -> string list -> 'key t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Description of an index as a sequence of `RPC_arg.t`. *)
|
|
|
|
type (_, _, _) args =
|
2020-02-12 20:40:17 +04:00
|
|
|
| One : {
|
|
|
|
rpc_arg : 'a RPC_arg.t;
|
|
|
|
encoding : 'a Data_encoding.t;
|
|
|
|
compare : 'a -> 'a -> int;
|
|
|
|
}
|
|
|
|
-> ('key, 'a, 'key * 'a) args
|
|
|
|
| Pair :
|
|
|
|
('key, 'a, 'inter_key) args * ('inter_key, 'b, 'sub_key) args
|
|
|
|
-> ('key, 'a * 'b, 'sub_key) args
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Return a description for a indexed sub-context.
|
|
|
|
All keys registred in the subcontext will be shared by the external
|
|
|
|
context. One should provide a function to list all the registred
|
|
|
|
index in the context. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val register_indexed_subcontext :
|
2019-09-05 17:21:01 +04:00
|
|
|
'key t ->
|
|
|
|
list:('key -> 'arg list tzresult Lwt.t) ->
|
2020-02-12 20:40:17 +04:00
|
|
|
('key, 'arg, 'sub_key) args ->
|
|
|
|
'sub_key t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Helpers for manipulating and defining indexes. *)
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
val pack : ('key, 'a, 'sub_key) args -> 'key -> 'a -> 'sub_key
|
|
|
|
|
|
|
|
val unpack : ('key, 'a, 'sub_key) args -> 'sub_key -> 'key * 'a
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
module type INDEX = sig
|
|
|
|
type t
|
2020-02-12 20:40:17 +04:00
|
|
|
|
|
|
|
val path_length : int
|
|
|
|
|
|
|
|
val to_path : t -> string list -> string list
|
|
|
|
|
|
|
|
val of_path : string list -> t option
|
|
|
|
|
|
|
|
val rpc_arg : t RPC_arg.t
|
|
|
|
|
|
|
|
val encoding : t Data_encoding.t
|
|
|
|
|
|
|
|
val compare : t -> t -> int
|
2019-09-05 17:21:01 +04:00
|
|
|
end
|