From b87bbbbe9697d2fef4b1f7f5e61e1b5d54dff4de Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Fri, 31 Jan 2025 11:04:49 -0800 Subject: [PATCH] Switch to unframed entities --- unison-cli/src/Unison/Share/SyncV2.hs | 10 +++++++--- unison-share-api/src/Unison/SyncV2/API.hs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/unison-cli/src/Unison/Share/SyncV2.hs b/unison-cli/src/Unison/Share/SyncV2.hs index 37f0720723..8f9768a7e0 100644 --- a/unison-cli/src/Unison/Share/SyncV2.hs +++ b/unison-cli/src/Unison/Share/SyncV2.hs @@ -440,21 +440,25 @@ type SyncAPI = ("ucm" Servant.:> "v2" Servant.:> "sync" Servant.:> SyncV2.API) syncAPI :: Proxy SyncAPI syncAPI = Proxy @SyncAPI -downloadEntitiesStreamClientM :: SyncV2.DownloadEntitiesRequest -> Servant.ClientM (Servant.SourceT IO SyncV2.DownloadEntitiesChunk) +downloadEntitiesStreamClientM :: SyncV2.DownloadEntitiesRequest -> Servant.ClientM (Servant.SourceT IO (CBORBytes SyncV2.DownloadEntitiesChunk)) SyncV2.Routes { downloadEntitiesStream = downloadEntitiesStreamClientM } = Servant.client syncAPI -- | Helper for running clientM that returns a stream of entities. -- You MUST consume the stream within the callback, it will be closed when the callback returns. -withConduit :: forall r. Servant.ClientEnv -> (Stream () SyncV2.DownloadEntitiesChunk -> StreamM r) -> Servant.ClientM (Servant.SourceIO SyncV2.DownloadEntitiesChunk) -> StreamM r +withConduit :: forall r. Servant.ClientEnv -> (Stream () (SyncV2.DownloadEntitiesChunk) -> StreamM r) -> Servant.ClientM (Servant.SourceIO (CBORBytes SyncV2.DownloadEntitiesChunk)) -> StreamM r withConduit clientEnv callback clientM = do ExceptT $ withRunInIO \runInIO -> do Servant.withClientM clientM clientEnv $ \case Left err -> pure . Left . TransportError $ (handleClientError clientEnv err) Right sourceT -> do conduit <- liftIO $ Servant.fromSourceIO sourceT - (runInIO . runExceptT $ callback conduit) + (runInIO . runExceptT $ callback (conduit C..| unpackCBORBytesStream)) + +unpackCBORBytesStream :: Stream (CBORBytes SyncV2.DownloadEntitiesChunk) SyncV2.DownloadEntitiesChunk +unpackCBORBytesStream = + C.map (BL.toStrict . coerce @_ @BL.ByteString) C..| decodeUnframedEntities handleClientError :: Servant.ClientEnv -> Servant.ClientError -> CodeserverTransportError handleClientError clientEnv err = diff --git a/unison-share-api/src/Unison/SyncV2/API.hs b/unison-share-api/src/Unison/SyncV2/API.hs index 71ea8693d3..ae575c1885 100644 --- a/unison-share-api/src/Unison/SyncV2/API.hs +++ b/unison-share-api/src/Unison/SyncV2/API.hs @@ -21,7 +21,7 @@ type API = NamedRoutes Routes type DownloadEntitiesStream = -- | The causal hash the client needs. The server should provide it and all of its dependencies ReqBody '[CBOR, JSON] DownloadEntitiesRequest - :> StreamPost NetstringFraming CBOR (SourceIO DownloadEntitiesChunk) + :> StreamPost NoFraming CBOR (SourceIO (CBORBytes DownloadEntitiesChunk)) data Routes mode = Routes { downloadEntitiesStream :: mode :- "entities" :> "download" :> DownloadEntitiesStream