-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parses a Persist Model file and produces Audit Models -- -- Simplify database audits @package persistent-audit @version 0.1.0.3 module Database.Persist.Audit.Parser.Types data MigrationOnlyAndSafeToRemoveOption MigrationOnly :: MigrationOnlyAndSafeToRemoveOption SafeToRemove :: MigrationOnlyAndSafeToRemoveOption data EntityFieldLastItem FieldDefault :: Text -> EntityFieldLastItem FieldSqlRow :: Text -> EntityFieldLastItem FieldSqlType :: Text -> EntityFieldLastItem FieldMaxLen :: Int -> EntityFieldLastItem instance GHC.Show.Show Database.Persist.Audit.Parser.Types.EntityFieldLastItem instance GHC.Read.Read Database.Persist.Audit.Parser.Types.EntityFieldLastItem instance GHC.Show.Show Database.Persist.Audit.Parser.Types.MigrationOnlyAndSafeToRemoveOption instance GHC.Read.Read Database.Persist.Audit.Parser.Types.MigrationOnlyAndSafeToRemoveOption instance GHC.Classes.Eq Database.Persist.Audit.Parser.Types.MigrationOnlyAndSafeToRemoveOption instance GHC.Classes.Eq Database.Persist.Audit.Parser.Types.EntityFieldLastItem module Database.Persist.Audit.MongoDB.Util -- | Used for creating instances of ToAudit when the original model -- database is Mongo and the audit model database is SQL. ==== -- Example User ident Text password Text Maybe UniqueUser ident -- UserAudit ident Text password Text Maybe originalId ByteString -- auditAction AuditAction editedBy Text editedOn UTCTime instance -- ToAudit User where type AuditResult User = UserAudit toAudit v k -- auditAction editedBy editedOn = UserAudit (userIdent v) (userPassword -- v) (mongoKeyToByteString k) auditAction editedBy editedOn mongoKeyToByteString :: (ToBackendKey MongoContext record) => Key record -> ByteString -- | Used for when Mongo stored in SQL needs to be converted to a Key to -- query the original MongoDB. byteStringToMongoKey :: (ToBackendKey MongoContext record) => ByteString -> Maybe (Key record) module Database.Persist.Audit.Types -- | A collection of data types with which you can recontruct a Persist -- Model file | or create an altered version. type PersistModelFile = [PersistModelFilePiece] -- | Top level pieces of a Persist Model file. data PersistModelFilePiece PersistModelFileEntity :: Entity -> PersistModelFilePiece PersistModelFileComment :: Comment -> PersistModelFilePiece PersistModelFileWhiteSpace :: WhiteSpace -> PersistModelFilePiece -- | A single Persist Model Entity. data Entity Entity :: Text -> Bool -> Maybe Text -> [EntityChild] -> Entity [_getEntityName] :: Entity -> Text [_isEntityDeriveJson] :: Entity -> Bool -- | Person json [_getEntitySqlTable] :: Entity -> Maybe Text -- | Person sql=peoples [_getEntityChildren] :: Entity -> [EntityChild] -- | All of the child elements of a Persist Model Entity. | They are all -- indented in the Model File. data EntityChild EntityChildEntityField :: EntityField -> EntityChild EntityChildEntityUnique :: EntityUnique -> EntityChild EntityChildEntityDerive :: EntityDerive -> EntityChild EntityChildEntityPrimary :: EntityPrimary -> EntityChild EntityChildEntityForeign :: EntityForeign -> EntityChild EntityChildComment :: Comment -> EntityChild EntityChildWhiteSpace :: WhiteSpace -> EntityChild -- | A data row from an Entity. data EntityField EntityField :: Text -> EntityFieldType -> Bool -> Bool -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> EntityField [_getEntityFieldName] :: EntityField -> Text [_getEntityFieldType] :: EntityField -> EntityFieldType [_isEntityFieldMigrationOnly] :: EntityField -> Bool -- | MigrationOnly [_isEntityFieldSafeToRemove] :: EntityField -> Bool -- | SafeToRemove [_getEntityFieldDefault] :: EntityField -> Maybe Text -- | default=Nothing, default=now(), default=CURRENT_DATE [_getEntityFieldSqlRow] :: EntityField -> Maybe Text -- | sql=my_id_name [_getEntityFieldSqlType] :: EntityField -> Maybe Text -- | sqltype=varchar(255) [_getEntityFieldMaxLen] :: EntityField -> Maybe Int -- | Table rows can be strict or lazy data Strictness -- | Persist Model types are strict without any notation Strict :: Strictness -- | "!" can be used to reemphasize that a type is strict ExplicitStrict :: Strictness -- | "~" means that a type is Lazy Lazy :: Strictness -- | An entity data row's type. If _isEntityFieldTypeList is -- True than this type is a list. data EntityFieldType EntityFieldType :: Text -> Strictness -> Bool -> Bool -> EntityFieldType [_getEntityFieldTypeText] :: EntityFieldType -> Text [_getEntityFieldStrictness] :: EntityFieldType -> Strictness [_isEntityFieldTypeList] :: EntityFieldType -> Bool [_isEntityFieldTypeMaybe] :: EntityFieldType -> Bool -- | A unique idenfitier for an Entity. data EntityUnique EntityUnique :: Text -> [Text] -> EntityUnique [_getEntityUniqueName] :: EntityUnique -> Text [_getEntityUniqueEntityFieldName] :: EntityUnique -> [Text] -- | 'deriving Eq', 'deriving Show', etc. data EntityDerive EntityDerive :: [Text] -> EntityDerive [_getEntityDeriveTypes] :: EntityDerive -> [Text] -- | 'Primary name' data EntityPrimary EntityPrimary :: [Text] -> EntityPrimary [_getEntityPrimeType] :: EntityPrimary -> [Text] -- | 'Foreign Tree fkparent parent' data EntityForeign EntityForeign :: Text -> [Text] -> EntityForeign [_getEntityForeignTable] :: EntityForeign -> Text [_getEntityForeignTypes] :: EntityForeign -> [Text] -- | Any white spaces that the user might want to maintain when generating -- Audit Models. data WhiteSpace WhiteSpace :: Text -> WhiteSpace [_getWhiteSpace] :: WhiteSpace -> Text -- | Haskell style comments that start with "-- " data Comment Comment :: Text -> Comment [_getComment] :: Comment -> Text -- | Annotations for each Audit Model to keep track of why it was inserted. data AuditAction Create :: AuditAction Delete :: AuditAction Update :: AuditAction instance Database.Persist.Class.PersistField.PersistField Database.Persist.Audit.Types.AuditAction instance Database.Persist.Sql.Class.PersistFieldSql Database.Persist.Audit.Types.AuditAction instance Data.Hashable.Class.Hashable Database.Persist.Audit.Types.AuditAction instance Data.Aeson.Types.Class.FromJSON Database.Persist.Audit.Types.AuditAction instance Data.Aeson.Types.Class.ToJSON Database.Persist.Audit.Types.AuditAction instance GHC.Generics.Generic Database.Persist.Audit.Types.AuditAction instance GHC.Classes.Ord Database.Persist.Audit.Types.AuditAction instance GHC.Classes.Eq Database.Persist.Audit.Types.AuditAction instance GHC.Read.Read Database.Persist.Audit.Types.AuditAction instance GHC.Show.Show Database.Persist.Audit.Types.AuditAction instance GHC.Read.Read Database.Persist.Audit.Types.PersistModelFilePiece instance GHC.Show.Show Database.Persist.Audit.Types.PersistModelFilePiece instance GHC.Classes.Eq Database.Persist.Audit.Types.PersistModelFilePiece instance GHC.Read.Read Database.Persist.Audit.Types.Entity instance GHC.Show.Show Database.Persist.Audit.Types.Entity instance GHC.Classes.Eq Database.Persist.Audit.Types.Entity instance GHC.Read.Read Database.Persist.Audit.Types.EntityChild instance GHC.Show.Show Database.Persist.Audit.Types.EntityChild instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityChild instance GHC.Read.Read Database.Persist.Audit.Types.Comment instance GHC.Show.Show Database.Persist.Audit.Types.Comment instance GHC.Classes.Eq Database.Persist.Audit.Types.Comment instance GHC.Read.Read Database.Persist.Audit.Types.WhiteSpace instance GHC.Show.Show Database.Persist.Audit.Types.WhiteSpace instance GHC.Classes.Eq Database.Persist.Audit.Types.WhiteSpace instance GHC.Read.Read Database.Persist.Audit.Types.EntityForeign instance GHC.Show.Show Database.Persist.Audit.Types.EntityForeign instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityForeign instance GHC.Read.Read Database.Persist.Audit.Types.EntityPrimary instance GHC.Show.Show Database.Persist.Audit.Types.EntityPrimary instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityPrimary instance GHC.Read.Read Database.Persist.Audit.Types.EntityDerive instance GHC.Show.Show Database.Persist.Audit.Types.EntityDerive instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityDerive instance GHC.Read.Read Database.Persist.Audit.Types.EntityUnique instance GHC.Show.Show Database.Persist.Audit.Types.EntityUnique instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityUnique instance GHC.Read.Read Database.Persist.Audit.Types.EntityField instance GHC.Show.Show Database.Persist.Audit.Types.EntityField instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityField instance GHC.Read.Read Database.Persist.Audit.Types.EntityFieldType instance GHC.Show.Show Database.Persist.Audit.Types.EntityFieldType instance GHC.Classes.Eq Database.Persist.Audit.Types.EntityFieldType instance GHC.Read.Read Database.Persist.Audit.Types.Strictness instance GHC.Show.Show Database.Persist.Audit.Types.Strictness instance GHC.Classes.Eq Database.Persist.Audit.Types.Strictness module Database.Persist.Audit.Generator -- | Five options for generating Audit Models and ToAudit Instances. data AuditGeneratorSettings AuditGeneratorSettings :: Int -> Text -> Bool -> Bool -> Bool -> ForeignKeyType -> AuditGeneratorSettings -- | The number of spaces to add for all items that appear under an -- EntityName. [childSpacing] :: AuditGeneratorSettings -> Int -- | The tag that will be added to the original model name in the generated -- audit models. If auditTag is History then User -- will become UserHistory. [auditTag] :: AuditGeneratorSettings -> Text -- | If True, the generated Audit Models will maintain the same -- derived Type Classes as the original file. [keepEntityDerive] :: AuditGeneratorSettings -> Bool -- | If True, the generated Audit Models will maintain the same -- comments as the original file. [keepComments] :: AuditGeneratorSettings -> Bool -- | If True, the generated Audit Models will maintain the same -- spacing as the original file. [keepSpacing] :: AuditGeneratorSettings -> Bool -- | Foreign Keys can be the original type, ByteString or Int64. [foreignKeyType] :: AuditGeneratorSettings -> ForeignKeyType -- | All foreign keys are kept in the audit models but derefenced so the -- original models | can be deleted without affecting the audit models. -- This is a work around in case the | original models and the audit -- models are stored in different databases. | Persist cannot handle keys -- across SQL and Mongo. data ForeignKeyType -- | Default setting. Link the ids as the original type with a -- "noreference" tag. OriginalKey :: ForeignKeyType -- | Store Mongo Key as a ByteString in SQL. MongoKeyInSQL :: ForeignKeyType -- | Store SQL Key as an Int64 in Mongo. SQLKeyInMongo :: ForeignKeyType -- | Settings that the author assumed would be most common. defaultSettings :: AuditGeneratorSettings -- | Convert a list of TopLevel to a list of Audit Models in -- Text. generateAuditModels :: AuditGeneratorSettings -> PersistModelFile -> Text -- | Select the correct type from Audit Model to original Model. Used for -- cross database. | fst is the type and snd is the -- original type in comment for if using cross database. printForeignKey :: ForeignKeyType -> Text -> (Text, Text) -- | Convert a TopLevel to an Audit Model, white space or comment -- in Text. printTopLevel :: AuditGeneratorSettings -> PersistModelFilePiece -> Text -- | Convert an EntityChild to a piece of an Audit Model in -- Text. | It does not generate anything for EntityUnique, -- EntityPrimary or EntityForeign | because Audits do not need to be -- unique, they will have an automatically produced Key | and should not -- have any foreign keys connecting back to the original model. printEntityChild :: AuditGeneratorSettings -> EntityChild -> Text -- | Convert a list of TopLevel to a to a list of ToAudit -- in Text. generateToAuditInstances :: AuditGeneratorSettings -> PersistModelFile -> Text -- | Convert TopLevel to an instance of ToAudit in -- Text. printToAuditInstance :: AuditGeneratorSettings -> PersistModelFilePiece -> Text -- | Convert EntityChild to a Model accessor. printModelAccessor :: AuditGeneratorSettings -> Text -> EntityChild -> Text -- | Select the correct function for handling foreign keys. printIfForeignKeyAlternate :: ForeignKeyType -> Text -> Text printIfForeignKeyAlternate2 :: ForeignKeyType -> Text -> EntityFieldType -> Text -- | If fst True then prefix the function with fmap printEntityFieldTypeFunctionConnector :: EntityFieldType -> (Bool, Text) -- | Return true if the last two characters are Id. stringEndsInId :: String -> Bool -- | Convert the first letter of a String to the corresponding -- uppercase letter. firstLetterToUpperCase :: String -> String -- | Convert the first letter of a String to the corresponsing -- lowercase letter. firstLetterToLowerCase :: String -> String instance GHC.Show.Show Database.Persist.Audit.Generator.AuditGeneratorSettings instance GHC.Read.Read Database.Persist.Audit.Generator.AuditGeneratorSettings instance GHC.Classes.Eq Database.Persist.Audit.Generator.AuditGeneratorSettings instance GHC.Show.Show Database.Persist.Audit.Generator.ForeignKeyType instance GHC.Read.Read Database.Persist.Audit.Generator.ForeignKeyType instance GHC.Classes.Eq Database.Persist.Audit.Generator.ForeignKeyType module Database.Persist.Audit.Parser parseQuasiQuoterFile :: Text -> Either String PersistModelFile parseModelsFile :: Text -> Either String PersistModelFile -- | Parse Persist Models that are in quasi-quoters. The source could be a -- haskell file. parsePersistQuasiQuoters :: Parser PersistModelFile -- | Parse a Persist Model file. parseEntities :: Parser PersistModelFile -- | Parse a single Persist Entity parseEntity :: Parser Entity parseEntitySqlTable :: Parser Text -- | Wrap a Parser in Maybe because it might fail. Useful for making -- choices. maybeOption :: Parser a -> Parser (Maybe a) -- | Parse a lowercase Char. lowerCase :: Parser Char -- | Parse an uppercase Char. upperCase :: Parser Char -- | Parse an underline. underline :: Parser Char -- | Parse strict marker "!" for haskellTypeName. exclamationMark :: Parser Char -- | Parse lazy marker "~" for haskellTypeName. tilde :: Parser Char -- | Parse any space Char excluding "n". spaceNoNewLine :: Parser Char -- | Parse a Haskell function name. It starts with underscore or lowercase -- letter then is followed by a combination of underscores, single -- quotes, letters and digits. E.g., "get", "_get", "get_1", etc. haskellFunctionName :: Parser Text -- | Parse a Haskell type name. It starts with an uppercase letter then is -- followed by a combination of underscores, single quotes, letters and -- digits. E.g., Person, Address, PhoneNumber, etc. haskellTypeName :: Parser Text haskellTypeNameWithoutPrefix :: Parser Text -- | Parse a comment that starts with "--". singleLineComment :: Parser Comment collectWhiteSpace :: Parser WhiteSpace parseEntityName :: Parser Text parseEntityField :: Parser EntityField deleteItems :: (Eq a) => [a] -> [a] -> [a] parseMigrationOnly :: Parser MigrationOnlyAndSafeToRemoveOption parseSafeToRemove :: Parser MigrationOnlyAndSafeToRemoveOption getMigrationOnlyAndSafeToRemoveOption :: MigrationOnlyAndSafeToRemoveOption -> Parser MigrationOnlyAndSafeToRemoveOption parseMigrationOnlyAndSafeToRemove :: [MigrationOnlyAndSafeToRemoveOption] -> Parser [MigrationOnlyAndSafeToRemoveOption] getFieldDefault :: [EntityFieldLastItem] -> Maybe Text getFieldSqlRow :: [EntityFieldLastItem] -> Maybe Text getFieldSqlType :: [EntityFieldLastItem] -> Maybe Text getFieldMaxLen :: [EntityFieldLastItem] -> Maybe Int getEntityFieldLastItemParser :: EntityFieldLastItem -> Parser EntityFieldLastItem parseFieldDefault :: Parser EntityFieldLastItem parseFieldSqlRow :: Parser EntityFieldLastItem parseFieldSqlType :: Parser EntityFieldLastItem parseFieldMaxLen :: Parser EntityFieldLastItem parseEntityFieldLastItem :: [EntityFieldLastItem] -> Parser [EntityFieldLastItem] parseEntityFieldName :: Parser Text parseStrictness :: Parser Strictness parseEntityFieldType :: Parser EntityFieldType parseMaybe :: Parser () parseEntityUnique :: Parser EntityUnique parseEntityUniqueName :: Parser Text parseEntityUniqueEntityFieldName :: Parser [Text] parseEntityDerive :: Parser EntityDerive parseEntityPrimary :: Parser EntityPrimary parseEntityForeign :: Parser EntityForeign parseForeignKeyType :: Parser () module Database.Persist.Audit.Class -- | Persistent Model types that have a corresponding Audit type as -- produced by generateAuditModels need to implement -- ToAudit in order to use the queries from Queries. Given -- the following two Persistent models: -- --
-- Person -- name String -- age Int Maybe -- -- PersonAudit -- name String -- age Int Maybe -- originalId PersonId noreference -- auditAction AuditAction -- editedBy Text -- editedOn UTCTime ---- -- The ToAudit instance should look like this: -- --
-- instance ToAudit Person where -- type AuditResult Person = PersonAudit -- toAudit v k auditAction editedBy editedOn = PersonAudit (personName v) -- (personAge v) -- k auditAction editedBy editedOn ---- -- generateAuditModels can help automate these instances. class ToAudit a where type AuditResult a :: * where { type family AuditResult a :: *; } toAudit :: ToAudit a => a -> Key a -> AuditAction -> Text -> UTCTime -> AuditResult a module Database.Persist.Audit.Queries insertAndAudit :: (MonadIO m, backend ~ BaseBackend backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => val -> Text -> ReaderT backend m (Key val) insertUniqueAndAudit :: (MonadIO m, backend ~ BaseBackend backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, PersistUnique backend, ToAudit val) => val -> Text -> ReaderT backend m (Maybe (Key val)) deleteAndAudit :: (MonadIO m, backend ~ BaseBackend backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => Key val -> Text -> ReaderT backend m () updateAndAudit :: (MonadIO m, backend ~ BaseBackend backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => Key val -> [Update val] -> Text -> ReaderT backend m () deleteWhereAndAudit :: (MonadIO m, backend ~ BaseBackend backend, PersistQueryWrite backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => [Filter val] -> Text -> ReaderT backend m () deleteByAndAudit :: (MonadIO m, backend ~ BaseBackend backend, PersistQueryWrite backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, PersistUnique backend, ToAudit val) => Unique val -> Text -> ReaderT backend m () updateWhereAndAudit :: (MonadIO m, backend ~ BaseBackend backend, PersistQueryWrite backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => [Filter val] -> [Update val] -> Text -> ReaderT backend m () repsertAndAudit :: (MonadIO m, backend ~ BaseBackend backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => Key val -> val -> Text -> ReaderT backend m (Key val) replaceAndAudit :: (MonadIO m, backend ~ BaseBackend backend, backend ~ PersistEntityBackend val, backend ~ PersistEntityBackend (AuditResult val), PersistEntity val, PersistEntity (AuditResult val), PersistStore backend, ToAudit val) => Key val -> val -> Text -> ReaderT backend m ()