Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file store_sigs.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs, <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Trili Tech, <contact@trili.tech> *)(* *)(* 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. *)(* *)(*****************************************************************************)(** The type of a [path]. [path]s are [strings]. They are used to determine
the location where the data should be persisted on disk. *)typepath=stringlist(** Keys in Map-like storage functors are represented as strings. *)typekey_path_representation=stringtyperw=[`Read|`Write]typero=[`Read]type_mode=Read_only:romode|Read_write:rwmode(** [BACKEND] is the module type defining the backend for persisting data to
disk. It is used by the functors in [Store_utils] to create Storage
modules that persist data structures on disk. *)moduletypeBACKEND=sig(** The type for representing storage backends that can be accessed by the
module. The type parameter indicates whether the storage can be only read
or both read and written. *)type+'at(** [name] is the name of the store. *)valname:string(** [make_key_path path raw_key] constructs a new path from [path]
and the [raw_key] key_path_representation. *)valmake_key_path:path->key_path_representation->path(** [load location] loads the backend storage from [location]. *)valload:'amode->string->'attzresultLwt.t(** [flush location] flushes to disk a sequence of changes to the data stored
at [location]. *)valflush:[>`Write]t->unittzresult(** [close t] closes the storage backend [t]. *)valclose:_t->unittzresultLwt.t(** [set_exn t path b] sets the contents for the store [t] at [path] to the
sequence of bytes [b]. The write operation can fail, in which case an
exception is thrown. *)valset:[>`Write]t->path->bytes->unittzresultLwt.t(** [get t path] returns the contents for the store [t] at the location
indicated by [path]. It can fail if [t] does not have any content
stored at [path]. *)valget:[>`Read]t->path->bytestzresultLwt.t(** [mem t path] returns whether the storage backend [t] contains any
data at the location indicated by [path]. *)valmem:[>`Read]t->path->booltzresultLwt.t(** [find t path] is the same as [get t path], except that an optional
value is returned. This value is [None] if the backend storage [t]
does not have any content stored at location [path]. *)valfind:[>`Read]t->path->bytesoptiontzresultLwt.t(** [path_to_string] converts a path to a string. *)valpath_to_string:path->string(** [readonly t] returns a read only version of the storage [t]. *)valreadonly:[>`Read]t->[`Read]tend(** Module type respresenting a [Mutable_value] that is persisted on store. *)moduletypeMutable_value=sig(** The type of the [store] that is used for persisting data on disk. *)type+'astore(** The type of the values that will be persisted. *)typevalue(** Path in the irmin tree. *)valpath_key:path(** [set store value] persists [value] for this [Mutable_value] on [store]. *)valset:[>`Write]store->value->unittzresultLwt.t(** [get store] retrieves the value persisted in [store] for this
[Mutable_value]. If the underlying storage backend fails to retrieve the
contents of the mutable value by throwing an exception, then the
exception is propagated by [get store]. *)valget:[>`Read]store->valuetzresultLwt.t(** [find store] returns an optional value containing the value persisted
in [store] for this [Mutable_value]. If no value is persisted for the
[Mutable_value], [None] is returned. *)valfind:[>`Read]store->valueoptiontzresultLwt.tend(** This module contains information about where to store and retrieve contents
of storage persisted on disk. *)moduletypeSTORAGE_INFO=sig(** [path] is a value of type path, it identifies the location of a piece of
storage in the underlying store. *)valpath:pathend(** [KEY] is a module type used to construct [Map]-like storage modules.
It defines how keys are used to determine a path on disk. *)moduletypeKEY=sig(** [key] is the type used for keys of maps persisted on disk. *)typekeyvalto_path_representation:key->key_path_representationend(** [VALUE] is a module type to define values that will be persisted on disk
via storage modules. *)moduletypeVALUE=sig(** The type of the [value] being persisted on disk. *)typevalue(** [name] is a string for identifying values of this type. It is
used by encoders of [Map]-like storage modules. *)valname:string(** [encoding] defines how values are serialized and deserialized when being
written to or read from the underlying store. *)valencoding:valueData_encoding.tend(** Generic module type for maps to be persisted on disk. *)moduletypeMap=sig(** The type of the [store] that is used for persisting data on disk. *)type+'astore(** The type of keys persisted by the map. *)typekey(** The type of values persisted by the map. *)typevalue(** Path in the irmin tree. *)valpath:path(** [mem store key] checks whether there is a binding of the map for key [key]
in [store]. *)valmem:[>`Read]store->key->booltzresultLwt.t(** [get store key] retrieves from [store] the value associated with [key] in
the map. It raises an error if such a value does not exist. *)valget:[>`Read]store->key->valuetzresultLwt.t(** [find store key] retrieves from [store] the value associated with [key]
in the map. If the value exists it is returned as an optional value.
Otherwise, [None] is returned. *)valfind:[>`Read]store->key->valueoptiontzresultLwt.t(** [find_with_default ~on_default store key] retrieves from [store] the
value associated with [key] in the map.
If the value exists it is returned as is.
Otherwise, [on_default] is returned. *)valfind_with_default:[>`Read]store->key->on_default:(unit->value)->valuetzresultLwt.t(** [add store key value] adds a binding from [key] to [value] to the map, and
persists it to disk. *)valadd:[>`Write]store->key->value->unittzresultLwt.tend(** Generic module type for append-only maps to be persisted on disk. *)moduletypeAppend_only_map=sigincludeMap(** [add store key value] adds a binding from [key] to [value] to the map, and
persists it to disk. If [key] already exists in the store, it must be
bound to [value]. *)valadd:rwstore->key->value->unittzresultLwt.tend(** [Nested_map] is a map where values are indexed by both a primary and
secondary key. It allows more flexibility over a map whose keys are
tupls of the form `(primary_key, secondary_key)`. In particular, it
provides functions to retrieve all the bindings in a map that share the
same primary_key.
*)moduletypeNested_map=sig(** The type of the [store] that is used for persisting data on disk. *)type+'astore(** [primary_key] is the type of primary keys for the [Nested_map]. *)typeprimary_key(** [secondary_key] is the type of secondary keys for the [Nested_map]. *)typesecondary_key(** [value] is the type of values that are going to be persisted on disk,
indexed by primary and secondary key. *)typevalue(** Path in the irmin tree. *)valpath:path(** [mem store ~primary_key ~secondary_key] returns whether there is a
value for the nested map persisted on [store] for the nested map,
indexed by [primary_key] and then by [secondary_key]. *)valmem:[>`Read]store->primary_key:primary_key->secondary_key:secondary_key->booltzresultLwt.t(** [get store ~primary_key ~secondary_key] retrieves from [store] the value
of the nested map associated with [primary_key] and [secondary_key], if
any. If such a value does not exist, it fails with error
[Store_errors.Cannot_read_key_from_store k], where [k] is the string
representation of the primary key. *)valget:[>`Read]store->primary_key:primary_key->secondary_key:secondary_key->valuetzresultLwt.t(** [find store ~primary_key ~secondary_key] is the same as
[get store ~primary_key ~secondary_key], except that no error is thrown
and an optional value is returned instead. The returned value is
[None] if there is not a value bound to [primary_key] and [seconary_key]
in the [store] for the [Nested_map]. *)valfind:[>`Read]store->primary_key:primary_key->secondary_key:secondary_key->valueoptiontzresultLwt.t(** [list secondary_keys store ~primary_key] retrieves from [store] the list
of bindings of the nested map that share the same [~primary_key]. For
each of these bindings, both the secondary_key and value are returned. *)vallist_secondary_keys_with_values:[>`Read]store->primary_key:primary_key->(secondary_key*value)listtzresultLwt.t(** [list_secondary_keys store ~primary_key] retrieves from [store]
the list of secondary_keys for which a value indexed by both
[primary_key] and secondary key is persisted on disk. *)vallist_secondary_keys:[>`Read]store->primary_key:primary_key->secondary_keylisttzresultLwt.t(** [list_values store ~primary_key] retrieves from [store] the list of
values for which a binding with primary key [primary_key] and
arbitrary secondary key exists. *)vallist_values:[>`Read]store->primary_key:primary_key->valuelisttzresultLwt.t(** [add store ~primary_key ~secondary_key value] persists [value] to
disk. The value is bound to the [primary_key] and [secondary_key].
*)valadd:rwstore->primary_key:primary_key->secondary_key:secondary_key->value->unittzresultLwt.tend(** [COMPARABLE_KEY] is a module type used to define secondary keys in nested
maps. *)moduletypeCOMPARABLE_KEY=sig(** The type of a comparable [key]. *)typekey(** [name] is a string to identify the value of [key]s. *)valname:string(** [compare key1 key2] compares [key1] with [key2]. *)valcompare:key->key->int(** [encoding] is the encoding for values of type [key]. *)valencoding:keyData_encoding.tendmoduletypeStore=sigtype+'at(** [Make_updatable_map(S)(K)(V)] constructs a [Map] which can be persisted on
store. The module [S] defines storage-dependent information about how the
map will be saved on and retrieved from the store (for example, it defines
the map location in the store). The module [K] defines the information
related to keys of the map, and the module [V] contains information about
how values will be stored to and retrieved from the store. The resulting
map allows to update the contents of an existing value for a key.
*)moduleMake_updatable_map(S:STORAGE_INFO)(K:KEY)(V:VALUE):Mapwithtype'astore='atandtypekey=K.keyandtypevalue=V.value(** [Make_append_only_map(S)(K)(V)] constructs an [Append_only_map] which can be
persisted on store. The module [S] defines storage-dependent information
about how the map will be saved on and retrieved from the store (for
example, it defines the map location in the store). The module [K]
contains information related to keys of the map, and the module [V]
contains information about how values will be stored to and retrieved from
the store. The resulting map forbids updating the contents of an existing
value with a new value, different from the previous one.
*)moduleMake_append_only_map(S:STORAGE_INFO)(K:KEY)(V:VALUE):Append_only_mapwithtype'astore='atandtypekey=K.keyandtypevalue=V.value(** [Make_mutable_value(S)(V)] constructs a [Mutable_value] for persisting a
mutable value in a store. The module parameter [S] defines the location of
the mutable value in the store, and the module parameter [V] contains
information about the type of values that the constructed module will
persist in the underlying store. *)moduleMake_mutable_value(S:STORAGE_INFO)(V:VALUE):Mutable_valuewithtype'astore='atandtypevalue=V.value(** Make_nested_map(S)(K1)(K2)(V) constructs a [Nested_map] module using
module parameter [S] to define where the map is going to be persisted on
store, [K1] and [K2] to define the primary and secondary key,
respectively, and [V] to define the values of the resulting
[Nested_map]. *)moduleMake_nested_map(S:STORAGE_INFO)(K1:KEY)(K2:COMPARABLE_KEY)(V:VALUE):Nested_mapwithtype'astore='atandtypeprimary_key=K1.keyandtypesecondary_key=K2.keyandtypevalue=V.valueend