{-# LANGUAGE UndecidableInstances #-} module IHP.DataSync.Controller where import IHP.ControllerPrelude hiding (OrderByClause) import IHP.DataSync.Types import IHP.DataSync.RowLevelSecurity import qualified Database.PostgreSQL.Simple.ToField as PG import qualified IHP.DataSync.ChangeNotifications as ChangeNotifications import IHP.DataSync.ControllerImpl (runDataSyncController, cleanupAllSubscriptions) import IHP.DataSync.DynamicQueryCompiler (camelCaseRenamer) instance ( PG.ToField (PrimaryKey (GetTableName CurrentUserRecord)) , Show (PrimaryKey (GetTableName CurrentUserRecord)) , HasNewSessionUrl CurrentUserRecord , Typeable CurrentUserRecord , HasField "id" CurrentUserRecord (Id' (GetTableName CurrentUserRecord)) ) => WSApp DataSyncController where initialState :: DataSyncController initialState = DataSyncController DataSyncController run :: (?state::IORef DataSyncController, ?context::ControllerContext, ?applicationContext::ApplicationContext, ?modelContext::ModelContext, ?connection::Connection) => IO () run = do Text -> IO TableWithRLS ensureRLSEnabled <- IO (Text -> IO TableWithRLS) (?modelContext::ModelContext) => IO (Text -> IO TableWithRLS) makeCachedEnsureRLSEnabled TableWithRLS -> IO () installTableChangeTriggers <- IO (TableWithRLS -> IO ()) (?modelContext::ModelContext) => IO (TableWithRLS -> IO ()) ChangeNotifications.makeCachedInstallTableChangeTriggers (HasField "id" CurrentUserRecord (Id' (GetTableName CurrentUserRecord)), ?applicationContext::ApplicationContext, ?context::ControllerContext, ?modelContext::ModelContext, ?state::IORef DataSyncController, ToField (PrimaryKey (GetTableName CurrentUserRecord)), Typeable CurrentUserRecord, HasNewSessionUrl CurrentUserRecord, Show (PrimaryKey (GetTableName CurrentUserRecord))) => (Text -> IO TableWithRLS) -> (TableWithRLS -> IO ()) -> IO ByteString -> SendJSONFn -> HandleCustomMessageFn -> (Text -> Renamer) -> IO () (Text -> IO TableWithRLS) -> (TableWithRLS -> IO ()) -> IO ByteString -> SendJSONFn -> HandleCustomMessageFn -> (Text -> Renamer) -> IO () runDataSyncController Text -> IO TableWithRLS ensureRLSEnabled TableWithRLS -> IO () installTableChangeTriggers (forall a. (?connection::Connection, WebSocketsData a) => IO a receiveData @ByteString) SendJSONFn forall value. (?connection::Connection, ToJSON value) => value -> IO () sendJSON (\SendJSONFn _ DataSyncMessage _ -> () -> IO () forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure ()) (\Text _ -> Renamer camelCaseRenamer) onClose :: (?state::IORef DataSyncController, ?context::ControllerContext, ?applicationContext::ApplicationContext, ?modelContext::ModelContext, ?connection::Connection) => IO () onClose = IO () (?state::IORef DataSyncController, ?applicationContext::ApplicationContext) => IO () cleanupAllSubscriptions