Module

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:

  1. In de, if the decoding fails.

  2. In Effect, if the localStorage values have been edited by an outside agent, such as non-Purversion code or the programmer

#save Source

save :: forall val de mv. Purverse mv de val -> val -> Effect Unit

Save a value into a Purverse key.

This first encodes the value down to a String via .encode, and then saves that string into localStorage.

#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:

  1. a rich type, via encode and decode; and
  2. 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 see make.

  • de :: Type -> Type provides a context to decoding, allowing failures. Ex: Either String, Maybe. Also see load.

  • val :: Type is the type of the values being stored by Purversion. Also see save, load.