@@ -4,14 +4,20 @@ module Kafka.Transaction
44 , commit
55 , abort
66 , send
7+ , sendOffsets
8+ , SendOffsets
9+ , TopicCommit
10+ , PartitionCommit
711 ) where
812
9−import Prelude (Unit, (#), (>>>))
1013import Control.Promise (Promise, toAffE)
1114import Data.Function.Uncurried (Fn2, runFn2)
1215import Effect (Effect)
1316import Effect.Aff (Aff)
17+import Kafka.Consumer (GroupId)
1418import Kafka.Producer (InternalProducerBatch, Producer, ProducerBatch, RecordMetadata, toInternalProducerBatch)
19+import Kafka.Types (Offset, Partition, Topic)
20+import Prelude (Unit, (#), (>>>))
1521
1622foreign import data Transaction :: Type
1723
@@ -20,6 +26,31 @@ foreign import transactionImpl :: Producer -> Effect (Promise Transaction)
2026transaction :: Producer -> Aff Transaction
2127transaction = transactionImpl >>> toAffE
2228
29+type PartitionCommit = {
30+ partition:: Partition,
31+ offset :: Offset
32+ }
33+
34+type TopicCommit = {
35+ topic :: Topic,
36+ partitions :: Array PartitionCommit
37+}
38+
39+type SendOffsets = {
40+ consumerGroupId :: GroupId,
41+ topics :: Array TopicCommit
42+}
43+
44+foreign import sendOffsetsImpl :: Fn2 Transaction SendOffsets (Effect (Promise Unit))
45+
46+sendOffsets :: Transaction -> SendOffsets -> Aff Unit
47+sendOffsets t so = runFn2 sendOffsetsImpl t so # toAffE
48+
49+foreign import sendImpl :: Fn2 Transaction InternalProducerBatch (Effect (Promise (Array RecordMetadata)))
50+
51+send :: Transaction -> ProducerBatch -> Aff (Array RecordMetadata)
52+send t pl = runFn2 sendImpl t (toInternalProducerBatch pl) # toAffE
53+
2354foreign import commitImpl :: Transaction -> Effect (Promise Unit)
2455
2556commit :: Transaction -> Aff Unit
@@ -30,7 +61,3 @@ foreign import abortImpl :: Transaction -> Effect (Promise Unit)
3061abort :: Transaction -> Aff Unit
3162abort = abortImpl >>> toAffE
3263
33−foreign import sendImpl :: Fn2 Transaction InternalProducerBatch (Effect (Promise (Array RecordMetadata)))
34−
35−send :: Transaction -> ProducerBatch -> Aff (Array RecordMetadata)
36−send t pl = runFn2 sendImpl t (toInternalProducerBatch pl) # toAffE