Compare commits

...

3 Commits

Author SHA1 Message Date
5febe2f86f
chore: prepare v1.3.0 2024-06-23 19:46:13 -05:00
cf5d2c6431
fix: bump node-stream-pipes 2024-06-23 19:46:03 -05:00
b89279a5ec
chore: prepare v1.2.0 2024-06-22 19:40:56 -05:00
5 changed files with 15 additions and 36 deletions

View File

@ -1,6 +1,6 @@
{
"name": "purescript-cbor-stream",
"version": "v1.1.0",
"version": "v1.3.0",
"type": "module",
"dependencies": {
"cbor-x": "^1.5.9",

View File

@ -19,13 +19,11 @@ workspace:
- maybe: ">=6.0.0 <7.0.0"
- node-buffer: ">=9.0.0 <10.0.0"
- node-event-emitter: ">=3.0.0 <4.0.0"
- node-stream-pipes: ">=2.0.2 <3.0.0"
- node-stream-pipes: ">=2.1.0 <3.0.0"
- node-streams: ">=9.0.0 <10.0.0"
- nullable: ">=6.0.0 <7.0.0"
- ordered-collections: ">=3.2.0 <4.0.0"
- pipes
- prelude: ">=6.0.1 <7.0.0"
- profunctor
- record: ">=4.0.0 <5.0.0"
- simple-json: ">=9.0.0 <10.0.0"
- tailrec: ">=6.1.0 <7.0.0"
@ -633,8 +631,8 @@ packages:
- effect
node-stream-pipes:
type: registry
version: 2.0.2
integrity: sha256-IwkFgzWVwqjZkQRLYBGaRukKqYIw2I7wKHwIXRcdBWI=
version: 2.1.0
integrity: sha256-pYBOQY4bGEZzI5UHsUxJAhsKqtmE6CC1sHmFqgj64V8=
dependencies:
- aff
- arrays
@ -662,7 +660,6 @@ packages:
- parallel
- pipes
- prelude
- profunctor
- st
- strings
- tailrec

View File

@ -1,7 +1,7 @@
package:
name: cbor-stream
publish:
version: '1.1.0'
version: '1.3.0'
license: 'GPL-3.0-or-later'
location:
githubOwner: 'cakekindel'
@ -10,8 +10,6 @@ package:
strict: true
pedanticPackages: true
dependencies:
- pipes
- profunctor
- aff: ">=7.1.0 <8.0.0"
- arrays: ">=7.3.0 <8.0.0"
- bifunctors: ">=6.0.0 <7.0.0"
@ -28,7 +26,7 @@ package:
- maybe: ">=6.0.0 <7.0.0"
- node-buffer: ">=9.0.0 <10.0.0"
- node-event-emitter: ">=3.0.0 <4.0.0"
- node-stream-pipes: ">=2.0.2 <3.0.0"
- node-stream-pipes: ">=2.1.0 <3.0.0"
- node-streams: ">=9.0.0 <10.0.0"
- nullable: ">=6.0.0 <7.0.0"
- ordered-collections: ">=3.2.0 <4.0.0"

View File

@ -7,21 +7,15 @@ import Control.Monad.Except (runExcept)
import Control.Monad.Rec.Class (class MonadRec)
import Data.Bifunctor (lmap)
import Data.CBOR (class ReadCBOR, class WriteCBOR, readCBOR, writeCBOR)
import Data.Either (Either)
import Data.Maybe (Maybe)
import Data.Profunctor as Pro
import Data.Traversable (traverse)
import Effect.Aff.Class (class MonadAff)
import Effect.Exception (Error, error)
import Foreign (Foreign, MultipleErrors)
import Node.Buffer (Buffer)
import Node.Stream.CBOR.Decode as CBOR.Decode
import Node.Stream.CBOR.Encode as CBOR.Encode
import Pipes.Async (AsyncPipe)
import Pipes.Core (Pipe)
import Pipes.Node.Stream (TransformContext)
import Pipes.Async (AsyncPipe, bindIO, mapIO)
import Pipes.Node.Stream as Pipes.Stream
import Pipes.Prelude as Pipe
-- | Transforms buffer chunks of a CBOR file to parsed values
-- | of type `a`.
@ -31,14 +25,12 @@ decode
=> MonadAff m
=> MonadThrow Error m
=> ReadCBOR a
=> AsyncPipe (TransformContext Buffer Foreign) m (Maybe Buffer) (Maybe (Either MultipleErrors a))
=> AsyncPipe (Maybe Buffer) (Maybe a) m Unit
decode = do
let
parser = Pipes.Stream.fromTransform $ CBOR.Decode.toObjectStream <$> CBOR.Decode.make {}
Pro.rmap (map (runExcept <<< readCBOR @a)) parser
decodeError :: forall m a r. MonadThrow Error m => Pipe (Maybe (Either MultipleErrors a)) (Maybe a) m r
decodeError = Pipe.mapM (traverse liftEither <<< map (lmap $ error <<< show))
decoder = Pipes.Stream.fromTransformEffect $ CBOR.Decode.toObjectStream <$> CBOR.Decode.make {}
parse = liftEither <<< lmap (error <<< show) <<< runExcept <<< readCBOR @a
bindIO pure (traverse parse) decoder
-- | Encode purescript values as CBOR buffers
encode
@ -47,9 +39,9 @@ encode
=> MonadThrow Error m
=> MonadRec m
=> WriteCBOR a
=> AsyncPipe (TransformContext Foreign Buffer) m (Maybe a) (Maybe Buffer)
=> AsyncPipe (Maybe a) (Maybe Buffer) m Unit
encode =
let
p = Pipes.Stream.fromTransform $ CBOR.Encode.toObjectStream <$> CBOR.Encode.make {}
p = Pipes.Stream.fromTransformEffect $ CBOR.Encode.toObjectStream <$> CBOR.Encode.make {}
in
Pro.lcmap (map writeCBOR) p
mapIO (map writeCBOR) identity p

View File

@ -2,23 +2,17 @@ module Test.Pipes.CBOR where
import Prelude
import Control.Monad.Cont (lift)
import Control.Monad.Error.Class (liftEither)
import Control.Monad.Gen (chooseInt)
import Data.Bifunctor (lmap)
import Data.DateTime (DateTime)
import Data.List ((:))
import Data.List as List
import Data.Maybe (Maybe(..), fromJust)
import Data.Newtype (wrap)
import Data.PreciseDateTime (fromRFC3339String, toDateTimeLossy)
import Data.Traversable (traverse)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (delay)
import Effect.CBOR as CBOR
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Node.Buffer (Buffer)
import Node.Buffer as Buffer
import Node.Encoding (Encoding(..))
@ -28,7 +22,7 @@ import Pipes.Async (debug, (>-/->))
import Pipes.CBOR as Pipes.CBOR
import Pipes.Collect as Pipes.Collect
import Pipes.Node.Stream as Pipes.Stream
import Pipes.Prelude (mapM, toListM) as Pipes
import Pipes.Prelude (toListM) as Pipes
import Test.QuickCheck.Gen (randomSample')
import Test.Spec (Spec, before, describe, it)
import Test.Spec.Assertions (shouldEqual)
@ -67,7 +61,6 @@ spec =
rows <- Pipes.toListM
$ (yield (Just buf) *> yield Nothing)
>-/-> debug "cbor" Pipes.CBOR.decode
>-> Pipes.CBOR.decodeError
rows `shouldEqual` ((Just exp) : Nothing : List.Nil)
before
@ -87,7 +80,6 @@ spec =
Pipes.Collect.toArray
$ Pipes.Stream.withEOS (yield bytes)
>-/-> Pipes.CBOR.decode @(Array {id :: Int})
>-> Pipes.CBOR.decodeError
>-> Pipes.Stream.unEOS
rows `shouldEqual` [(\id -> { id }) <$> nums]