avers-0.0.17.1: Server-side implementation of the Avers storage model

Safe HaskellNone
LanguageHaskell2010

Avers

Contents

Synopsis

The Avers Monad

data Avers a #

Instances

Monad Avers # 

Methods

(>>=) :: Avers a -> (a -> Avers b) -> Avers b #

(>>) :: Avers a -> Avers b -> Avers b #

return :: a -> Avers a #

fail :: String -> Avers a #

Functor Avers # 

Methods

fmap :: (a -> b) -> Avers a -> Avers b #

(<$) :: a -> Avers b -> Avers a #

Applicative Avers # 

Methods

pure :: a -> Avers a #

(<*>) :: Avers (a -> b) -> Avers a -> Avers b #

(*>) :: Avers a -> Avers b -> Avers b #

(<*) :: Avers a -> Avers b -> Avers a #

MonadIO Avers # 

Methods

liftIO :: IO a -> Avers a #

MonadAvers Avers # 

Methods

liftAvers :: Avers a -> Avers a #

MonadError AversError Avers # 

Methods

throwError :: AversError -> Avers a #

catchError :: Avers a -> (AversError -> Avers a) -> Avers a #

MonadState Handle Avers # 

Methods

get :: Avers Handle #

put :: Handle -> Avers () #

state :: (Handle -> (a, Handle)) -> Avers a #

Types

newtype Path #

Path

Constructors

Path 

Fields

Instances

Eq Path # 

Methods

(==) :: Path -> Path -> Bool #

(/=) :: Path -> Path -> Bool #

Ord Path # 

Methods

compare :: Path -> Path -> Ordering #

(<) :: Path -> Path -> Bool #

(<=) :: Path -> Path -> Bool #

(>) :: Path -> Path -> Bool #

(>=) :: Path -> Path -> Bool #

max :: Path -> Path -> Path #

min :: Path -> Path -> Path #

Show Path # 

Methods

showsPrec :: Int -> Path -> ShowS #

show :: Path -> String #

showList :: [Path] -> ShowS #

IsString Path # 

Methods

fromString :: String -> Path #

Generic Path # 

Associated Types

type Rep Path :: * -> * #

Methods

from :: Path -> Rep Path x #

to :: Rep Path x -> Path #

ToJSON Path # 
FromJSON Path # 
ToDatum Path # 

Methods

toDatum :: Path -> Datum #

FromDatum Path # 
type Rep Path # 
type Rep Path = D1 (MetaData "Path" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" True) (C1 (MetaCons "Path" PrefixI True) (S1 (MetaSel (Just Symbol "unPath") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text)))

class Pk a where #

Pk - Types which can be converted to a database primary key.

Minimal complete definition

toPk

Methods

toPk :: a -> Text #

Instances

Pk Text # 

Methods

toPk :: Text -> Text #

Pk ObjectId # 

Methods

toPk :: ObjectId -> Text #

Pk RevId # 

Methods

toPk :: RevId -> Text #

Pk ObjId # 

Methods

toPk :: ObjId -> Text #

Pk Object # 

Methods

toPk :: Object -> Text #

Pk Patch # 

Methods

toPk :: Patch -> Text #

Pk Snapshot # 

Methods

toPk :: Snapshot -> Text #

Pk Secret # 

Methods

toPk :: Secret -> Text #

Pk SecretId # 

Methods

toPk :: SecretId -> Text #

Pk Blob # 

Methods

toPk :: Blob -> Text #

Pk BlobId # 

Methods

toPk :: BlobId -> Text #

Pk Session # 

Methods

toPk :: Session -> Text #

Pk SessionId # 

Methods

toPk :: SessionId -> Text #

Pk (Record a) # 

Methods

toPk :: Record a -> Text #

newtype ObjId #

ObjId

Constructors

ObjId 

Fields

Instances

Eq ObjId # 

Methods

(==) :: ObjId -> ObjId -> Bool #

(/=) :: ObjId -> ObjId -> Bool #

Ord ObjId # 

Methods

compare :: ObjId -> ObjId -> Ordering #

(<) :: ObjId -> ObjId -> Bool #

(<=) :: ObjId -> ObjId -> Bool #

(>) :: ObjId -> ObjId -> Bool #

(>=) :: ObjId -> ObjId -> Bool #

max :: ObjId -> ObjId -> ObjId #

min :: ObjId -> ObjId -> ObjId #

Show ObjId # 

Methods

showsPrec :: Int -> ObjId -> ShowS #

show :: ObjId -> String #

showList :: [ObjId] -> ShowS #

Generic ObjId # 

Associated Types

type Rep ObjId :: * -> * #

Methods

from :: ObjId -> Rep ObjId x #

to :: Rep ObjId x -> ObjId #

ToJSON ObjId # 
FromJSON ObjId # 
ToDatum ObjId # 

Methods

toDatum :: ObjId -> Datum #

FromDatum ObjId # 
Pk ObjId # 

Methods

toPk :: ObjId -> Text #

type Rep ObjId # 
type Rep ObjId = D1 (MetaData "ObjId" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" True) (C1 (MetaCons "ObjId" PrefixI True) (S1 (MetaSel (Just Symbol "unObjId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text)))

rootObjId :: ObjId #

The root object id is used for object created internally or when there is no applicable creator.

newtype RevId #

RevId

Constructors

RevId 

Fields

Instances

Enum RevId # 
Eq RevId # 

Methods

(==) :: RevId -> RevId -> Bool #

(/=) :: RevId -> RevId -> Bool #

Ord RevId # 

Methods

compare :: RevId -> RevId -> Ordering #

(<) :: RevId -> RevId -> Bool #

(<=) :: RevId -> RevId -> Bool #

(>) :: RevId -> RevId -> Bool #

(>=) :: RevId -> RevId -> Bool #

max :: RevId -> RevId -> RevId #

min :: RevId -> RevId -> RevId #

Show RevId # 

Methods

showsPrec :: Int -> RevId -> ShowS #

show :: RevId -> String #

showList :: [RevId] -> ShowS #

Generic RevId # 

Associated Types

type Rep RevId :: * -> * #

Methods

from :: RevId -> Rep RevId x #

to :: Rep RevId x -> RevId #

ToJSON RevId # 
FromJSON RevId # 
ToDatum RevId # 

Methods

toDatum :: RevId -> Datum #

FromDatum RevId # 
Pk RevId # 

Methods

toPk :: RevId -> Text #

type Rep RevId # 
type Rep RevId = D1 (MetaData "RevId" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" True) (C1 (MetaCons "RevId" PrefixI True) (S1 (MetaSel (Just Symbol "unRevId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)))

zeroRevId :: RevId #

The RevId which is used for the initial snapshot.

data ObjectId #

ObjectId

Constructors

BaseObjectId !ObjId

The base object whose snapshots contain the actual content.

ReleaseObjectId !ObjId !RevId

An object describing a particualar release of the base object.

AuthorizationObjectId !ObjId

Object which contains authorization rules.

Instances

Eq ObjectId # 
Ord ObjectId # 
Show ObjectId # 
Generic ObjectId # 

Associated Types

type Rep ObjectId :: * -> * #

Methods

from :: ObjectId -> Rep ObjectId x #

to :: Rep ObjectId x -> ObjectId #

ToJSON ObjectId # 
FromJSON ObjectId # 
ToDatum ObjectId # 

Methods

toDatum :: ObjectId -> Datum #

FromDatum ObjectId # 
Pk ObjectId # 

Methods

toPk :: ObjectId -> Text #

type Rep ObjectId # 

data Operation #

The operations that can be applied to JSON values.

Constructors

Set

Set is applied to Objects. It is used for adding, updating and deleting properties from the object.

Fields

Splice

Splice is used to manipulate Arrays. It can remove and insert multiple elements in a single operation.

Fields

Instances

Eq Operation # 
Show Operation # 
Generic Operation # 

Associated Types

type Rep Operation :: * -> * #

ToJSON Operation # 
FromJSON Operation # 
ToDatum Operation # 

Methods

toDatum :: Operation -> Datum #

FromDatum Operation # 
type Rep Operation # 

Object

data Object #

exists :: ObjId -> Avers Bool #

True if the object exists.

createObject :: ToJSON a => ObjectType a -> ObjId -> a -> Avers ObjId #

Create a new object of the given type. An initial snapshot (RevId 0) is created from the supplied content.

createObject' :: ToJSON a => ObjId -> UTCTime -> ObjectType a -> ObjId -> a -> Avers () #

A more low-level version of createObject, for use when you want to generate your own ObjId or create objects at a specific time.

lookupObject :: ObjId -> Avers Object #

Lookup an Object by its ObjId. Throws ObjectNotFound if the object doesn't exist.

deleteObject :: ObjId -> Avers () #

Mark the object as deleted.

pruneObject :: ObjId -> Avers () #

Prune the object from the database. This is only allowed if the object is marked as deleted. Note that this is a very dangerous operation, it can not be undone.

TODO: Prune related Release and Authoriation objects.

createCheckpoint :: ObjectId -> ObjId -> Avers RevId #

Create a checkpoint for for the given object. All patches (and of course snapshots) before the checkpoint can be dropped. Use vacuumObject to do that.

vacuumObject :: ObjectId -> Avers () #

Drop all patches and snapshots before the most recent checkpoint. This effectively drops the object's history, and frees space in the database.

Patch

data Patch #

Patch

data PatchError #

Constructors

UnknownPatchError !Text 

Instances

Show PatchError # 
Generic PatchError # 

Associated Types

type Rep PatchError :: * -> * #

type Rep PatchError # 
type Rep PatchError = D1 (MetaData "PatchError" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" False) (C1 (MetaCons "UnknownPatchError" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)))

Snapshot

lookupLatestSnapshot :: ObjectId -> Avers Snapshot #

Get the snapshot of the newest revision of the given object.

objectContent :: FromJSON a => ObjectId -> Avers a #

Fetch the content of the object and try to parse it.

This function will fail with a ParseError if the content can not be decoded into the desired type.

Release

createRelease :: ObjId -> RevId -> Avers () #

Create a new release of the given revision. If the object doesn't exist, it will fail with ObjectNotFound.

Patching

resolvePathIn :: Path -> Value -> Maybe Value #

Resolve the path in the object.

Session

newtype SessionId #

SessionId

Constructors

SessionId 

Fields

Instances

data Session #

The session record that is stored in the database.

A session is a unique identifier attached to a particular object. It contains the creation date and when it was last accessed. If you need to store additional data for a session, we recommend to use cookies.

data ObjectType a #

An ObjectType describes a particular type of object that is managed by Avers.

Constructors

ObjectType 

Fields

data SomeObjectType where #

lookupObjectType :: Text -> Avers SomeObjectType #

Lookup an object type which is registered in the Avers monad.

data AversError #

Instances

Show AversError # 
Generic AversError # 

Associated Types

type Rep AversError :: * -> * #

MonadError AversError Avers # 

Methods

throwError :: AversError -> Avers a #

catchError :: Avers a -> (AversError -> Avers a) -> Avers a #

type Rep AversError # 

data Config #

Configuration of the Avers monad.

Constructors

Config 

Fields

data Handle #

Instances

MonadState Handle Avers # 

Methods

get :: Avers Handle #

put :: Handle -> Avers () #

state :: (Handle -> (a, Handle)) -> Avers a #

newState :: Config -> IO (Either AversError Handle) #

Deprecated: Use newHandle instead

Blob

newtype BlobId #

BlobId

Constructors

BlobId 

Fields

Instances

Show BlobId # 
Generic BlobId # 

Associated Types

type Rep BlobId :: * -> * #

Methods

from :: BlobId -> Rep BlobId x #

to :: Rep BlobId x -> BlobId #

ToJSON BlobId # 
FromJSON BlobId # 
ToDatum BlobId # 

Methods

toDatum :: BlobId -> Datum #

FromDatum BlobId # 
Pk BlobId # 

Methods

toPk :: BlobId -> Text #

type Rep BlobId # 
type Rep BlobId = D1 (MetaData "BlobId" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" True) (C1 (MetaCons "BlobId" PrefixI True) (S1 (MetaSel (Just Symbol "unBlobId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text)))

data Blob #

Blob

Constructors

Blob 

Instances

Show Blob # 

Methods

showsPrec :: Int -> Blob -> ShowS #

show :: Blob -> String #

showList :: [Blob] -> ShowS #

Generic Blob # 

Associated Types

type Rep Blob :: * -> * #

Methods

from :: Blob -> Rep Blob x #

to :: Rep Blob x -> Blob #

ToJSON Blob # 
FromJSON Blob # 
ToDatum Blob # 

Methods

toDatum :: Blob -> Datum #

FromDatum Blob # 
Pk Blob # 

Methods

toPk :: Blob -> Text #

type Rep Blob # 
type Rep Blob = D1 (MetaData "Blob" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" False) (C1 (MetaCons "Blob" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "blobId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 BlobId)) ((:*:) (S1 (MetaSel (Just Symbol "blobSize") NoSourceUnpackedness SourceStrict DecidedUnpack) (Rec0 Int)) (S1 (MetaSel (Just Symbol "blobContentType") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)))))

Secret

newtype SecretId #

SecretId

Constructors

SecretId 

Fields

Instances

Show SecretId # 
Generic SecretId # 

Associated Types

type Rep SecretId :: * -> * #

Methods

from :: SecretId -> Rep SecretId x #

to :: Rep SecretId x -> SecretId #

ToJSON SecretId # 
FromJSON SecretId # 
ToDatum SecretId # 

Methods

toDatum :: SecretId -> Datum #

FromDatum SecretId # 
Pk SecretId # 

Methods

toPk :: SecretId -> Text #

type Rep SecretId # 
type Rep SecretId = D1 (MetaData "SecretId" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" True) (C1 (MetaCons "SecretId" PrefixI True) (S1 (MetaSel (Just Symbol "unSecretId") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text)))

data Secret #

Secret

A Secret is a password (encrypted with scrypt) that is attached to a SecretId (for example the ObjId of an account).

It is up to you to ensure that SecretIds are unique. If you use ObjIds then they by definition are.

Constructors

Secret 

Instances

Generic Secret # 

Associated Types

type Rep Secret :: * -> * #

Methods

from :: Secret -> Rep Secret x #

to :: Rep Secret x -> Secret #

ToJSON Secret # 
FromJSON Secret # 
ToDatum Secret # 

Methods

toDatum :: Secret -> Datum #

FromDatum Secret # 
Pk Secret # 

Methods

toPk :: Secret -> Text #

type Rep Secret # 
type Rep Secret = D1 (MetaData "Secret" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" False) (C1 (MetaCons "Secret" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "secretId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 SecretId)) (S1 (MetaSel (Just Symbol "secretValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text))))

verifySecret :: SecretId -> Text -> Avers () #

Verify the value against the secret. If that fails, then this function throws an error.

This function automatically updates the secret in the database if the scrypt params have changed.

applyObjectUpdates #

Arguments

:: ObjectId

The object which you want to update

-> RevId

The RevId against which the operations were created

-> ObjId

Committer

-> [Operation]

The operations to apply

-> Bool

True if validation should be skipped

-> Avers ([Patch], Int, [Patch]) 

newId :: Int -> IO Text #

Views

data View obj a #

Constructors

View 

Fields

data SomeView obj where #

Constructors

SomeView :: (ToDatum a, FromDatum a, FromJSON obj, ToJSON a) => View obj a -> SomeView obj 

viewTable :: View obj a -> Exp Table #

Construct the table name for the given view. The table names look something like this: "view_openGames"

updateView :: ToDatum a => View obj a -> ObjId -> Maybe obj -> Avers () #

Index

data Index a #

Constructors

Index 

data SomeIndex where #

Constructors

SomeIndex :: IsDatum a => Index a -> SomeIndex 

Metrics

Change

data Change #

A change in the system, for example a new object, patch, release, blob etc.

Constructors

CPatch !Patch

A new patch was created.

Instances

Show Change # 
Generic Change # 

Associated Types

type Rep Change :: * -> * #

Methods

from :: Change -> Rep Change x #

to :: Rep Change x -> Change #

ToJSON Change # 
type Rep Change # 
type Rep Change = D1 (MetaData "Change" "Avers.Types" "avers-0.0.17.1-GXLwK1SQtx5ExJULyYRYIy" False) (C1 (MetaCons "CPatch" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Patch)))

changeChannel :: Handle -> IO (TChan Change) #

Return a TChan to which all changes in the system are streamed. Make sure to continuously drain items from the TChan, otherwise they will accumulate in memory and you will run OOM eventually.

Do not write into the channel!