Skip to content

Commit 4a07ef7

Browse files
committed
Bump hasql-listen notify and get more things compiling
1 parent 68d8b99 commit 4a07ef7

7 files changed

Lines changed: 62 additions & 56 deletions

File tree

share-api/src/Share/Notifications/Types.hs

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE ApplicativeDo #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE RecordWildCards #-}
34

@@ -74,7 +75,7 @@ data NotificationTopic
7475
deriving (Eq, Show, Ord, Enum, Bounded)
7576

7677
instance PG.EncodeValue NotificationTopic where
77-
encodeValue = HasqlEncoders.enum \case
78+
encodeValue = HasqlEncoders.enum Nothing "notification_topic" \case
7879
ProjectBranchUpdated -> "project:branch:updated"
7980
ProjectContributionCreated -> "project:contribution:created"
8081
ProjectContributionStatusUpdated -> "project:contribution:updated"
@@ -85,7 +86,7 @@ instance PG.EncodeValue NotificationTopic where
8586
ProjectReleaseCreated -> "project:release:created"
8687

8788
instance PG.DecodeValue NotificationTopic where
88-
decodeValue = HasqlDecoders.enum \case
89+
decodeValue = HasqlDecoders.enum Nothing "notification_topic" \case
8990
"project:branch:updated" -> Just ProjectBranchUpdated
9091
"project:contribution:created" -> Just ProjectContributionCreated
9192
"project:contribution:updated" -> Just ProjectContributionStatusUpdated
@@ -125,12 +126,12 @@ data NotificationTopicGroup
125126
deriving (Eq, Show, Ord)
126127

127128
instance PG.EncodeValue NotificationTopicGroup where
128-
encodeValue = HasqlEncoders.enum \case
129+
encodeValue = HasqlEncoders.enum Nothing "notification_topic_group" \case
129130
WatchProject -> "watch_project"
130131
AllProjectTopics -> "all_project_topics"
131132

132133
instance PG.DecodeValue NotificationTopicGroup where
133-
decodeValue = HasqlDecoders.enum \case
134+
decodeValue = HasqlDecoders.enum Nothing "notification_topic_group" \case
134135
"watch_project" -> Just WatchProject
135136
"all_project_topics" -> Just AllProjectTopics
136137
_ -> Nothing
@@ -179,13 +180,13 @@ instance Aeson.FromJSON NotificationStatus where
179180
s -> fail $ "Invalid notification status: " <> Text.unpack s
180181

181182
instance PG.EncodeValue NotificationStatus where
182-
encodeValue = HasqlEncoders.enum \case
183+
encodeValue = HasqlEncoders.enum Nothing "notification_status" \case
183184
Unread -> "unread"
184185
Read -> "read"
185186
Archived -> "archived"
186187

187188
instance PG.DecodeValue NotificationStatus where
188-
decodeValue = HasqlDecoders.enum \case
189+
decodeValue = HasqlDecoders.enum Nothing "notification_status" \case
189190
"unread" -> Just Unread
190191
"read" -> Just Read
191192
"archived" -> Just Archived
@@ -395,36 +396,39 @@ instance PG.EncodeValue NotificationEventData where
395396
instance Hasql.DecodeRow NotificationEventData where
396397
decodeRow = do
397398
topic <- PG.decodeField
398-
Hasql.Jsonb jsonData <- PG.decodeField
399-
case topic of
400-
ProjectBranchUpdated -> do
401-
(project :++ branch) <- parseJsonData jsonData
402-
pure $ ProjectBranchUpdatedData project branch
403-
ProjectContributionCreated -> do
404-
(project :++ contr) <- parseJsonData jsonData
405-
pure $ ProjectContributionCreatedData project contr
406-
ProjectContributionStatusUpdated -> do
407-
(project :++ contr :++ status) <- parseJsonData jsonData
408-
pure $ ProjectContributionStatusUpdatedData project contr status
409-
ProjectContributionComment -> do
410-
(project :++ contr :++ comm) <- parseJsonData jsonData
411-
pure $ ProjectContributionCommentData project contr comm
412-
ProjectTicketCreated -> do
413-
(project :++ ticket) <- parseJsonData jsonData
414-
pure $ ProjectTicketCreatedData project ticket
415-
ProjectTicketStatusUpdated -> do
416-
(project :++ ticket :++ status) <- parseJsonData jsonData
417-
pure $ ProjectTicketStatusUpdatedData project ticket status
418-
ProjectTicketComment -> do
419-
(project :++ ticket :++ comm) <- parseJsonData jsonData
420-
pure $ ProjectTicketCommentData project ticket comm
421-
ProjectReleaseCreated -> do
422-
(project :++ release) <- parseJsonData jsonData
423-
pure $ ProjectReleaseCreatedData project release
399+
jsonb <- PG.decodeField
400+
pure $
401+
-- ApplicativeDo isn't very smart, therefore, nested lets.
402+
let Hasql.Jsonb jsonData = jsonb
403+
in case topic of
404+
ProjectBranchUpdated ->
405+
let (project :++ branch) = parseJsonData jsonData
406+
in ProjectBranchUpdatedData project branch
407+
ProjectContributionCreated -> do
408+
let (project :++ contr) = parseJsonData jsonData
409+
in ProjectContributionCreatedData project contr
410+
ProjectContributionStatusUpdated -> do
411+
let (project :++ contr :++ status) = parseJsonData jsonData
412+
in ProjectContributionStatusUpdatedData project contr status
413+
ProjectContributionComment -> do
414+
let (project :++ contr :++ comm) = parseJsonData jsonData
415+
in ProjectContributionCommentData project contr comm
416+
ProjectTicketCreated -> do
417+
let (project :++ ticket) = parseJsonData jsonData
418+
in ProjectTicketCreatedData project ticket
419+
ProjectTicketStatusUpdated -> do
420+
let (project :++ ticket :++ status) = parseJsonData jsonData
421+
in ProjectTicketStatusUpdatedData project ticket status
422+
ProjectTicketComment -> do
423+
let (project :++ ticket :++ comm) = parseJsonData jsonData
424+
in ProjectTicketCommentData project ticket comm
425+
ProjectReleaseCreated -> do
426+
let (project :++ release) = parseJsonData jsonData
427+
in ProjectReleaseCreatedData project release
424428
where
425429
parseJsonData v = case Aeson.fromJSON v of
426-
Aeson.Error e -> fail e
427-
Aeson.Success a -> pure a
430+
Aeson.Error e -> error e
431+
Aeson.Success a -> a
428432

429433
eventTopic :: NotificationEventData -> NotificationTopic
430434
eventTopic = \case
@@ -530,8 +534,10 @@ data NotificationWebhookConfig = NotificationWebhookConfig
530534
instance PG.DecodeRow NotificationWebhookConfig where
531535
decodeRow = do
532536
webhookDeliveryId <- PG.decodeField
533-
URIParam webhookDeliveryUrl <- PG.decodeField
534-
pure $ NotificationWebhookConfig {webhookDeliveryId, webhookDeliveryUrl}
537+
url <- PG.decodeField
538+
pure $
539+
let URIParam webhookDeliveryUrl = url
540+
in NotificationWebhookConfig {webhookDeliveryId, webhookDeliveryUrl}
535541

536542
instance Aeson.ToJSON NotificationWebhookConfig where
537543
toJSON NotificationWebhookConfig {webhookDeliveryId, webhookDeliveryUrl} =
@@ -602,16 +608,17 @@ instance PG.DecodeRow (NotificationSubscription NotificationSubscriptionId) wher
602608
subscriptionScopeProject <- PG.decodeField
603609
subscriberUser <- PG.decodeField
604610
subscriberProject <- PG.decodeField
605-
let subscriptionOwner = case (subscriberUser, subscriberProject) of
606-
(Just uid, Nothing) -> UserSubscriptionOwner uid
607-
(Nothing, Just pid) -> ProjectSubscriptionOwner pid
608-
_ -> error "Invalid subscription owner in database"
609611
subscriptionTopics <- Set.fromList <$> PG.decodeField
610612
subscriptionTopicGroups <- Set.fromList <$> PG.decodeField
611613
subscriptionFilter <- PG.decodeField
612614
subscriptionCreatedAt <- PG.decodeField
613615
subscriptionUpdatedAt <- PG.decodeField
614-
pure $ NotificationSubscription {subscriptionId, subscriptionScopeUser, subscriptionScopeProject, subscriptionOwner, subscriptionTopics, subscriptionTopicGroups, subscriptionFilter, subscriptionCreatedAt, subscriptionUpdatedAt}
616+
pure $
617+
let subscriptionOwner = case (subscriberUser, subscriberProject) of
618+
(Just uid, Nothing) -> UserSubscriptionOwner uid
619+
(Nothing, Just pid) -> ProjectSubscriptionOwner pid
620+
_ -> error "Invalid subscription owner in database"
621+
in NotificationSubscription {subscriptionId, subscriptionScopeUser, subscriptionScopeProject, subscriptionOwner, subscriptionTopics, subscriptionTopicGroups, subscriptionFilter, subscriptionCreatedAt, subscriptionUpdatedAt}
615622

616623
instance Aeson.ToJSON (NotificationSubscription NotificationSubscriptionId) where
617624
toJSON NotificationSubscription {subscriptionId, subscriptionScopeUser, subscriptionScopeProject, subscriptionOwner, subscriptionTopics, subscriptionTopicGroups, subscriptionFilter, subscriptionCreatedAt, subscriptionUpdatedAt} =

share-api/src/Share/Postgres/Definitions/Queries.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ expectShareTermComponent (CodebaseEnv {codebaseOwner}) componentHashId = do
239239
-- Ensure we get at least one index, and that we have bytes saved for each part of the
240240
-- component.
241241
<&> checkElements
242-
)
242+
)
243243
`whenNothingM` do
244244
unrecoverableError $ InternalServerError "expected-term-component" (ExpectedTermComponentNotFound componentHashId)
245245
second (Hash32.fromHash . unComponentHash) . Share.TermComponent . toList <$> for componentElements \(termId, LocalTermBytes bytes) ->
@@ -1076,7 +1076,7 @@ saveTypeComponent (codebase@CodebaseEnv {codebaseOwner}) componentHash maySerial
10761076
constructorsTableWithIds <-
10771077
( HashQ.ensureComponentHashIdsOf (traversed . _4 . _Just) constructorsTable
10781078
>>= ensureTextIdsOf (traversed . _3 . _Just)
1079-
)
1079+
)
10801080

10811081
whenNonEmpty constructorsTableWithIds $
10821082
execute_
@@ -1372,7 +1372,7 @@ data ReferenceIdTuple = ReferenceIdTuple
13721372
deriving (Eq, Show)
13731373

13741374
instance Hasql.DecodeValue ReferenceIdTuple where
1375-
decodeValue = Decoders.composite $ do
1375+
decodeValue = Decoders.record $ do
13761376
tupleComponentHash <- Decoders.field $ Hasql.decodeField
13771377
tupleComponentIndex <- Decoders.field $ Hasql.decodeField
13781378
pure ReferenceIdTuple {tupleComponentHash, tupleComponentIndex}

share-api/src/Share/Postgres/NameLookups/Queries.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ newtype NamedReferentResult = NamedReferentResult (NamedRef (PGReferent, (Maybe
168168
deriving (Show)
169169

170170
instance Hasql.DecodeValue NamedReferentResult where
171-
decodeValue = Decoders.composite $ do
171+
decodeValue = Decoders.record $ do
172172
name <- Decoders.field $ Hasql.decodeField @ReversedName
173173
ref <- decodeComposite
174174
ct <- (Decoders.field $ Hasql.decodeField @(Maybe ConstructorType))
@@ -177,7 +177,7 @@ instance Hasql.DecodeValue NamedReferentResult where
177177
newtype NamedReferenceResult = NamedReferenceResult (NamedRef PGReference)
178178

179179
instance Hasql.DecodeValue NamedReferenceResult where
180-
decodeValue = Decoders.composite $ do
180+
decodeValue = Decoders.record $ do
181181
name <- Decoders.field $ Hasql.decodeField @ReversedName
182182
ref <- decodeComposite
183183
pure $ NamedReferenceResult (NamedRef name ref)
@@ -498,8 +498,7 @@ projectTermsWithinRootV1 !_nlReceipt bhId = do
498498
WHERE root_branch_hash_id = #{bhId}
499499
|]
500500
<&> fmap
501-
( \NamedRef {reversedSegments, ref} -> (reversedNameToName reversedSegments, referent2to1 ref)
502-
)
501+
(\NamedRef {reversedSegments, ref} -> (reversedNameToName reversedSegments, referent2to1 ref))
503502

504503
-- | Get a cursor over all non-lib terms within the given root branch.
505504
projectTermsWithinRoot :: (QueryM m) => NameLookupReceipt -> BranchHashId -> m (PGCursor (Name, V2.Referent))

share-api/src/Share/Postgres/NameLookups/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ data NameWithSuffix = NameWithSuffix
5757
deriving stock (Eq, Ord, Show, Generic)
5858

5959
instance PG.DecodeValue NameWithSuffix where
60-
decodeValue = Decoders.composite nameWithSuffixComposite
60+
decodeValue = Decoders.record nameWithSuffixComposite
6161

6262
nameWithSuffixComposite :: Decoders.Composite NameWithSuffix
6363
nameWithSuffixComposite = do

share-api/src/Share/Postgres/Notifications.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ initialize scope = Ki.fork_ scope $ forever do
4545
result <- UnliftIO.try $ do
4646
PG.runSession $ do
4747
for_ allChannels \kind -> do
48-
PG.statement () $ Hasql.listen (Hasql.Identifier . Text.encodeUtf8 $ toChannelText kind)
48+
PG.statement () $ Hasql.listen (Hasql.Identifier $ toChannelText kind)
4949
-- Wait for notifications
5050
let loop = do
5151
Hasql.Notification {channel} <- PG.Session . lift . lift . lift $ Hasql.await

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extra-deps:
8787
# Updated to work against hasql-1.10
8888
# Unfortunately hasql-1.10 makes its libpq dependencies more private
8989
- github: ChrisPenner/hasql-listen-notify
90-
commit: d75951239f1b8f2d87425769bc1aa29dc17b5ce8
90+
commit: 9bd6fcf058faf36d3bf9aea2a09acdd112490106
9191

9292
ghc-options:
9393
# All packages

stack.yaml.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ packages:
197197
- completed:
198198
name: hasql-listen-notify
199199
pantry-tree:
200-
sha256: 4b1f48dc8015debc556f6fc77d903891905f5b56f855c7d26d11a55444147cc3
200+
sha256: fc73475fc9fcae1102afbd981927bc66a4499ffe57bf432b952a16b9bb06e917
201201
size: 610
202-
sha256: 9e1128de5650d45a126b45d63a6dc27c23b53782d33283c5304eea094e4ec68c
203-
size: 8687
204-
url: https://github.com/ChrisPenner/hasql-listen-notify/archive/d75951239f1b8f2d87425769bc1aa29dc17b5ce8.tar.gz
202+
sha256: d040a58f9cec7ca260e5bd8c37cce2879b02476d28e7f276f81d44e0fe20d68a
203+
size: 8838
204+
url: https://github.com/ChrisPenner/hasql-listen-notify/archive/9bd6fcf058faf36d3bf9aea2a09acdd112490106.tar.gz
205205
version: 0.1.0.1
206206
original:
207-
url: https://github.com/ChrisPenner/hasql-listen-notify/archive/d75951239f1b8f2d87425769bc1aa29dc17b5ce8.tar.gz
207+
url: https://github.com/ChrisPenner/hasql-listen-notify/archive/9bd6fcf058faf36d3bf9aea2a09acdd112490106.tar.gz
208208
snapshots:
209209
- completed:
210210
sha256: 4b787f53036611a03edbf438dd5412daa03fb3da5d938ae8865ec471fe3f9632

0 commit comments

Comments
 (0)