| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Avers
Contents
Synopsis
- data Avers a
- evalAvers :: Handle -> Avers a -> IO (Either AversError a)
- newtype Path = Path {}
- class Pk a where
- newtype ObjId = ObjId {}
- rootObjId :: ObjId
- newtype RevId = RevId {}
- zeroRevId :: RevId
- data ObjectId
- data Operation
- data Object = Object {
- objectId :: !ObjId
- objectType :: !Text
- objectCreatedAt :: !UTCTime
- objectCreatedBy :: !ObjId
- objectDeleted :: !(Maybe Bool)
- exists :: ObjId -> Avers Bool
- createObject :: ToJSON a => ObjectType a -> ObjId -> a -> Avers ObjId
- createObject' :: ToJSON a => ObjId -> UTCTime -> ObjectType a -> ObjId -> a -> Avers ()
- lookupObject :: ObjId -> Avers Object
- deleteObject :: ObjId -> Avers ()
- pruneObject :: ObjId -> Avers ()
- objectsOfType :: ObjectType a -> Avers (Vector ObjId)
- allObjectsOfType :: ObjectType a -> Avers (Vector ObjId)
- createCheckpoint :: ObjectId -> ObjId -> Avers RevId
- vacuumObject :: ObjectId -> Avers ()
- data Patch = Patch {}
- data PatchError = UnknownPatchError !Text
- lookupPatch :: ObjectId -> RevId -> Avers Patch
- data Snapshot = Snapshot {}
- lookupLatestSnapshot :: ObjectId -> Avers Snapshot
- objectContent :: FromJSON a => ObjectId -> Avers a
- data Release = Release
- lookupRelease :: ObjId -> RevId -> Avers Release
- createRelease :: ObjId -> RevId -> Avers ()
- lookupLatestRelease :: ObjId -> Avers (Maybe RevId)
- resolvePathIn :: Path -> Value -> Maybe Value
- newtype SessionId = SessionId {
- unSessionId :: Text
- data Session = Session {}
- saveSession :: Session -> Avers ()
- lookupSession :: SessionId -> Avers Session
- dropSession :: SessionId -> Avers ()
- data ObjectType a = ObjectType {}
- data SomeObjectType where
- SomeObjectType :: (ToDatum a, FromDatum a, FromJSON a, ToJSON a) => ObjectType a -> SomeObjectType
- lookupObjectType :: Text -> Avers SomeObjectType
- data AversError
- data Config = Config {
- databaseURI :: !URI
- putBlob :: BlobId -> Text -> ByteString -> IO (Either AversError ())
- objectTypes :: ![SomeObjectType]
- emitMeasurement :: Measurement -> Double -> IO ()
- data Handle
- newHandle :: Config -> IO (Either AversError Handle)
- newState :: Config -> IO (Either AversError Handle)
- strErr :: String -> Avers a
- parseValueAs :: FromJSON a => ObjectType a -> Value -> Either AversError a
- bootstrap :: Avers ()
- newtype BlobId = BlobId {}
- data Blob = Blob {}
- createBlob :: ByteString -> Text -> Avers Blob
- lookupBlob :: BlobId -> Avers Blob
- newtype SecretId = SecretId {
- unSecretId :: Text
- data Secret = Secret {
- secretId :: !SecretId
- secretValue :: !Text
- updateSecret :: SecretId -> Text -> Avers ()
- verifySecret :: SecretId -> Text -> Avers ()
- applyObjectUpdates :: ObjectId -> RevId -> ObjId -> [Operation] -> Bool -> Avers ([Patch], Int, [Patch])
- runQuery :: FromResponse (Result a) => Exp a -> Avers (Result a)
- runQueryCollect :: (FromDatum a, Result e ~ Sequence a) => Exp e -> Avers (Vector a)
- parseValue :: (FromJSON a, MonadError AversError m) => Value -> m a
- parseDatum :: (FromDatum a, MonadError AversError m) => Datum -> m a
- newId :: Int -> IO Text
- objectsTable :: Exp Table
- blobsTable :: Exp Table
- validateObject :: Text -> Value -> Avers ()
- data View obj a = View {
- viewName :: Text
- viewParser :: Datum -> Either AversError a
- viewObjectTransformer :: obj -> Avers (Maybe a)
- viewIndices :: [SomeIndex]
- data SomeView obj where
- viewTable :: View obj a -> Exp Table
- updateView :: ToDatum a => View obj a -> ObjId -> Maybe obj -> Avers ()
- data Index a = Index {}
- data SomeIndex where
- data Measurement
- = M_avers_storage_lookupObject_duration
- | M_avers_storage_lookupSnapshot_duration
- | M_avers_storage_lookupLatestSnapshot_duration
- | M_avers_storage_newestSnapshot_duration
- | M_avers_storage_patchesAfterRevision_duration
- | M_avers_storage_lookupPatch_duration
- | M_avers_storage_applyObjectUpdates_duration
- | M_avers_storage_applyObjectUpdates_numOperations
- | M_avers_storage_applyObjectUpdates_numPreviousPatches
- | M_avers_storage_exists_duration
- measurementLabels :: Measurement -> [[Char]]
- data Change = CPatch !Patch
- changeChannel :: Handle -> IO (TChan Change)
The Avers Monad
Instances
| Monad Avers # | |
| Functor Avers # | |
| Applicative Avers # | |
| MonadIO Avers # | |
Defined in Avers.Types | |
| MonadAvers Avers # | |
Defined in Avers.Types | |
| MonadState Handle Avers # | |
| MonadError AversError Avers # | |
Defined in Avers.Types Methods throwError :: AversError -> Avers a # catchError :: Avers a -> (AversError -> Avers a) -> Avers a # | |
Types
Path
Instances
| Eq Path # | |
| Ord Path # | |
| Show Path # | |
| IsString Path # | |
Defined in Avers.Types Methods fromString :: String -> Path # | |
| Generic Path # | |
| ToJSON Path # | |
Defined in Avers.Types | |
| FromJSON Path # | |
| ToDatum Path # | |
Defined in Avers.Types | |
| FromDatum Path # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Path # | |
| type Rep Path # | |
Defined in Avers.Types | |
Pk - Types which can be converted to a database primary key.
Instances
| Pk Text # | |
Defined in Avers.Types | |
| Pk ObjectId # | |
Defined in Avers.Types | |
| Pk RevId # | |
Defined in Avers.Types | |
| Pk ObjId # | |
Defined in Avers.Types | |
| Pk Object # | |
Defined in Avers.Types | |
| Pk Patch # | |
Defined in Avers.Types | |
| Pk Snapshot # | |
Defined in Avers.Types | |
| Pk Secret # | |
Defined in Avers.Types | |
| Pk SecretId # | |
Defined in Avers.Types | |
| Pk Blob # | |
Defined in Avers.Types | |
| Pk BlobId # | |
Defined in Avers.Types | |
| Pk Session # | |
Defined in Avers.Types | |
| Pk SessionId # | |
Defined in Avers.Types | |
| Pk (Record a) # | |
Defined in Avers.Views | |
ObjId
Instances
| Eq ObjId # | |
| Ord ObjId # | |
| Show ObjId # | |
| Generic ObjId # | |
| ToJSON ObjId # | |
Defined in Avers.Types | |
| FromJSON ObjId # | |
| ToDatum ObjId # | |
Defined in Avers.Types | |
| FromDatum ObjId # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser ObjId # | |
| Pk ObjId # | |
Defined in Avers.Types | |
| type Rep ObjId # | |
Defined in Avers.Types | |
The root object id is used for object created internally or when there is no applicable creator.
RevId
Instances
| Enum RevId # | |
| Eq RevId # | |
| Ord RevId # | |
| Show RevId # | |
| Generic RevId # | |
| ToJSON RevId # | |
Defined in Avers.Types | |
| FromJSON RevId # | |
| ToDatum RevId # | |
Defined in Avers.Types | |
| FromDatum RevId # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser RevId # | |
| Pk RevId # | |
Defined in Avers.Types | |
| type Rep RevId # | |
Defined in Avers.Types | |
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
The operations that can be applied to JSON values.
Constructors
| Set | Set is applied to |
| Splice | Splice is used to manipulate |
Instances
Object
Constructors
| Object | |
Fields
| |
Instances
| Show Object # | |
| Generic Object # | |
| ToJSON Object # | |
Defined in Avers.Types | |
| FromJSON Object # | |
| ToDatum Object # | |
Defined in Avers.Types | |
| FromDatum Object # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Object # | |
| Pk Object # | |
Defined in Avers.Types | |
| type Rep Object # | |
Defined in Avers.Types type Rep Object = D1 (MetaData "Object" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "Object" PrefixI True) ((S1 (MetaSel (Just "objectId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ObjId) :*: S1 (MetaSel (Just "objectType") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)) :*: (S1 (MetaSel (Just "objectCreatedAt") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UTCTime) :*: (S1 (MetaSel (Just "objectCreatedBy") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ObjId) :*: S1 (MetaSel (Just "objectDeleted") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Maybe Bool)))))) | |
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.
objectsOfType :: ObjectType a -> Avers (Vector ObjId) #
allObjectsOfType :: ObjectType a -> Avers (Vector ObjId) #
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
Patch
Constructors
| Patch | |
Fields
| |
Instances
| Show Patch # | |
| Generic Patch # | |
| ToJSON Patch # | |
Defined in Avers.Types | |
| FromJSON Patch # | |
| ToDatum Patch # | |
Defined in Avers.Types | |
| FromDatum Patch # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Patch # | |
| Pk Patch # | |
Defined in Avers.Types | |
| type Rep Patch # | |
Defined in Avers.Types type Rep Patch = D1 (MetaData "Patch" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "Patch" PrefixI True) ((S1 (MetaSel (Just "patchObjectId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ObjectId) :*: S1 (MetaSel (Just "patchRevisionId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 RevId)) :*: (S1 (MetaSel (Just "patchAuthorId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ObjId) :*: (S1 (MetaSel (Just "patchCreatedAt") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UTCTime) :*: S1 (MetaSel (Just "patchOperation") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Operation))))) | |
data PatchError #
Constructors
| UnknownPatchError !Text |
Instances
| Show PatchError # | |
Defined in Avers.Types Methods showsPrec :: Int -> PatchError -> ShowS # show :: PatchError -> String # showList :: [PatchError] -> ShowS # | |
| Generic PatchError # | |
Defined in Avers.Types Associated Types type Rep PatchError :: Type -> Type # | |
| type Rep PatchError # | |
Defined in Avers.Types type Rep PatchError = D1 (MetaData "PatchError" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "UnknownPatchError" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text))) | |
Snapshot
Snapshot
Constructors
| Snapshot | |
Fields
| |
Instances
| Show Snapshot # | |
| Generic Snapshot # | |
| ToJSON Snapshot # | |
Defined in Avers.Types | |
| FromJSON Snapshot # | |
| ToDatum Snapshot # | |
Defined in Avers.Types | |
| FromDatum Snapshot # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Snapshot # | |
| Pk Snapshot # | |
Defined in Avers.Types | |
| type Rep Snapshot # | |
Defined in Avers.Types type Rep Snapshot = D1 (MetaData "Snapshot" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "Snapshot" PrefixI True) (S1 (MetaSel (Just "snapshotObjectId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ObjectId) :*: (S1 (MetaSel (Just "snapshotRevisionId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 RevId) :*: S1 (MetaSel (Just "snapshotContent") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Value)))) | |
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
Session
SessionId
Constructors
| SessionId | |
Fields
| |
Instances
| Generic SessionId # | |
| ToJSON SessionId # | |
Defined in Avers.Types | |
| FromJSON SessionId # | |
| ToDatum SessionId # | |
Defined in Avers.Types | |
| FromDatum SessionId # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser SessionId # | |
| Pk SessionId # | |
Defined in Avers.Types | |
| type Rep SessionId # | |
Defined in Avers.Types | |
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.
Constructors
| Session | |
Fields
| |
Instances
| Generic Session # | |
| ToJSON Session # | |
Defined in Avers.Types | |
| FromJSON Session # | |
| ToDatum Session # | |
Defined in Avers.Types | |
| FromDatum Session # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Session # | |
| Pk Session # | |
Defined in Avers.Types | |
| type Rep Session # | |
Defined in Avers.Types type Rep Session = D1 (MetaData "Session" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "Session" PrefixI True) ((S1 (MetaSel (Just "sessionId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 SessionId) :*: S1 (MetaSel (Just "sessionObjId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ObjId)) :*: (S1 (MetaSel (Just "sessionCreatedAt") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UTCTime) :*: S1 (MetaSel (Just "sessionLastAccessedAt") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UTCTime)))) | |
saveSession :: Session -> Avers () #
lookupSession :: SessionId -> Avers Session #
dropSession :: SessionId -> Avers () #
data ObjectType a #
An ObjectType describes a particular type of object that is managed by
Avers.
data SomeObjectType where #
Constructors
| SomeObjectType :: (ToDatum a, FromDatum a, FromJSON a, ToJSON a) => ObjectType a -> SomeObjectType |
lookupObjectType :: Text -> Avers SomeObjectType #
Lookup an object type which is registered in the Avers monad.
data AversError #
Constructors
| InternalError !AversError | |
| DatabaseError !Text | |
| PatchError !PatchError | |
| ParseError !Value !Text | |
| UnknownObjectType !Text | |
| ObjectNotFound !ObjId | |
| DocumentNotFound !Text | |
| AversError !Text | |
| NotAuthorized |
Instances
Configuration of the Avers monad.
Constructors
| Config | |
Fields
| |
parseValueAs :: FromJSON a => ObjectType a -> Value -> Either AversError a #
Blob
BlobId
Instances
| Show BlobId # | |
| Generic BlobId # | |
| ToJSON BlobId # | |
Defined in Avers.Types | |
| FromJSON BlobId # | |
| ToDatum BlobId # | |
Defined in Avers.Types | |
| FromDatum BlobId # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser BlobId # | |
| Pk BlobId # | |
Defined in Avers.Types | |
| type Rep BlobId # | |
Defined in Avers.Types | |
Blob
Instances
| Show Blob # | |
| Generic Blob # | |
| ToJSON Blob # | |
Defined in Avers.Types | |
| FromJSON Blob # | |
| ToDatum Blob # | |
Defined in Avers.Types | |
| FromDatum Blob # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Blob # | |
| Pk Blob # | |
Defined in Avers.Types | |
| type Rep Blob # | |
Defined in Avers.Types type Rep Blob = D1 (MetaData "Blob" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "Blob" PrefixI True) (S1 (MetaSel (Just "blobId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 BlobId) :*: (S1 (MetaSel (Just "blobSize") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Just "blobContentType") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)))) | |
createBlob :: ByteString -> Text -> Avers Blob #
lookupBlob :: BlobId -> Avers Blob #
Secret
SecretId
Constructors
| SecretId | |
Fields
| |
Instances
| Show SecretId # | |
| Generic SecretId # | |
| ToJSON SecretId # | |
Defined in Avers.Types | |
| FromJSON SecretId # | |
| ToDatum SecretId # | |
Defined in Avers.Types | |
| FromDatum SecretId # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser SecretId # | |
| Pk SecretId # | |
Defined in Avers.Types | |
| type Rep SecretId # | |
Defined in Avers.Types | |
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 | |
Fields
| |
Instances
| Generic Secret # | |
| ToJSON Secret # | |
Defined in Avers.Types | |
| FromJSON Secret # | |
| ToDatum Secret # | |
Defined in Avers.Types | |
| FromDatum Secret # | |
Defined in Avers.Types Methods parseDatum :: Datum -> Parser Secret # | |
| Pk Secret # | |
Defined in Avers.Types | |
| type Rep Secret # | |
Defined in Avers.Types type Rep Secret = D1 (MetaData "Secret" "Avers.Types" "avers-0.0.17.1-9UlRn0838nX4asVZe4Ejxo" False) (C1 (MetaCons "Secret" PrefixI True) (S1 (MetaSel (Just "secretId") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 SecretId) :*: S1 (MetaSel (Just "secretValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text))) | |
updateSecret :: SecretId -> Text -> Avers () #
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.
parseValue :: (FromJSON a, MonadError AversError m) => Value -> m a #
parseDatum :: (FromDatum a, MonadError AversError m) => Datum -> m a #
objectsTable :: Exp Table #
blobsTable :: Exp Table #
validateObject :: Text -> Value -> Avers () #
Views
Constructors
| View | |
Fields
| |
viewTable :: View obj a -> Exp Table #
Construct the table name for the given view. The table names look something like this: "view_openGames"
Index
Metrics
data Measurement #
Constructors
measurementLabels :: Measurement -> [[Char]] #