Module Brr.Store

module Store: sig .. end
Persistent storage.

Persisent key-value store implemented over webstorage. Safe if no one tampers with the storage outside of the program. FIXME/TODO this still relies on the jsoo representation, add safer keys with type indexed codecs.

Storage scope

type scope = [ `Persist | `Session ] 
The storage scope.
val support : scope -> bool
support scope is true iff values can be stored in scope.


type 'a key 
The type for keys whose lookup value is 'a
val key : ?ns:Brr.Jstr.t -> unit -> 'a key
key ~ns () is a new storage key in namespace ns. If ns is unspecified, the key lives in a global namespace.

Warning. Reordering invocations of Brr.Store.key in the same namespace will most of the time corrupt existing storage. This means that all Brr.Store.key calls should always be performed at initialization time. Brr.Store.force_version can be used to easily version your store and aleviate this problem.


In the functions below scope defaults to `Persist.

val mem : ?scope:scope -> 'a key -> bool
mem k is true iff k has a mapping.
val add : ?scope:scope -> 'a key -> 'a -> unit
add k v maps k to v.
val rem : ?scope:scope -> 'a key -> unit
rem k unbinds k.
val find : ?scope:scope -> 'a key -> 'a option
find k is k's mapping in m, if any.
val get : ?scope:scope -> ?absent:'a -> 'a key -> 'a
get k is k's mapping. If absent is provided and m has not binding for k, absent is returned.
Raises Invalid_argument if k is not bound and absent is unspecified or if scope is not Brr.Store.supported.
val clear : ?scope:scope -> unit -> unit
clear (), clears all mapping.


val force_version : ?scope:scope -> string -> unit
force_version v checks that the version of the store is v. If it's not it Brr.Store.clears the store and sets the version to v.