Skip to content

Commit

Permalink
Update Data.Event (//issues/5)
Browse files Browse the repository at this point in the history
  • Loading branch information
markfarrell committed May 28, 2020
1 parent 8d7e01d commit ea0ac96
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
37 changes: 30 additions & 7 deletions src/Data/Event.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Data.Event
( Event(..)
, EventType(..)
, SourceID
, SessionID
, DestinationID
Expand All @@ -9,6 +8,7 @@ module Data.Event
, FeatureID
, InstanceID
, module Data.Event.Class
, module Data.Event.EventType
, eventTypes
, foreignEvent
) where
Expand All @@ -25,7 +25,7 @@ import FFI.UUID (UUID)

import Data.Event.Class (class EventCategory, class EventID, eventCategories, eventIDs)

data EventType = Success | Failure
import Data.Event.EventType (EventType(..))

type SourceID = UUID
type SessionID = UUID
Expand All @@ -52,20 +52,43 @@ data Event a b = Event (EventCategory a => EventID b =>
, endTime :: Date
})

instance showEventType :: Show EventType where
show Success = "SUCCESS"
show Failure = "FAILURE"
{-- todo: see https://github.com/markfarrell/3iter/issues/5 --}

type Feature a b = (EventCategory a => EventID b =>
{ eventCategory :: a
, eventType :: EventType
, eventID :: b
})

type Identifier =
{ sourceID :: SourceID
, sessionID :: SessionID
, destinationID :: DestinationID
, logID :: LogID
, schemaID :: SchemaID
}

type Checksum =
{ featureID :: FeatureID
, instanceID :: InstanceID
}

type Period =
{ startTime :: Date
, duration :: Int
, endTime :: Date
}

instance showEvent :: (EventCategory a, EventID b) => Show (Event a b) where
show = JSON.stringify <<< foreignEvent

derive instance eqEventType :: Eq EventType

derive instance eqEvent :: (EventCategory a, EventID b) => Eq (Event a b)

eventTypes :: Array EventType
eventTypes = [ Success, Failure ]

{-- todo: see https://github.com/markfarrell/3tier/issues/27 --}

foreignEvent :: forall a b. EventCategory a => EventID b => Event a b -> Foreign
foreignEvent (Event x) = unsafeCoerce $
{ eventCategory : show x.eventCategory
Expand Down
15 changes: 15 additions & 0 deletions src/Data/Event/EventType.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Data.Event.EventType
( EventType (..)
) where

import Prelude

{-- todo: see https://github.com/markfarrell/3tier/issues/5 --}

data EventType = Success | Failure

instance showEventType :: Show EventType where
show Success = "SUCCESS"
show Failure = "FAILURE"

derive instance eqEventType :: Eq EventType
6 changes: 3 additions & 3 deletions src/Data/Forward.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Data.Linux as Linux
import Data.Windows as Windows

data Event =
Alert Alert.Event
| Audit Audit.Event
Alert Alert.Event
| Audit Audit.Event
| Traffic Traffic.Event
| Linux Linux.Event
| Linux Linux.Event
| Windows Windows.Event

instance showEventForward :: Show Event where
Expand Down

0 comments on commit ea0ac96

Please sign in to comment.