Skip to content

Commit dec693c

Browse files
committed
Add caDecodeFile, Re-export HydraSdk.Internal.Lib.Codec
1 parent ae394bc commit dec693c

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

spago.dhall

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
, "newtype"
2828
, "node-buffer"
2929
, "node-child-process"
30+
, "node-fs"
3031
, "node-path"
3132
, "node-streams"
3233
, "optparse"
@@ -48,5 +49,5 @@
4849
, "variant"
4950
]
5051
, packages = ./packages.dhall
51-
, sources = [ "src/**/*.purs", "app/**/*.purs", "test/**/*.purs" ]
52+
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
5253
}

src/Internal/Lib/Codec.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module HydraSdk.Internal.Lib.Codec
33
, class ToVariantGeneric
44
, addressCodec
55
, byteArrayCodec
6+
, caDecodeFile
67
, caDecodeString
78
, caEncodeString
89
, cborBytesCodec
@@ -79,7 +80,11 @@ import Data.Tuple (Tuple)
7980
import Data.UInt (fromString, toString) as UInt
8081
import Data.Variant (Variant)
8182
import Data.Variant (inj, prj) as Variant
83+
import Effect (Effect)
8284
import Foreign.Object (delete, fromHomogeneous, lookup, member, size, union) as Obj
85+
import Node.Encoding (Encoding(UTF8)) as Encoding
86+
import Node.FS.Sync (readTextFile) as FSSync
87+
import Node.Path (FilePath)
8388
import Partial.Unsafe (unsafePartial)
8489
import Prim.Row (class Cons) as Row
8590
import Type.Proxy (Proxy(Proxy))
@@ -191,6 +196,11 @@ fromCaJsonDecodeError = case _ of
191196
CA.Named name err -> A.Named name $ fromCaJsonDecodeError err
192197
CA.MissingValue -> A.MissingValue
193198

199+
caDecodeFile :: forall a. CA.JsonCodec a -> FilePath -> Effect (Either CA.JsonDecodeError a)
200+
caDecodeFile codec =
201+
map (caDecodeString codec)
202+
<<< FSSync.readTextFile Encoding.UTF8
203+
194204
caDecodeString :: forall a. CA.JsonCodec a -> String -> Either CA.JsonDecodeError a
195205
caDecodeString codec jsonStr = do
196206
json <- lmap (const (CA.TypeMismatch "JSON")) $ A.parseJson jsonStr

src/Lib.purs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module HydraSdk.Lib
2+
( module ExportCodec
3+
) where
4+
5+
import HydraSdk.Internal.Lib.Codec
6+
( class FromVariantGeneric
7+
, class ToVariantGeneric
8+
, addressCodec
9+
, byteArrayCodec
10+
, caDecodeFile
11+
, caDecodeString
12+
, caEncodeString
13+
, cborBytesCodec
14+
, dataHashCodec
15+
, dateTimeCodec
16+
, ed25519KeyHashCodec
17+
, fixTaggedSumCodec
18+
, fromCaJsonDecodeError
19+
, fromVariantGeneric
20+
, orefCodec
21+
, printOref
22+
, readOref
23+
, scriptHashCodec
24+
, sumGenericCodec
25+
, toVariantGeneric
26+
, txCodec
27+
, txHashCodec
28+
) as ExportCodec

0 commit comments

Comments
 (0)