Database.Purversion
- Package
- purescript-purversion
- Repository
- Quelklef/purversion
#make Source
make :: forall val de mv. Monad mv => Traversable mv => { decode :: String -> de val, encode :: val -> String, key :: String, migrations :: Array (String -> mv String) } -> Effect (mv (Purverse mv de val))
Create a Purversion-managed localStorage key.
This will first run all migrations for the key, failing in mv
if any migration fails.
If no failure is encountered, then a Purversion
value is produced and returned,
which can be used with the rest of the API to interact with the localStorage key.
#load Source
load :: forall val de mv. Purverse mv de val -> Effect (de val)
Read the value of out a Purverse
key.
This reads the String
value from localStorage, and then
transforms it into a val
with .decode
.
Two kinds of failures are possible:
In
de
, if the decoding fails.In
Effect
, if the localStorage values have been edited by an outside agent, such as non-Purversion code or the programmer
#Purverse Source
data Purverse mv de val
Represents a localStorage key which is managed by Purversion
By "managed" I mean that Purversion equips the native string localStorage value with:
- a rich type, via
encode
anddecode
; and - versioning, via
migrations
Each Purverse
value must be created via make
. This is to ensure that one cannot
save
to or load
from a key that has not been migrated.
The type variables have the following meaning:
mv :: Type -> Type
provides a context to migrations, allowing failures. Ex:Either String
,Maybe
. Also seemake
.de :: Type -> Type
provides a context to decoding, allowing failures. Ex:Either String
,Maybe
. Also seeload
.val :: Type
is the type of the values being stored by Purversion. Also seesave
,load
.
- Modules
- Database.
Purversion