{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.DDL.EventTrigger
( CreateEventTriggerQuery,
runCreateEventTriggerQuery,
DeleteEventTriggerQuery,
runDeleteEventTriggerQuery,
dropEventTriggerInMetadata,
RedeliverEventQuery,
runRedeliverEvent,
InvokeEventTriggerQuery,
runInvokeEventTrigger,
getHeaderInfosFromConf,
getWebhookInfoFromConf,
buildEventTriggerInfo,
getTriggerNames,
getTriggersMap,
getTableNameFromTrigger,
cetqSource,
cetqName,
cetqTable,
cetqInsert,
cetqUpdate,
cetqDelete,
cetqEnableManual,
cetqRetryConf,
cetqWebhook,
cetqWebhookFromEnv,
cetqHeaders,
cetqReplace,
cetqRequestTransform,
cetqResponseTrasnform,
)
where
import Control.Lens (makeLenses, (.~))
import Data.Aeson
import Data.ByteString.Lazy qualified as LBS
import Data.Environment qualified as Env
import Data.HashMap.Strict qualified as HM
import Data.HashMap.Strict.InsOrd qualified as OMap
import Data.HashSet qualified as Set
import Data.Text qualified as T
import Data.Text.Extended
import Data.URL.Template (printURLTemplate)
import Hasura.Base.Error
import Hasura.EncJSON
import Hasura.Prelude
import Hasura.RQL.DDL.Headers
import Hasura.RQL.DDL.Webhook.Transform (MetadataResponseTransform, RequestTransform)
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.EventTrigger
import Hasura.RQL.Types.Eventing
import Hasura.RQL.Types.Eventing.Backend
import Hasura.RQL.Types.Metadata
import Hasura.RQL.Types.Metadata.Backend
import Hasura.RQL.Types.Metadata.Object
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.SchemaCache.Build
import Hasura.RQL.Types.SchemaCacheTypes
import Hasura.RQL.Types.Source
import Hasura.RQL.Types.Table
import Hasura.SQL.AnyBackend qualified as AB
import Hasura.SQL.Backend
import Hasura.Session
import Hasura.Tracing qualified as Tracing
import Text.Regex.TDFA qualified as TDFA
data CreateEventTriggerQuery (b :: BackendType) = CreateEventTriggerQuery
{ CreateEventTriggerQuery b -> SourceName
_cetqSource :: SourceName,
CreateEventTriggerQuery b -> TriggerName
_cetqName :: TriggerName,
CreateEventTriggerQuery b -> TableName b
_cetqTable :: TableName b,
CreateEventTriggerQuery b -> Maybe (SubscribeOpSpec b)
_cetqInsert :: Maybe (SubscribeOpSpec b),
CreateEventTriggerQuery b -> Maybe (SubscribeOpSpec b)
_cetqUpdate :: Maybe (SubscribeOpSpec b),
CreateEventTriggerQuery b -> Maybe (SubscribeOpSpec b)
_cetqDelete :: Maybe (SubscribeOpSpec b),
CreateEventTriggerQuery b -> Maybe Bool
_cetqEnableManual :: Maybe Bool,
CreateEventTriggerQuery b -> Maybe RetryConf
_cetqRetryConf :: Maybe RetryConf,
CreateEventTriggerQuery b -> Maybe InputWebhook
_cetqWebhook :: Maybe InputWebhook,
CreateEventTriggerQuery b -> Maybe Text
_cetqWebhookFromEnv :: Maybe Text,
:: Maybe [HeaderConf],
CreateEventTriggerQuery b -> Bool
_cetqReplace :: Bool,
CreateEventTriggerQuery b -> Maybe RequestTransform
_cetqRequestTransform :: Maybe RequestTransform,
CreateEventTriggerQuery b -> Maybe MetadataResponseTransform
_cetqResponseTrasnform :: Maybe MetadataResponseTransform
}
$()
instance Backend b => FromJSON (CreateEventTriggerQuery b) where
parseJSON :: Value -> Parser (CreateEventTriggerQuery b)
parseJSON = String
-> (Object -> Parser (CreateEventTriggerQuery b))
-> Value
-> Parser (CreateEventTriggerQuery b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CreateEventTriggerQuery" \Object
o -> do
SourceName
sourceName <- Object
o Object -> Key -> Parser (Maybe SourceName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"source" Parser (Maybe SourceName) -> SourceName -> Parser SourceName
forall a. Parser (Maybe a) -> a -> Parser a
.!= SourceName
defaultSource
TriggerName
name <- Object
o Object -> Key -> Parser TriggerName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
TableName b
table <- Object
o Object -> Key -> Parser (TableName b)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"table"
Maybe (SubscribeOpSpec b)
insert <- Object
o Object -> Key -> Parser (Maybe (SubscribeOpSpec b))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"insert"
Maybe (SubscribeOpSpec b)
update <- Object
o Object -> Key -> Parser (Maybe (SubscribeOpSpec b))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"update"
Maybe (SubscribeOpSpec b)
delete <- Object
o Object -> Key -> Parser (Maybe (SubscribeOpSpec b))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"delete"
Bool
enableManual <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"enable_manual" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
Maybe RetryConf
retryConf <- Object
o Object -> Key -> Parser (Maybe RetryConf)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retry_conf"
Maybe InputWebhook
webhook <- Object
o Object -> Key -> Parser (Maybe InputWebhook)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"webhook"
Maybe Text
webhookFromEnv <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"webhook_from_env"
Maybe [HeaderConf]
headers <- Object
o Object -> Key -> Parser (Maybe [HeaderConf])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"headers"
Bool
replace <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"replace" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
Maybe RequestTransform
requestTransform <- Object
o Object -> Key -> Parser (Maybe RequestTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"request_transform"
Maybe MetadataResponseTransform
responseTransform <- Object
o Object -> Key -> Parser (Maybe MetadataResponseTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"response_transform"
let regex :: ByteString
regex = ByteString
"^[A-Za-z]+[A-Za-z0-9_\\-]*$" :: LBS.ByteString
compiledRegex :: Regex
compiledRegex = ByteString -> Regex
forall regex compOpt execOpt source.
RegexMaker regex compOpt execOpt source =>
source -> regex
TDFA.makeRegex ByteString
regex :: TDFA.Regex
isMatch :: Bool
isMatch = Regex -> String -> Bool
forall regex source target.
RegexContext regex source target =>
regex -> source -> target
TDFA.match Regex
compiledRegex (String -> Bool) -> (Text -> String) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> Bool) -> Text -> Bool
forall a b. (a -> b) -> a -> b
$ TriggerName -> Text
triggerNameToTxt TriggerName
name
Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
isMatch (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$
String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"only alphanumeric and underscore and hyphens allowed for name"
Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Int
T.length (TriggerName -> Text
triggerNameToTxt TriggerName
name) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
maxTriggerNameLength) (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$
String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"event trigger name can be at most 42 characters"
Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((Maybe (SubscribeOpSpec b) -> Bool)
-> [Maybe (SubscribeOpSpec b)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Maybe (SubscribeOpSpec b) -> Bool
forall a. Maybe a -> Bool
isJust [Maybe (SubscribeOpSpec b)
insert, Maybe (SubscribeOpSpec b)
update, Maybe (SubscribeOpSpec b)
delete] Bool -> Bool -> Bool
|| Bool
enableManual) (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$
String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"atleast one amongst insert/update/delete/enable_manual spec must be provided"
case (Maybe InputWebhook
webhook, Maybe Text
webhookFromEnv) of
(Just InputWebhook
_, Maybe Text
Nothing) -> () -> Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
(Maybe InputWebhook
Nothing, Just Text
_) -> () -> Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
(Just InputWebhook
_, Just Text
_) -> String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"only one of webhook or webhook_from_env should be given"
(Maybe InputWebhook, Maybe Text)
_ -> String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"must provide webhook or webhook_from_env"
(Maybe (SubscribeOpSpec b) -> Parser ())
-> [Maybe (SubscribeOpSpec b)] -> Parser ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Maybe (SubscribeOpSpec b) -> Parser ()
forall (f :: * -> *) (b :: BackendType).
MonadFail f =>
Maybe (SubscribeOpSpec b) -> f ()
checkEmptyCols [Maybe (SubscribeOpSpec b)
insert, Maybe (SubscribeOpSpec b)
update, Maybe (SubscribeOpSpec b)
delete]
CreateEventTriggerQuery b -> Parser (CreateEventTriggerQuery b)
forall (m :: * -> *) a. Monad m => a -> m a
return (CreateEventTriggerQuery b -> Parser (CreateEventTriggerQuery b))
-> CreateEventTriggerQuery b -> Parser (CreateEventTriggerQuery b)
forall a b. (a -> b) -> a -> b
$ SourceName
-> TriggerName
-> TableName b
-> Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe Bool
-> Maybe RetryConf
-> Maybe InputWebhook
-> Maybe Text
-> Maybe [HeaderConf]
-> Bool
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> CreateEventTriggerQuery b
forall (b :: BackendType).
SourceName
-> TriggerName
-> TableName b
-> Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe Bool
-> Maybe RetryConf
-> Maybe InputWebhook
-> Maybe Text
-> Maybe [HeaderConf]
-> Bool
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> CreateEventTriggerQuery b
CreateEventTriggerQuery SourceName
sourceName TriggerName
name TableName b
table Maybe (SubscribeOpSpec b)
insert Maybe (SubscribeOpSpec b)
update Maybe (SubscribeOpSpec b)
delete (Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
enableManual) Maybe RetryConf
retryConf Maybe InputWebhook
webhook Maybe Text
webhookFromEnv Maybe [HeaderConf]
headers Bool
replace Maybe RequestTransform
requestTransform Maybe MetadataResponseTransform
responseTransform
where
checkEmptyCols :: Maybe (SubscribeOpSpec b) -> f ()
checkEmptyCols Maybe (SubscribeOpSpec b)
spec =
case Maybe (SubscribeOpSpec b)
spec of
Just (SubscribeOpSpec (SubCArray [Column b]
cols) Maybe (SubscribeColumns b)
_) -> Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Column b] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Column b]
cols) (String -> f ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"found empty column specification")
Just (SubscribeOpSpec SubscribeColumns b
_ (Just (SubCArray [Column b]
cols))) -> Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Column b] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Column b]
cols) (String -> f ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"found empty payload specification")
Maybe (SubscribeOpSpec b)
_ -> () -> f ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
data DeleteEventTriggerQuery (b :: BackendType) = DeleteEventTriggerQuery
{ DeleteEventTriggerQuery b -> SourceName
_detqSource :: SourceName,
DeleteEventTriggerQuery b -> TriggerName
_detqName :: TriggerName
}
instance FromJSON (DeleteEventTriggerQuery b) where
parseJSON :: Value -> Parser (DeleteEventTriggerQuery b)
parseJSON = String
-> (Object -> Parser (DeleteEventTriggerQuery b))
-> Value
-> Parser (DeleteEventTriggerQuery b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DeleteEventTriggerQuery" ((Object -> Parser (DeleteEventTriggerQuery b))
-> Value -> Parser (DeleteEventTriggerQuery b))
-> (Object -> Parser (DeleteEventTriggerQuery b))
-> Value
-> Parser (DeleteEventTriggerQuery b)
forall a b. (a -> b) -> a -> b
$ \Object
o ->
SourceName -> TriggerName -> DeleteEventTriggerQuery b
forall (b :: BackendType).
SourceName -> TriggerName -> DeleteEventTriggerQuery b
DeleteEventTriggerQuery
(SourceName -> TriggerName -> DeleteEventTriggerQuery b)
-> Parser SourceName
-> Parser (TriggerName -> DeleteEventTriggerQuery b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe SourceName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"source" Parser (Maybe SourceName) -> SourceName -> Parser SourceName
forall a. Parser (Maybe a) -> a -> Parser a
.!= SourceName
defaultSource
Parser (TriggerName -> DeleteEventTriggerQuery b)
-> Parser TriggerName -> Parser (DeleteEventTriggerQuery b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser TriggerName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
data RedeliverEventQuery (b :: BackendType) = RedeliverEventQuery
{ RedeliverEventQuery b -> EventId
_rdeqEventId :: EventId,
RedeliverEventQuery b -> SourceName
_rdeqSource :: SourceName
}
instance FromJSON (RedeliverEventQuery b) where
parseJSON :: Value -> Parser (RedeliverEventQuery b)
parseJSON = String
-> (Object -> Parser (RedeliverEventQuery b))
-> Value
-> Parser (RedeliverEventQuery b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"RedeliverEventQuery" ((Object -> Parser (RedeliverEventQuery b))
-> Value -> Parser (RedeliverEventQuery b))
-> (Object -> Parser (RedeliverEventQuery b))
-> Value
-> Parser (RedeliverEventQuery b)
forall a b. (a -> b) -> a -> b
$ \Object
o ->
EventId -> SourceName -> RedeliverEventQuery b
forall (b :: BackendType).
EventId -> SourceName -> RedeliverEventQuery b
RedeliverEventQuery
(EventId -> SourceName -> RedeliverEventQuery b)
-> Parser EventId -> Parser (SourceName -> RedeliverEventQuery b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser EventId
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"event_id"
Parser (SourceName -> RedeliverEventQuery b)
-> Parser SourceName -> Parser (RedeliverEventQuery b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe SourceName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"source" Parser (Maybe SourceName) -> SourceName -> Parser SourceName
forall a. Parser (Maybe a) -> a -> Parser a
.!= SourceName
defaultSource
data InvokeEventTriggerQuery (b :: BackendType) = InvokeEventTriggerQuery
{ InvokeEventTriggerQuery b -> TriggerName
_ietqName :: TriggerName,
InvokeEventTriggerQuery b -> SourceName
_ietqSource :: SourceName,
InvokeEventTriggerQuery b -> Value
_ietqPayload :: Value
}
instance Backend b => FromJSON (InvokeEventTriggerQuery b) where
parseJSON :: Value -> Parser (InvokeEventTriggerQuery b)
parseJSON = String
-> (Object -> Parser (InvokeEventTriggerQuery b))
-> Value
-> Parser (InvokeEventTriggerQuery b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"InvokeEventTriggerQuery" ((Object -> Parser (InvokeEventTriggerQuery b))
-> Value -> Parser (InvokeEventTriggerQuery b))
-> (Object -> Parser (InvokeEventTriggerQuery b))
-> Value
-> Parser (InvokeEventTriggerQuery b)
forall a b. (a -> b) -> a -> b
$ \Object
o ->
TriggerName -> SourceName -> Value -> InvokeEventTriggerQuery b
forall (b :: BackendType).
TriggerName -> SourceName -> Value -> InvokeEventTriggerQuery b
InvokeEventTriggerQuery
(TriggerName -> SourceName -> Value -> InvokeEventTriggerQuery b)
-> Parser TriggerName
-> Parser (SourceName -> Value -> InvokeEventTriggerQuery b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser TriggerName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser (SourceName -> Value -> InvokeEventTriggerQuery b)
-> Parser SourceName -> Parser (Value -> InvokeEventTriggerQuery b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe SourceName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"source" Parser (Maybe SourceName) -> SourceName -> Parser SourceName
forall a. Parser (Maybe a) -> a -> Parser a
.!= SourceName
defaultSource
Parser (Value -> InvokeEventTriggerQuery b)
-> Parser Value -> Parser (InvokeEventTriggerQuery b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
resolveEventTriggerQuery ::
forall b m.
(Backend b, UserInfoM m, QErrM m, CacheRM m) =>
CreateEventTriggerQuery b ->
m (Bool, EventTriggerConf b)
resolveEventTriggerQuery :: CreateEventTriggerQuery b -> m (Bool, EventTriggerConf b)
resolveEventTriggerQuery (CreateEventTriggerQuery SourceName
source TriggerName
name TableName b
qt Maybe (SubscribeOpSpec b)
insert Maybe (SubscribeOpSpec b)
update Maybe (SubscribeOpSpec b)
delete Maybe Bool
enableManual Maybe RetryConf
retryConf Maybe InputWebhook
webhook Maybe Text
webhookFromEnv Maybe [HeaderConf]
mheaders Bool
replace Maybe RequestTransform
reqTransform Maybe MetadataResponseTransform
respTransform) = do
TableCoreInfo b
ti <- SourceName -> TableName b -> m (TableCoreInfo b)
forall (b :: BackendType) (m :: * -> *).
(QErrM m, CacheRM m, Backend b) =>
SourceName -> TableName b -> m (TableCoreInfo b)
askTableCoreInfo SourceName
source TableName b
qt
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
replace (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
TableCoreInfo b
ti' <- TableInfo b -> TableCoreInfo b
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo (TableInfo b -> TableCoreInfo b)
-> m (TableInfo b) -> m (TableCoreInfo b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SourceName -> TriggerName -> m (TableInfo b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, QErrM m, CacheRM m) =>
SourceName -> TriggerName -> m (TableInfo b)
askTabInfoFromTrigger @b SourceName
source TriggerName
name
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TableCoreInfo b -> TableName b
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> TableName b
_tciName TableCoreInfo b
ti' TableName b -> TableName b -> Bool
forall a. Eq a => a -> a -> Bool
/= TableCoreInfo b -> TableName b
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> TableName b
_tciName TableCoreInfo b
ti) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ Code -> Text -> m ()
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"cannot replace table or schema for trigger"
TableCoreInfo b -> Maybe (SubscribeOpSpec b) -> m ()
assertCols TableCoreInfo b
ti Maybe (SubscribeOpSpec b)
insert
TableCoreInfo b -> Maybe (SubscribeOpSpec b) -> m ()
assertCols TableCoreInfo b
ti Maybe (SubscribeOpSpec b)
update
TableCoreInfo b -> Maybe (SubscribeOpSpec b) -> m ()
assertCols TableCoreInfo b
ti Maybe (SubscribeOpSpec b)
delete
let rconf :: RetryConf
rconf = RetryConf -> Maybe RetryConf -> RetryConf
forall a. a -> Maybe a -> a
fromMaybe RetryConf
defaultRetryConf Maybe RetryConf
retryConf
(Bool, EventTriggerConf b) -> m (Bool, EventTriggerConf b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
replace, TriggerName
-> TriggerOpsDef b
-> Maybe InputWebhook
-> Maybe Text
-> RetryConf
-> Maybe [HeaderConf]
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> EventTriggerConf b
forall (b :: BackendType).
TriggerName
-> TriggerOpsDef b
-> Maybe InputWebhook
-> Maybe Text
-> RetryConf
-> Maybe [HeaderConf]
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> EventTriggerConf b
EventTriggerConf TriggerName
name (Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe Bool
-> TriggerOpsDef b
forall (b :: BackendType).
Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe (SubscribeOpSpec b)
-> Maybe Bool
-> TriggerOpsDef b
TriggerOpsDef Maybe (SubscribeOpSpec b)
insert Maybe (SubscribeOpSpec b)
update Maybe (SubscribeOpSpec b)
delete Maybe Bool
enableManual) Maybe InputWebhook
webhook Maybe Text
webhookFromEnv RetryConf
rconf Maybe [HeaderConf]
mheaders Maybe RequestTransform
reqTransform Maybe MetadataResponseTransform
respTransform)
where
assertCols :: TableCoreInfo b -> Maybe (SubscribeOpSpec b) -> m ()
assertCols :: TableCoreInfo b -> Maybe (SubscribeOpSpec b) -> m ()
assertCols TableCoreInfo b
ti Maybe (SubscribeOpSpec b)
opSpec = Maybe (SubscribeOpSpec b) -> (SubscribeOpSpec b -> m ()) -> m ()
forall (m :: * -> *) a.
Applicative m =>
Maybe a -> (a -> m ()) -> m ()
onJust Maybe (SubscribeOpSpec b)
opSpec \SubscribeOpSpec b
sos -> case SubscribeOpSpec b -> SubscribeColumns b
forall (b :: BackendType). SubscribeOpSpec b -> SubscribeColumns b
sosColumns SubscribeOpSpec b
sos of
SubscribeColumns b
SubCStar -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
SubCArray [Column b]
columns -> [Column b] -> (Column b -> m ()) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Column b]
columns (FieldInfoMap (FieldInfo b) -> Text -> Column b -> m ()
forall (backend :: BackendType) (m :: * -> *).
(MonadError QErr m, Backend backend) =>
FieldInfoMap (FieldInfo backend) -> Text -> Column backend -> m ()
assertColumnExists @b (TableCoreInfo b -> FieldInfoMap (FieldInfo b)
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> FieldInfoMap field
_tciFieldInfoMap TableCoreInfo b
ti) Text
"")
droppedTriggerOps :: TriggerOpsDef b -> TriggerOpsDef b -> HashSet Ops
droppedTriggerOps :: TriggerOpsDef b -> TriggerOpsDef b -> HashSet Ops
droppedTriggerOps TriggerOpsDef b
oldEventTriggerOps TriggerOpsDef b
newEventTriggerOps =
[Ops] -> HashSet Ops
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList ([Ops] -> HashSet Ops) -> [Ops] -> HashSet Ops
forall a b. (a -> b) -> a -> b
$
[Maybe Ops] -> [Ops]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe Ops] -> [Ops]) -> [Maybe Ops] -> [Ops]
forall a b. (a -> b) -> a -> b
$
[ (Maybe Ops -> Maybe Ops -> Bool -> Maybe Ops
forall a. a -> a -> Bool -> a
bool Maybe Ops
forall a. Maybe a
Nothing (Ops -> Maybe Ops
forall a. a -> Maybe a
Just Ops
INSERT) (Maybe (SubscribeOpSpec b) -> Maybe (SubscribeOpSpec b) -> Bool
forall a a. Maybe a -> Maybe a -> Bool
isDroppedOp (TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
forall (b :: BackendType).
TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
tdInsert TriggerOpsDef b
oldEventTriggerOps) (TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
forall (b :: BackendType).
TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
tdInsert TriggerOpsDef b
newEventTriggerOps))),
(Maybe Ops -> Maybe Ops -> Bool -> Maybe Ops
forall a. a -> a -> Bool -> a
bool Maybe Ops
forall a. Maybe a
Nothing (Ops -> Maybe Ops
forall a. a -> Maybe a
Just Ops
UPDATE) (Maybe (SubscribeOpSpec b) -> Maybe (SubscribeOpSpec b) -> Bool
forall a a. Maybe a -> Maybe a -> Bool
isDroppedOp (TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
forall (b :: BackendType).
TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
tdUpdate TriggerOpsDef b
oldEventTriggerOps) (TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
forall (b :: BackendType).
TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
tdUpdate TriggerOpsDef b
newEventTriggerOps))),
(Maybe Ops -> Maybe Ops -> Bool -> Maybe Ops
forall a. a -> a -> Bool -> a
bool Maybe Ops
forall a. Maybe a
Nothing (Ops -> Maybe Ops
forall a. a -> Maybe a
Just Ops
DELETE) (Maybe (SubscribeOpSpec b) -> Maybe (SubscribeOpSpec b) -> Bool
forall a a. Maybe a -> Maybe a -> Bool
isDroppedOp (TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
forall (b :: BackendType).
TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
tdDelete TriggerOpsDef b
oldEventTriggerOps) (TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
forall (b :: BackendType).
TriggerOpsDef b -> Maybe (SubscribeOpSpec b)
tdDelete TriggerOpsDef b
newEventTriggerOps)))
]
where
isDroppedOp :: Maybe a -> Maybe a -> Bool
isDroppedOp Maybe a
old Maybe a
new = Maybe a -> Bool
forall a. Maybe a -> Bool
isJust Maybe a
old Bool -> Bool -> Bool
&& Maybe a -> Bool
forall a. Maybe a -> Bool
isNothing Maybe a
new
createEventTriggerQueryMetadata ::
forall b m.
(BackendMetadata b, QErrM m, UserInfoM m, CacheRWM m, MetadataM m, BackendEventTrigger b, MonadIO m) =>
CreateEventTriggerQuery b ->
m ()
createEventTriggerQueryMetadata :: CreateEventTriggerQuery b -> m ()
createEventTriggerQueryMetadata CreateEventTriggerQuery b
q = do
(Bool
replace, EventTriggerConf b
triggerConf) <- CreateEventTriggerQuery b -> m (Bool, EventTriggerConf b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, UserInfoM m, QErrM m, CacheRM m) =>
CreateEventTriggerQuery b -> m (Bool, EventTriggerConf b)
resolveEventTriggerQuery CreateEventTriggerQuery b
q
let table :: TableName b
table = CreateEventTriggerQuery b -> TableName b
forall (b :: BackendType). CreateEventTriggerQuery b -> TableName b
_cetqTable CreateEventTriggerQuery b
q
source :: SourceName
source = CreateEventTriggerQuery b -> SourceName
forall (b :: BackendType). CreateEventTriggerQuery b -> SourceName
_cetqSource CreateEventTriggerQuery b
q
triggerName :: TriggerName
triggerName = EventTriggerConf b -> TriggerName
forall (b :: BackendType). EventTriggerConf b -> TriggerName
etcName EventTriggerConf b
triggerConf
metadataObj :: MetadataObjId
metadataObj =
SourceName -> AnyBackend SourceMetadataObjId -> MetadataObjId
MOSourceObjId SourceName
source (AnyBackend SourceMetadataObjId -> MetadataObjId)
-> AnyBackend SourceMetadataObjId -> MetadataObjId
forall a b. (a -> b) -> a -> b
$
SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId)
-> SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall a b. (a -> b) -> a -> b
$
TableName b -> TableMetadataObjId -> SourceMetadataObjId b
forall (b :: BackendType).
TableName b -> TableMetadataObjId -> SourceMetadataObjId b
SMOTableObj @b TableName b
table (TableMetadataObjId -> SourceMetadataObjId b)
-> TableMetadataObjId -> SourceMetadataObjId b
forall a b. (a -> b) -> a -> b
$
TriggerName -> TableMetadataObjId
MTOTrigger TriggerName
triggerName
SourceInfo b
sourceInfo <- SourceName -> m (SourceInfo b)
forall (b :: BackendType) (m :: * -> *).
(CacheRM m, MetadataM m, MonadError QErr m, Backend b) =>
SourceName -> m (SourceInfo b)
askSourceInfo @b SourceName
source
let sourceConfig :: SourceConfig b
sourceConfig = (SourceInfo b -> SourceConfig b
forall (b :: BackendType). SourceInfo b -> SourceConfig b
_siConfiguration SourceInfo b
sourceInfo)
if Bool
replace
then do
TriggerOpsDef b
existingEventTriggerOps <- EventTriggerInfo b -> TriggerOpsDef b
forall (b :: BackendType). EventTriggerInfo b -> TriggerOpsDef b
etiOpsDef (EventTriggerInfo b -> TriggerOpsDef b)
-> m (EventTriggerInfo b) -> m (TriggerOpsDef b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SourceName -> TriggerName -> m (EventTriggerInfo b)
forall (b :: BackendType) (m :: * -> *).
(QErrM m, CacheRM m, Backend b) =>
SourceName -> TriggerName -> m (EventTriggerInfo b)
askEventTriggerInfo @b SourceName
source TriggerName
triggerName
let droppedOps :: HashSet Ops
droppedOps = TriggerOpsDef b -> TriggerOpsDef b -> HashSet Ops
forall (b :: BackendType).
TriggerOpsDef b -> TriggerOpsDef b -> HashSet Ops
droppedTriggerOps TriggerOpsDef b
existingEventTriggerOps (EventTriggerConf b -> TriggerOpsDef b
forall (b :: BackendType). EventTriggerConf b -> TriggerOpsDef b
etcDefinition EventTriggerConf b
triggerConf)
SourceConfig b -> TriggerName -> TableName b -> HashSet Ops -> m ()
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadIO m, MonadError QErr m) =>
SourceConfig b -> TriggerName -> TableName b -> HashSet Ops -> m ()
dropDanglingSQLTrigger @b (SourceInfo b -> SourceConfig b
forall (b :: BackendType). SourceInfo b -> SourceConfig b
_siConfiguration SourceInfo b
sourceInfo) TriggerName
triggerName TableName b
table HashSet Ops
droppedOps
else do
Bool
doesTriggerExists <- SourceConfig b -> TriggerName -> HashSet Ops -> m Bool
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadIO m, MonadError QErr m) =>
SourceConfig b -> TriggerName -> HashSet Ops -> m Bool
checkIfTriggerExists @b SourceConfig b
sourceConfig TriggerName
triggerName ([Ops] -> HashSet Ops
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Ops
INSERT, Ops
UPDATE, Ops
DELETE])
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
doesTriggerExists (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
Code -> Text -> m ()
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
AlreadyExists (Text
"Event trigger with name " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TriggerName -> Text
triggerNameToTxt TriggerName
triggerName Text -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" already exists")
MetadataObjId -> MetadataModifier -> m ()
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
MetadataObjId -> MetadataModifier -> m ()
buildSchemaCacheFor MetadataObjId
metadataObj (MetadataModifier -> m ()) -> MetadataModifier -> m ()
forall a b. (a -> b) -> a -> b
$
(Metadata -> Metadata) -> MetadataModifier
MetadataModifier ((Metadata -> Metadata) -> MetadataModifier)
-> (Metadata -> Metadata) -> MetadataModifier
forall a b. (a -> b) -> a -> b
$
SourceName -> TableName b -> ASetter' Metadata (TableMetadata b)
forall (b :: BackendType).
Backend b =>
SourceName -> TableName b -> ASetter' Metadata (TableMetadata b)
tableMetadataSetter @b SourceName
source TableName b
table ASetter' Metadata (TableMetadata b)
-> ((EventTriggers b -> Identity (EventTriggers b))
-> TableMetadata b -> Identity (TableMetadata b))
-> (EventTriggers b -> Identity (EventTriggers b))
-> Metadata
-> Identity Metadata
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EventTriggers b -> Identity (EventTriggers b))
-> TableMetadata b -> Identity (TableMetadata b)
forall (b :: BackendType).
Lens' (TableMetadata b) (EventTriggers b)
tmEventTriggers
((EventTriggers b -> Identity (EventTriggers b))
-> Metadata -> Identity Metadata)
-> (EventTriggers b -> EventTriggers b) -> Metadata -> Metadata
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ if Bool
replace
then Index (EventTriggers b)
-> Traversal' (EventTriggers b) (IxValue (EventTriggers b))
forall m. Ixed m => Index m -> Traversal' m (IxValue m)
ix Index (EventTriggers b)
TriggerName
triggerName ((EventTriggerConf b -> Identity (EventTriggerConf b))
-> EventTriggers b -> Identity (EventTriggers b))
-> EventTriggerConf b -> EventTriggers b -> EventTriggers b
forall s t a b. ASetter s t a b -> b -> s -> t
.~ EventTriggerConf b
triggerConf
else TriggerName
-> EventTriggerConf b -> EventTriggers b -> EventTriggers b
forall k v.
(Eq k, Hashable k) =>
k -> v -> InsOrdHashMap k v -> InsOrdHashMap k v
OMap.insert TriggerName
triggerName EventTriggerConf b
triggerConf
runCreateEventTriggerQuery ::
forall b m.
(BackendMetadata b, BackendEventTrigger b, QErrM m, UserInfoM m, CacheRWM m, MetadataM m, MonadIO m) =>
CreateEventTriggerQuery b ->
m EncJSON
runCreateEventTriggerQuery :: CreateEventTriggerQuery b -> m EncJSON
runCreateEventTriggerQuery CreateEventTriggerQuery b
q = do
CreateEventTriggerQuery b -> m ()
forall (b :: BackendType) (m :: * -> *).
(BackendMetadata b, QErrM m, UserInfoM m, CacheRWM m, MetadataM m,
BackendEventTrigger b, MonadIO m) =>
CreateEventTriggerQuery b -> m ()
createEventTriggerQueryMetadata @b CreateEventTriggerQuery b
q
EncJSON -> m EncJSON
forall (f :: * -> *) a. Applicative f => a -> f a
pure EncJSON
successMsg
runDeleteEventTriggerQuery ::
forall b m.
(BackendEventTrigger b, MonadError QErr m, CacheRWM m, MonadIO m, MetadataM m) =>
DeleteEventTriggerQuery b ->
m EncJSON
runDeleteEventTriggerQuery :: DeleteEventTriggerQuery b -> m EncJSON
runDeleteEventTriggerQuery (DeleteEventTriggerQuery SourceName
sourceName TriggerName
triggerName) = do
SourceConfig b
sourceConfig <- SourceName -> m (SourceConfig b)
forall (b :: BackendType) (m :: * -> *).
(CacheRM m, MonadError QErr m, Backend b, MetadataM m) =>
SourceName -> m (SourceConfig b)
askSourceConfig @b SourceName
sourceName
TableName b
tableName <- (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> TableName b
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> TableName b
_tciName (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> TableName b)
-> (TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b))
-> TableInfo b
-> TableName b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo) (TableInfo b -> TableName b) -> m (TableInfo b) -> m (TableName b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SourceName -> TriggerName -> m (TableInfo b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, QErrM m, CacheRM m) =>
SourceName -> TriggerName -> m (TableInfo b)
askTabInfoFromTrigger @b SourceName
sourceName TriggerName
triggerName
m () -> m ()
forall (m :: * -> *) a. (QErrM m, CacheRM m) => m a -> m a
withNewInconsistentObjsCheck (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
MetadataModifier -> m ()
forall (m :: * -> *).
(MetadataM m, CacheRWM m) =>
MetadataModifier -> m ()
buildSchemaCache (MetadataModifier -> m ()) -> MetadataModifier -> m ()
forall a b. (a -> b) -> a -> b
$
(Metadata -> Metadata) -> MetadataModifier
MetadataModifier ((Metadata -> Metadata) -> MetadataModifier)
-> (Metadata -> Metadata) -> MetadataModifier
forall a b. (a -> b) -> a -> b
$
SourceName -> TableName b -> ASetter' Metadata (TableMetadata b)
forall (b :: BackendType).
Backend b =>
SourceName -> TableName b -> ASetter' Metadata (TableMetadata b)
tableMetadataSetter @b SourceName
sourceName TableName b
tableName ASetter' Metadata (TableMetadata b)
-> (TableMetadata b -> TableMetadata b) -> Metadata -> Metadata
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ TriggerName -> TableMetadata b -> TableMetadata b
forall (b :: BackendType).
TriggerName -> TableMetadata b -> TableMetadata b
dropEventTriggerInMetadata TriggerName
triggerName
SourceConfig b -> TriggerName -> TableName b -> m ()
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadIO m, MonadError QErr m) =>
SourceConfig b -> TriggerName -> TableName b -> m ()
dropTriggerAndArchiveEvents @b SourceConfig b
sourceConfig TriggerName
triggerName TableName b
tableName
EncJSON -> m EncJSON
forall (f :: * -> *) a. Applicative f => a -> f a
pure EncJSON
successMsg
runRedeliverEvent ::
forall b m.
(BackendEventTrigger b, MonadIO m, CacheRM m, QErrM m, MetadataM m) =>
RedeliverEventQuery b ->
m EncJSON
runRedeliverEvent :: RedeliverEventQuery b -> m EncJSON
runRedeliverEvent (RedeliverEventQuery EventId
eventId SourceName
source) = do
SourceConfig b
sourceConfig <- SourceName -> m (SourceConfig b)
forall (b :: BackendType) (m :: * -> *).
(CacheRM m, MonadError QErr m, Backend b, MetadataM m) =>
SourceName -> m (SourceConfig b)
askSourceConfig @b SourceName
source
SourceConfig b -> EventId -> m ()
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadIO m, MonadError QErr m) =>
SourceConfig b -> EventId -> m ()
redeliverEvent @b SourceConfig b
sourceConfig EventId
eventId
EncJSON -> m EncJSON
forall (f :: * -> *) a. Applicative f => a -> f a
pure EncJSON
successMsg
runInvokeEventTrigger ::
forall b m.
( MonadIO m,
QErrM m,
CacheRM m,
MetadataM m,
Tracing.MonadTrace m,
UserInfoM m,
BackendEventTrigger b
) =>
InvokeEventTriggerQuery b ->
m EncJSON
runInvokeEventTrigger :: InvokeEventTriggerQuery b -> m EncJSON
runInvokeEventTrigger (InvokeEventTriggerQuery TriggerName
name SourceName
source Value
payload) = do
EventTriggerInfo b
trigInfo <- SourceName -> TriggerName -> m (EventTriggerInfo b)
forall (b :: BackendType) (m :: * -> *).
(QErrM m, CacheRM m, Backend b) =>
SourceName -> TriggerName -> m (EventTriggerInfo b)
askEventTriggerInfo @b SourceName
source TriggerName
name
TriggerOpsDef b -> m ()
forall (m :: * -> *) (b :: BackendType).
MonadError QErr m =>
TriggerOpsDef b -> m ()
assertManual (TriggerOpsDef b -> m ()) -> TriggerOpsDef b -> m ()
forall a b. (a -> b) -> a -> b
$ EventTriggerInfo b -> TriggerOpsDef b
forall (b :: BackendType). EventTriggerInfo b -> TriggerOpsDef b
etiOpsDef EventTriggerInfo b
trigInfo
TableInfo b
ti <- SourceName -> TriggerName -> m (TableInfo b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, QErrM m, CacheRM m) =>
SourceName -> TriggerName -> m (TableInfo b)
askTabInfoFromTrigger SourceName
source TriggerName
name
SourceConfig b
sourceConfig <- SourceName -> m (SourceConfig b)
forall (b :: BackendType) (m :: * -> *).
(CacheRM m, MonadError QErr m, Backend b, MetadataM m) =>
SourceName -> m (SourceConfig b)
askSourceConfig @b SourceName
source
TraceContext
traceCtx <- m TraceContext
forall (m :: * -> *). MonadTrace m => m TraceContext
Tracing.currentContext
UserInfo
userInfo <- m UserInfo
forall (m :: * -> *). UserInfoM m => m UserInfo
askUserInfo
EventId
eid <- SourceConfig b
-> TableName b
-> TriggerName
-> Value
-> UserInfo
-> TraceContext
-> m EventId
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadIO m, MonadError QErr m) =>
SourceConfig b
-> TableName b
-> TriggerName
-> Value
-> UserInfo
-> TraceContext
-> m EventId
insertManualEvent @b SourceConfig b
sourceConfig (TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName @b TableInfo b
ti) TriggerName
name (Value -> Value
forall v. ToJSON v => v -> Value
makePayload Value
payload) UserInfo
userInfo TraceContext
traceCtx
EncJSON -> m EncJSON
forall (m :: * -> *) a. Monad m => a -> m a
return (EncJSON -> m EncJSON) -> EncJSON -> m EncJSON
forall a b. (a -> b) -> a -> b
$ Value -> EncJSON
forall a. ToJSON a => a -> EncJSON
encJFromJValue (Value -> EncJSON) -> Value -> EncJSON
forall a b. (a -> b) -> a -> b
$ [Pair] -> Value
object [Key
"event_id" Key -> EventId -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= EventId
eid]
where
makePayload :: v -> Value
makePayload v
o = [Pair] -> Value
object [Key
"old" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Value
Null, Key
"new" Key -> v -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= v
o]
assertManual :: TriggerOpsDef b -> m ()
assertManual (TriggerOpsDef Maybe (SubscribeOpSpec b)
_ Maybe (SubscribeOpSpec b)
_ Maybe (SubscribeOpSpec b)
_ Maybe Bool
man) = case Maybe Bool
man of
Just Bool
True -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Maybe Bool
_ -> Code -> Text -> m ()
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"manual mode is not enabled for event trigger"
askTabInfoFromTrigger ::
(Backend b, QErrM m, CacheRM m) =>
SourceName ->
TriggerName ->
m (TableInfo b)
askTabInfoFromTrigger :: SourceName -> TriggerName -> m (TableInfo b)
askTabInfoFromTrigger SourceName
sourceName TriggerName
triggerName = do
SchemaCache
schemaCache <- m SchemaCache
forall (m :: * -> *). CacheRM m => m SchemaCache
askSchemaCache
SchemaCache -> SourceName -> TriggerName -> m (TableInfo b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, QErrM m) =>
SchemaCache -> SourceName -> TriggerName -> m (TableInfo b)
getTabInfoFromSchemaCache SchemaCache
schemaCache SourceName
sourceName TriggerName
triggerName
getTabInfoFromSchemaCache ::
(Backend b, QErrM m) =>
SchemaCache ->
SourceName ->
TriggerName ->
m (TableInfo b)
getTabInfoFromSchemaCache :: SchemaCache -> SourceName -> TriggerName -> m (TableInfo b)
getTabInfoFromSchemaCache SchemaCache
schemaCache SourceName
sourceName TriggerName
triggerName = do
let tabInfos :: [TableInfo b]
tabInfos = HashMap (TableName b) (TableInfo b) -> [TableInfo b]
forall k v. HashMap k v -> [v]
HM.elems (HashMap (TableName b) (TableInfo b) -> [TableInfo b])
-> HashMap (TableName b) (TableInfo b) -> [TableInfo b]
forall a b. (a -> b) -> a -> b
$ HashMap (TableName b) (TableInfo b)
-> Maybe (HashMap (TableName b) (TableInfo b))
-> HashMap (TableName b) (TableInfo b)
forall a. a -> Maybe a -> a
fromMaybe HashMap (TableName b) (TableInfo b)
forall a. Monoid a => a
mempty (Maybe (HashMap (TableName b) (TableInfo b))
-> HashMap (TableName b) (TableInfo b))
-> Maybe (HashMap (TableName b) (TableInfo b))
-> HashMap (TableName b) (TableInfo b)
forall a b. (a -> b) -> a -> b
$ SourceName
-> SourceCache -> Maybe (HashMap (TableName b) (TableInfo b))
forall (b :: BackendType).
Backend b =>
SourceName -> SourceCache -> Maybe (TableCache b)
unsafeTableCache SourceName
sourceName (SourceCache -> Maybe (HashMap (TableName b) (TableInfo b)))
-> SourceCache -> Maybe (HashMap (TableName b) (TableInfo b))
forall a b. (a -> b) -> a -> b
$ SchemaCache -> SourceCache
scSources SchemaCache
schemaCache
(TableInfo b -> Bool) -> [TableInfo b] -> Maybe (TableInfo b)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (Maybe (EventTriggerInfo b) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (EventTriggerInfo b) -> Bool)
-> (TableInfo b -> Maybe (EventTriggerInfo b))
-> TableInfo b
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TriggerName
-> HashMap TriggerName (EventTriggerInfo b)
-> Maybe (EventTriggerInfo b)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup TriggerName
triggerName (HashMap TriggerName (EventTriggerInfo b)
-> Maybe (EventTriggerInfo b))
-> (TableInfo b -> HashMap TriggerName (EventTriggerInfo b))
-> TableInfo b
-> Maybe (EventTriggerInfo b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableInfo b -> HashMap TriggerName (EventTriggerInfo b)
forall (b :: BackendType). TableInfo b -> EventTriggerInfoMap b
_tiEventTriggerInfoMap) [TableInfo b]
tabInfos
Maybe (TableInfo b) -> m (TableInfo b) -> m (TableInfo b)
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
`onNothing` Code -> Text -> m (TableInfo b)
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotExists Text
errMsg
where
errMsg :: Text
errMsg = Text
"event trigger " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TriggerName
triggerName TriggerName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" does not exist"
askEventTriggerInfo ::
forall b m.
(QErrM m, CacheRM m, Backend b) =>
SourceName ->
TriggerName ->
m (EventTriggerInfo b)
askEventTriggerInfo :: SourceName -> TriggerName -> m (EventTriggerInfo b)
askEventTriggerInfo SourceName
sourceName TriggerName
triggerName = do
TableInfo b
triggerInfo <- SourceName -> TriggerName -> m (TableInfo b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, QErrM m, CacheRM m) =>
SourceName -> TriggerName -> m (TableInfo b)
askTabInfoFromTrigger @b SourceName
sourceName TriggerName
triggerName
let eventTriggerInfoMap :: EventTriggerInfoMap b
eventTriggerInfoMap = TableInfo b -> EventTriggerInfoMap b
forall (b :: BackendType). TableInfo b -> EventTriggerInfoMap b
_tiEventTriggerInfoMap TableInfo b
triggerInfo
TriggerName -> EventTriggerInfoMap b -> Maybe (EventTriggerInfo b)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup TriggerName
triggerName EventTriggerInfoMap b
eventTriggerInfoMap Maybe (EventTriggerInfo b)
-> m (EventTriggerInfo b) -> m (EventTriggerInfo b)
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
`onNothing` Code -> Text -> m (EventTriggerInfo b)
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotExists Text
errMsg
where
errMsg :: Text
errMsg = Text
"event trigger " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TriggerName
triggerName TriggerName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" does not exist"
maxTriggerNameLength :: Int
maxTriggerNameLength :: Int
maxTriggerNameLength = Int
42
getHeaderInfosFromConf ::
QErrM m =>
Env.Environment ->
[HeaderConf] ->
m [EventHeaderInfo]
Environment
env = (HeaderConf -> m EventHeaderInfo)
-> [HeaderConf] -> m [EventHeaderInfo]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM HeaderConf -> m EventHeaderInfo
forall (m :: * -> *). QErrM m => HeaderConf -> m EventHeaderInfo
getHeader
where
getHeader :: QErrM m => HeaderConf -> m EventHeaderInfo
getHeader :: HeaderConf -> m EventHeaderInfo
getHeader HeaderConf
hconf = case HeaderConf
hconf of
(HeaderConf Text
_ (HVValue Text
val)) -> EventHeaderInfo -> m EventHeaderInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (EventHeaderInfo -> m EventHeaderInfo)
-> EventHeaderInfo -> m EventHeaderInfo
forall a b. (a -> b) -> a -> b
$ HeaderConf -> Text -> EventHeaderInfo
EventHeaderInfo HeaderConf
hconf Text
val
(HeaderConf Text
_ (HVEnv Text
val)) -> do
Text
envVal <- Environment -> Text -> m Text
forall (m :: * -> *). QErrM m => Environment -> Text -> m Text
getEnv Environment
env Text
val
EventHeaderInfo -> m EventHeaderInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (EventHeaderInfo -> m EventHeaderInfo)
-> EventHeaderInfo -> m EventHeaderInfo
forall a b. (a -> b) -> a -> b
$ HeaderConf -> Text -> EventHeaderInfo
EventHeaderInfo HeaderConf
hconf Text
envVal
getWebhookInfoFromConf ::
QErrM m =>
Env.Environment ->
WebhookConf ->
m WebhookConfInfo
getWebhookInfoFromConf :: Environment -> WebhookConf -> m WebhookConfInfo
getWebhookInfoFromConf Environment
env WebhookConf
webhookConf = case WebhookConf
webhookConf of
WCValue InputWebhook
w -> do
ResolvedWebhook
resolvedWebhook <- Environment -> InputWebhook -> m ResolvedWebhook
forall (m :: * -> *).
QErrM m =>
Environment -> InputWebhook -> m ResolvedWebhook
resolveWebhook Environment
env InputWebhook
w
let urlTemplate :: Text
urlTemplate = URLTemplate -> Text
printURLTemplate (URLTemplate -> Text) -> URLTemplate -> Text
forall a b. (a -> b) -> a -> b
$ InputWebhook -> URLTemplate
unInputWebhook InputWebhook
w
WebhookConfInfo -> m WebhookConfInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (WebhookConfInfo -> m WebhookConfInfo)
-> WebhookConfInfo -> m WebhookConfInfo
forall a b. (a -> b) -> a -> b
$ WebhookConf -> EnvRecord ResolvedWebhook -> WebhookConfInfo
WebhookConfInfo WebhookConf
webhookConf (Text -> ResolvedWebhook -> EnvRecord ResolvedWebhook
forall a. Text -> a -> EnvRecord a
EnvRecord Text
urlTemplate ResolvedWebhook
resolvedWebhook)
WCEnv Text
webhookEnvVar -> do
Text
envVal <- Environment -> Text -> m Text
forall (m :: * -> *). QErrM m => Environment -> Text -> m Text
getEnv Environment
env Text
webhookEnvVar
WebhookConfInfo -> m WebhookConfInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (WebhookConfInfo -> m WebhookConfInfo)
-> WebhookConfInfo -> m WebhookConfInfo
forall a b. (a -> b) -> a -> b
$ WebhookConf -> EnvRecord ResolvedWebhook -> WebhookConfInfo
WebhookConfInfo WebhookConf
webhookConf (Text -> ResolvedWebhook -> EnvRecord ResolvedWebhook
forall a. Text -> a -> EnvRecord a
EnvRecord Text
webhookEnvVar (Text -> ResolvedWebhook
ResolvedWebhook Text
envVal))
buildEventTriggerInfo ::
forall b m.
(Backend b, QErrM m) =>
Env.Environment ->
SourceName ->
TableName b ->
EventTriggerConf b ->
m (EventTriggerInfo b, [SchemaDependency])
buildEventTriggerInfo :: Environment
-> SourceName
-> TableName b
-> EventTriggerConf b
-> m (EventTriggerInfo b, [SchemaDependency])
buildEventTriggerInfo Environment
env SourceName
source TableName b
tableName (EventTriggerConf TriggerName
name TriggerOpsDef b
def Maybe InputWebhook
webhook Maybe Text
webhookFromEnv RetryConf
rconf Maybe [HeaderConf]
mheaders Maybe RequestTransform
reqTransform Maybe MetadataResponseTransform
respTransform) = do
WebhookConf
webhookConf <- case (Maybe InputWebhook
webhook, Maybe Text
webhookFromEnv) of
(Just InputWebhook
w, Maybe Text
Nothing) -> WebhookConf -> m WebhookConf
forall (m :: * -> *) a. Monad m => a -> m a
return (WebhookConf -> m WebhookConf) -> WebhookConf -> m WebhookConf
forall a b. (a -> b) -> a -> b
$ InputWebhook -> WebhookConf
WCValue InputWebhook
w
(Maybe InputWebhook
Nothing, Just Text
wEnv) -> WebhookConf -> m WebhookConf
forall (m :: * -> *) a. Monad m => a -> m a
return (WebhookConf -> m WebhookConf) -> WebhookConf -> m WebhookConf
forall a b. (a -> b) -> a -> b
$ Text -> WebhookConf
WCEnv Text
wEnv
(Maybe InputWebhook, Maybe Text)
_ -> Text -> m WebhookConf
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 Text
"expected webhook or webhook_from_env"
let headerConfs :: [HeaderConf]
headerConfs = [HeaderConf] -> Maybe [HeaderConf] -> [HeaderConf]
forall a. a -> Maybe a -> a
fromMaybe [] Maybe [HeaderConf]
mheaders
WebhookConfInfo
webhookInfo <- Environment -> WebhookConf -> m WebhookConfInfo
forall (m :: * -> *).
QErrM m =>
Environment -> WebhookConf -> m WebhookConfInfo
getWebhookInfoFromConf Environment
env WebhookConf
webhookConf
[EventHeaderInfo]
headerInfos <- Environment -> [HeaderConf] -> m [EventHeaderInfo]
forall (m :: * -> *).
QErrM m =>
Environment -> [HeaderConf] -> m [EventHeaderInfo]
getHeaderInfosFromConf Environment
env [HeaderConf]
headerConfs
let eTrigInfo :: EventTriggerInfo b
eTrigInfo = TriggerName
-> TriggerOpsDef b
-> RetryConf
-> WebhookConfInfo
-> [EventHeaderInfo]
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> EventTriggerInfo b
forall (b :: BackendType).
TriggerName
-> TriggerOpsDef b
-> RetryConf
-> WebhookConfInfo
-> [EventHeaderInfo]
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> EventTriggerInfo b
EventTriggerInfo TriggerName
name TriggerOpsDef b
def RetryConf
rconf WebhookConfInfo
webhookInfo [EventHeaderInfo]
headerInfos Maybe RequestTransform
reqTransform Maybe MetadataResponseTransform
respTransform
tabDep :: SchemaDependency
tabDep =
SchemaObjId -> DependencyReason -> SchemaDependency
SchemaDependency
( SourceName -> AnyBackend SourceObjId -> SchemaObjId
SOSourceObj SourceName
source (AnyBackend SourceObjId -> SchemaObjId)
-> AnyBackend SourceObjId -> SchemaObjId
forall a b. (a -> b) -> a -> b
$
SourceObjId b -> AnyBackend SourceObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceObjId b -> AnyBackend SourceObjId)
-> SourceObjId b -> AnyBackend SourceObjId
forall a b. (a -> b) -> a -> b
$
TableName b -> SourceObjId b
forall (b :: BackendType). TableName b -> SourceObjId b
SOITable @b TableName b
tableName
)
DependencyReason
DRParent
(EventTriggerInfo b, [SchemaDependency])
-> m (EventTriggerInfo b, [SchemaDependency])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EventTriggerInfo b
eTrigInfo, SchemaDependency
tabDep SchemaDependency -> [SchemaDependency] -> [SchemaDependency]
forall a. a -> [a] -> [a]
: SourceName -> TableName b -> TriggerOpsDef b -> [SchemaDependency]
forall (b :: BackendType).
Backend b =>
SourceName -> TableName b -> TriggerOpsDef b -> [SchemaDependency]
getTrigDefDeps @b SourceName
source TableName b
tableName TriggerOpsDef b
def)
getTrigDefDeps ::
forall b.
Backend b =>
SourceName ->
TableName b ->
TriggerOpsDef b ->
[SchemaDependency]
getTrigDefDeps :: SourceName -> TableName b -> TriggerOpsDef b -> [SchemaDependency]
getTrigDefDeps SourceName
source TableName b
tableName (TriggerOpsDef Maybe (SubscribeOpSpec b)
mIns Maybe (SubscribeOpSpec b)
mUpd Maybe (SubscribeOpSpec b)
mDel Maybe Bool
_) =
[[SchemaDependency]] -> [SchemaDependency]
forall a. Monoid a => [a] -> a
mconcat ([[SchemaDependency]] -> [SchemaDependency])
-> [[SchemaDependency]] -> [SchemaDependency]
forall a b. (a -> b) -> a -> b
$
[Maybe [SchemaDependency]] -> [[SchemaDependency]]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
[ SubscribeOpSpec b -> [SchemaDependency]
subsOpSpecDeps (SubscribeOpSpec b -> [SchemaDependency])
-> Maybe (SubscribeOpSpec b) -> Maybe [SchemaDependency]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (SubscribeOpSpec b)
mIns,
SubscribeOpSpec b -> [SchemaDependency]
subsOpSpecDeps (SubscribeOpSpec b -> [SchemaDependency])
-> Maybe (SubscribeOpSpec b) -> Maybe [SchemaDependency]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (SubscribeOpSpec b)
mUpd,
SubscribeOpSpec b -> [SchemaDependency]
subsOpSpecDeps (SubscribeOpSpec b -> [SchemaDependency])
-> Maybe (SubscribeOpSpec b) -> Maybe [SchemaDependency]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (SubscribeOpSpec b)
mDel
]
where
subsOpSpecDeps :: SubscribeOpSpec b -> [SchemaDependency]
subsOpSpecDeps :: SubscribeOpSpec b -> [SchemaDependency]
subsOpSpecDeps SubscribeOpSpec b
os =
let cols :: [Column b]
cols = SubscribeColumns b -> [Column b]
forall (b :: BackendType). SubscribeColumns b -> [Column b]
getColsFromSub (SubscribeColumns b -> [Column b])
-> SubscribeColumns b -> [Column b]
forall a b. (a -> b) -> a -> b
$ SubscribeOpSpec b -> SubscribeColumns b
forall (b :: BackendType). SubscribeOpSpec b -> SubscribeColumns b
sosColumns SubscribeOpSpec b
os
mkColDependency :: DependencyReason -> Column b -> SchemaDependency
mkColDependency DependencyReason
dependencyReason Column b
col =
SchemaObjId -> DependencyReason -> SchemaDependency
SchemaDependency
( SourceName -> AnyBackend SourceObjId -> SchemaObjId
SOSourceObj SourceName
source (AnyBackend SourceObjId -> SchemaObjId)
-> AnyBackend SourceObjId -> SchemaObjId
forall a b. (a -> b) -> a -> b
$
SourceObjId b -> AnyBackend SourceObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceObjId b -> AnyBackend SourceObjId)
-> SourceObjId b -> AnyBackend SourceObjId
forall a b. (a -> b) -> a -> b
$
TableName b -> TableObjId b -> SourceObjId b
forall (b :: BackendType).
TableName b -> TableObjId b -> SourceObjId b
SOITableObj @b TableName b
tableName (Column b -> TableObjId b
forall (b :: BackendType). Column b -> TableObjId b
TOCol @b Column b
col)
)
DependencyReason
dependencyReason
colDeps :: [SchemaDependency]
colDeps = (Column b -> SchemaDependency) -> [Column b] -> [SchemaDependency]
forall a b. (a -> b) -> [a] -> [b]
map (DependencyReason -> Column b -> SchemaDependency
mkColDependency DependencyReason
DRColumn) [Column b]
cols
payload :: [Column b]
payload = [Column b]
-> (SubscribeColumns b -> [Column b])
-> Maybe (SubscribeColumns b)
-> [Column b]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] SubscribeColumns b -> [Column b]
forall (b :: BackendType). SubscribeColumns b -> [Column b]
getColsFromSub (SubscribeOpSpec b -> Maybe (SubscribeColumns b)
forall (b :: BackendType).
SubscribeOpSpec b -> Maybe (SubscribeColumns b)
sosPayload SubscribeOpSpec b
os)
payloadDeps :: [SchemaDependency]
payloadDeps = (Column b -> SchemaDependency) -> [Column b] -> [SchemaDependency]
forall a b. (a -> b) -> [a] -> [b]
map (DependencyReason -> Column b -> SchemaDependency
mkColDependency DependencyReason
DRPayload) [Column b]
payload
in [SchemaDependency]
colDeps [SchemaDependency] -> [SchemaDependency] -> [SchemaDependency]
forall a. Semigroup a => a -> a -> a
<> [SchemaDependency]
payloadDeps
getColsFromSub :: SubscribeColumns b -> [Column b]
getColsFromSub SubscribeColumns b
sc = case SubscribeColumns b
sc of
SubscribeColumns b
SubCStar -> []
SubCArray [Column b]
cols -> [Column b]
cols
getTriggersMap ::
SourceMetadata b ->
InsOrdHashMap TriggerName (EventTriggerConf b)
getTriggersMap :: SourceMetadata b -> InsOrdHashMap TriggerName (EventTriggerConf b)
getTriggersMap = [InsOrdHashMap TriggerName (EventTriggerConf b)]
-> InsOrdHashMap TriggerName (EventTriggerConf b)
forall k (f :: * -> *) v.
(Eq k, Hashable k, Foldable f) =>
f (InsOrdHashMap k v) -> InsOrdHashMap k v
OMap.unions ([InsOrdHashMap TriggerName (EventTriggerConf b)]
-> InsOrdHashMap TriggerName (EventTriggerConf b))
-> (SourceMetadata b
-> [InsOrdHashMap TriggerName (EventTriggerConf b)])
-> SourceMetadata b
-> InsOrdHashMap TriggerName (EventTriggerConf b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TableMetadata b -> InsOrdHashMap TriggerName (EventTriggerConf b))
-> [TableMetadata b]
-> [InsOrdHashMap TriggerName (EventTriggerConf b)]
forall a b. (a -> b) -> [a] -> [b]
map TableMetadata b -> InsOrdHashMap TriggerName (EventTriggerConf b)
forall (b :: BackendType). TableMetadata b -> EventTriggers b
_tmEventTriggers ([TableMetadata b]
-> [InsOrdHashMap TriggerName (EventTriggerConf b)])
-> (SourceMetadata b -> [TableMetadata b])
-> SourceMetadata b
-> [InsOrdHashMap TriggerName (EventTriggerConf b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InsOrdHashMap (TableName b) (TableMetadata b) -> [TableMetadata b]
forall k v. InsOrdHashMap k v -> [v]
OMap.elems (InsOrdHashMap (TableName b) (TableMetadata b)
-> [TableMetadata b])
-> (SourceMetadata b
-> InsOrdHashMap (TableName b) (TableMetadata b))
-> SourceMetadata b
-> [TableMetadata b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceMetadata b -> InsOrdHashMap (TableName b) (TableMetadata b)
forall (b :: BackendType). SourceMetadata b -> Tables b
_smTables
getTriggerNames ::
SourceMetadata b ->
Set.HashSet TriggerName
getTriggerNames :: SourceMetadata b -> HashSet TriggerName
getTriggerNames = [TriggerName] -> HashSet TriggerName
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList ([TriggerName] -> HashSet TriggerName)
-> (SourceMetadata b -> [TriggerName])
-> SourceMetadata b
-> HashSet TriggerName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InsOrdHashMap TriggerName (EventTriggerConf b) -> [TriggerName]
forall k v. InsOrdHashMap k v -> [k]
OMap.keys (InsOrdHashMap TriggerName (EventTriggerConf b) -> [TriggerName])
-> (SourceMetadata b
-> InsOrdHashMap TriggerName (EventTriggerConf b))
-> SourceMetadata b
-> [TriggerName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceMetadata b -> InsOrdHashMap TriggerName (EventTriggerConf b)
forall (b :: BackendType).
SourceMetadata b -> InsOrdHashMap TriggerName (EventTriggerConf b)
getTriggersMap
getTableNameFromTrigger ::
forall b m.
(Backend b, QErrM m) =>
SchemaCache ->
SourceName ->
TriggerName ->
m (TableName b)
getTableNameFromTrigger :: SchemaCache -> SourceName -> TriggerName -> m (TableName b)
getTableNameFromTrigger SchemaCache
schemaCache SourceName
sourceName TriggerName
triggerName =
(TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> TableName b
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> TableName b
_tciName (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> TableName b)
-> (TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b))
-> TableInfo b
-> TableName b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo) (TableInfo b -> TableName b) -> m (TableInfo b) -> m (TableName b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SchemaCache -> SourceName -> TriggerName -> m (TableInfo b)
forall (b :: BackendType) (m :: * -> *).
(Backend b, QErrM m) =>
SchemaCache -> SourceName -> TriggerName -> m (TableInfo b)
getTabInfoFromSchemaCache @b SchemaCache
schemaCache SourceName
sourceName TriggerName
triggerName