packages feed

dhall-json 1.6.1 → 1.6.2

raw patch · 16 files changed

+275/−10 lines, 16 filesdep ~dhallPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: dhall

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,10 @@+1.6.2++* [Fix `dhall-json` for new `Prelude.JSON.Type`](https://github.com/dhall-lang/dhall-haskell/pull/1631)+    * Version 13.0.0 of the Prelude caused the `JSON` type to change, which+      broke `dhall-json`'s support for that type+    * This release fixes that (and still supports the old `JSON` type)+ 1.6.1  * [Fix typos in error messages](https://github.com/dhall-lang/dhall-haskell/pull/1595)
dhall-json.cabal view
@@ -1,8 +1,8 @@ Name: dhall-json-Version: 1.6.1+Version: 1.6.2 Cabal-Version: >=1.8.0.2 Build-Type: Simple-Tested-With: GHC == 7.10.3, GHC == 8.4.3, GHC == 8.6.1+Tested-With: GHC == 8.0.2, GHC == 8.4.3, GHC == 8.6.1 License: BSD3 License-File: LICENSE Copyright: 2017 Gabriel Gonzalez@@ -40,11 +40,11 @@         aeson-yaml                >= 1.0.5    && < 1.1 ,         bytestring                               < 0.11,         containers                                     ,-        dhall                     >= 1.28.0   && < 1.30,+        dhall                     >= 1.28.0   && < 1.31,         exceptions                >= 0.8.3    && < 0.11,         filepath                                 < 1.5 ,         optparse-applicative      >= 0.14.0.0 && < 0.16,-        prettyprinter             >= 1.5.1    && < 1.6 ,+        prettyprinter             >= 1.5.1    && < 1.7 ,         scientific                >= 0.3.0.0  && < 0.4 ,         text                      >= 0.11.1.0 && < 1.3 ,         unordered-containers                     < 0.3 ,
src/Dhall/JSON.hs view
@@ -540,6 +540,47 @@                     outer _ = Left (Unsupported e)                  outer value+        Core.Lam _ (Core.Const Core.Type)+            (Core.Lam _+                (Core.Record+                    [ ("array" , Core.Pi _ (Core.App Core.List (V 0)) (V 1))+                    , ("bool"  , Core.Pi _ Core.Bool (V 1))+                    , ("double", Core.Pi _ Core.Double (V 1))+                    , ("integer", Core.Pi _ Core.Integer (V 1))+                    , ("null"  , V 0)+                    , ("object", Core.Pi _ (Core.App Core.List (Core.Record [ ("mapKey", Core.Text), ("mapValue", V 0)])) (V 1))+                    , ("string", Core.Pi _ Core.Text (V 1))+                    ]+                )+                value+            ) -> do+                let outer (Core.Field (V 0) "null") = do+                        return Aeson.Null+                    outer (Core.App (Core.Field (V 0) "bool") (Core.BoolLit b)) = do+                        return (Aeson.Bool b)+                    outer (Core.App (Core.Field (V 0) "array") (Core.ListLit _ xs)) = do+                        ys <- traverse outer (Foldable.toList xs)++                        return (Aeson.Array (Vector.fromList ys))+                    outer (Core.App (Core.Field (V 0) "object") (Core.ListLit _ xs)) = do+                        let inner (Core.RecordLit [("mapKey", Core.TextLit (Core.Chunks [] mapKey)), ("mapValue", mapExpression)]) = do+                                mapValue <- outer mapExpression++                                return (mapKey, mapValue)+                            inner _ = Left (Unsupported e)++                        ys <- traverse inner (Foldable.toList xs)++                        return (Aeson.Object (HashMap.fromList ys))+                    outer (Core.App (Core.Field (V 0) "double") (Core.DoubleLit (DhallDouble n))) = do+                        return (Aeson.toJSON n)+                    outer (Core.App (Core.Field (V 0) "integer") (Core.IntegerLit n)) = do+                        return (Aeson.toJSON n)+                    outer (Core.App (Core.Field (V 0) "string") (Core.TextLit (Core.Chunks [] text))) = do+                        return (toJSON text)+                    outer _ = Left (Unsupported e)++                outer value         _ -> Left (Unsupported e)  getContents :: Expr s Void -> Maybe (Text, Maybe (Expr s Void))@@ -943,11 +984,11 @@           where             a' = fmap (fmap loop) a -        Core.Combine a b ->-            Core.Combine a' b'+        Core.Combine a b c ->+            Core.Combine a b' c'           where-            a' = loop a             b' = loop b+            c' = loop c          Core.CombineTypes a b ->             Core.CombineTypes a' b'
src/Dhall/JSON/Yaml.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP               #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards   #-} 
src/Dhall/JSONToDhall.hs view
@@ -225,7 +225,9 @@ import           Data.Foldable (toList) import qualified Data.HashMap.Strict as HM import           Data.List ((\\))+import qualified Data.List as List import           Data.Monoid ((<>))+import qualified Data.Ord as Ord import           Data.Scientific (floatingOrInteger, toRealFloat) import qualified Data.Sequence as Seq import qualified Data.String@@ -521,7 +523,7 @@     loop (App D.Optional expr) value         = D.Some <$> loop expr value -    -- Arbitrary JSON ~> https://prelude.dhall-lang.org/JSON/Type+    -- Arbitrary JSON ~> https://prelude.dhall-lang.org/JSON/Type (< v13.0.0)     loop       (D.Pi _ (D.Const D.Type)           (D.Pi _@@ -545,7 +547,14 @@                               , ("mapValue", outer val                  )                               ] -                      elements = Seq.fromList (fmap inner (HM.toList o))+                      elements =+                          Seq.fromList+                              (fmap inner+                                  (List.sortBy+                                      (Ord.comparing fst)+                                      (HM.toList o)+                                  )+                              )                        elementType                           | null elements =@@ -581,6 +590,86 @@                             , ("bool"  , D.Pi "_" D.Bool "JSON")                             , ("null"  , "JSON")                             , ("number", D.Pi "_" D.Double "JSON")+                            , ("object", D.Pi "_" (D.App D.List (D.Record [ ("mapKey", D.Text), ("mapValue", "JSON")])) "JSON")+                            , ("string", D.Pi "_" D.Text "JSON")+                            ]+                        )+                        (outer value)+                    )++          return result++    -- Arbitrary JSON ~> https://prelude.dhall-lang.org/JSON/Type (v13.0.0 <=)+    loop+      (D.Pi _ (D.Const D.Type)+          (D.Pi _+              (D.Record+                  [ ("array" , D.Pi _ (D.App D.List (V 0)) (V 1))+                  , ("bool"  , D.Pi _ D.Bool (V 1))+                  , ("double", D.Pi _ D.Double (V 1))+                  , ("integer", D.Pi _ D.Integer (V 1))+                  , ("null"  , V 0)+                  , ("object", D.Pi _ (D.App D.List (D.Record [ ("mapKey", D.Text), ("mapValue", V 0)])) (V 1))+                  , ("string", D.Pi _ D.Text (V 1))+                  ]+              )+              (V 1)+          )+      )+      value = do+          let outer (A.Object o) =+                  let inner (key, val) =+                          D.RecordLit+                              [ ("mapKey"  , D.TextLit (D.Chunks [] key))+                              , ("mapValue", outer val                  )+                              ]++                      elements =+                          Seq.fromList+                              (fmap inner+                                  (List.sortBy+                                      (Ord.comparing fst)+                                      (HM.toList o)+                                  )+                              )++                      elementType+                          | null elements =+                              Just (D.App D.List (D.Record [ ("mapKey", D.Text), ("mapValue", "JSON") ]))+                          | otherwise =+                              Nothing++                      keyValues = D.ListLit elementType elements++                  in  (D.App (D.Field "json" "object") keyValues)+              outer (A.Array a) =+                  let elements = Seq.fromList (fmap outer (Vector.toList a))++                      elementType+                          | null elements = Just (D.App D.List "JSON")+                          | otherwise     = Nothing++                  in  D.App (D.Field "json" "array") (D.ListLit elementType elements)+              outer (A.String s) =+                  D.App (D.Field "json" "string") (D.TextLit (D.Chunks [] s))+              outer (A.Number n) =+                  case floatingOrInteger n of+                      Left floating -> D.App (D.Field "json" "double") (D.DoubleLit (DhallDouble floating))+                      Right integer -> D.App (D.Field "json" "integer") (D.IntegerLit integer)+              outer (A.Bool b) =+                  D.App (D.Field "json" "bool") (D.BoolLit b)+              outer A.Null =+                  D.Field "json" "null"++          let result =+                D.Lam "JSON" (D.Const D.Type)+                    (D.Lam "json"+                        (D.Record+                            [ ("array" , D.Pi "_" (D.App D.List "JSON") "JSON")+                            , ("bool"  , D.Pi "_" D.Bool "JSON")+                            , ("double", D.Pi "_" D.Double "JSON")+                            , ("integer", D.Pi "_" D.Integer "JSON")+                            , ("null"  , "JSON")                             , ("object", D.Pi "_" (D.App D.List (D.Record [ ("mapKey", D.Text), ("mapValue", "JSON")])) "JSON")                             , ("string", D.Pi "_" D.Text "JSON")                             ]
tasty/Main.hs view
@@ -31,11 +31,15 @@     Test.Tasty.testGroup "dhall-json"         [ testDhallToJSON "./tasty/data/issue48"         , testDhallToJSON "./tasty/data/emptyObjectStrongType"+        , testDhallToJSON "./tasty/data/toArbitraryJSON_12_0_0"+        , testDhallToJSON "./tasty/data/toArbitraryJSON_13_0_0"         , testJSONToDhall "./tasty/data/emptyAlternative"         , testJSONToDhall "./tasty/data/emptyObject"         , testJSONToDhall "./tasty/data/emptyList"         , testJSONToDhall "./tasty/data/emptyObjectStrongType"         , testJSONToDhall "./tasty/data/emptyListStrongType"+        , testJSONToDhall "./tasty/data/fromArbitraryJSON_12_0_0"+        , testJSONToDhall "./tasty/data/fromArbitraryJSON_13_0_0"         , testCustomConversionJSONToDhall omissibleLists "./tasty/data/missingList"         , Test.Tasty.testGroup "Nesting"             [ testDhallToJSON "./tasty/data/nesting0"
+ tasty/data/fromArbitraryJSON_12_0_0.dhall view
@@ -0,0 +1,17 @@+  λ(JSON : Type)+→ λ ( json+    : { array : List JSON → JSON+      , bool : Bool → JSON+      , null : JSON+      , number : Double → JSON+      , object : List { mapKey : Text, mapValue : JSON } → JSON+      , string : Text → JSON+      }+    )+→ json.object+    [ { mapKey = "array", mapValue = json.array ([] : List JSON) }+    , { mapKey = "bool", mapValue = json.bool False }+    , { mapKey = "null", mapValue = json.null }+    , { mapKey = "number", mapValue = json.number 1.0 }+    , { mapKey = "string", mapValue = json.string "ABC" }+    ]
+ tasty/data/fromArbitraryJSON_12_0_0.json view
@@ -0,0 +1,7 @@+{+  "array": [],+  "bool": false,+  "null": null,+  "number": 1,+  "string": "ABC"+}
+ tasty/data/fromArbitraryJSON_12_0_0Schema.dhall view
@@ -0,0 +1,11 @@+  ∀(JSON : Type)+→ ∀ ( json+    : { array : List JSON → JSON+      , bool : Bool → JSON+      , null : JSON+      , number : Double → JSON+      , object : List { mapKey : Text, mapValue : JSON } → JSON+      , string : Text → JSON+      }+    )+→ JSON
+ tasty/data/fromArbitraryJSON_13_0_0.dhall view
@@ -0,0 +1,19 @@+  λ(JSON : Type)+→ λ ( json+    : { array : List JSON → JSON+      , bool : Bool → JSON+      , double : Double → JSON+      , integer : Integer → JSON+      , null : JSON+      , object : List { mapKey : Text, mapValue : JSON } → JSON+      , string : Text → JSON+      }+    )+→ json.object+    [ { mapKey = "array", mapValue = json.array ([] : List JSON) }+    , { mapKey = "bool", mapValue = json.bool False }+    , { mapKey = "double", mapValue = json.double 1.5 }+    , { mapKey = "integer", mapValue = json.integer +1 }+    , { mapKey = "null", mapValue = json.null }+    , { mapKey = "string", mapValue = json.string "ABC" }+    ]
+ tasty/data/fromArbitraryJSON_13_0_0.json view
@@ -0,0 +1,8 @@+{+  "array": [],+  "bool": false,+  "null": null,+  "double": 1.5,+  "integer": 1,+  "string": "ABC"+}
+ tasty/data/fromArbitraryJSON_13_0_0Schema.dhall view
@@ -0,0 +1,12 @@+  ∀(JSON : Type)+→ ∀ ( json+    : { array : List JSON → JSON+      , bool : Bool → JSON+      , double : Double → JSON+      , integer : Integer → JSON+      , null : JSON+      , object : List { mapKey : Text, mapValue : JSON } → JSON+      , string : Text → JSON+      }+    )+→ JSON
+ tasty/data/toArbitraryJSON_12_0_0.dhall view
@@ -0,0 +1,17 @@+  λ(_ : Type)+→ λ ( _+    : { array : List _ → _@1+      , bool : Bool → _@1+      , null : _+      , number : Double → _@1+      , object : List { mapKey : Text, mapValue : _ } → _@1+      , string : Text → _@1+      }+    )+→ _.object+    [ { mapKey = "array", mapValue = _.array ([] : List _@1) }+    , { mapKey = "bool", mapValue = _.bool False }+    , { mapKey = "null", mapValue = _.null }+    , { mapKey = "number", mapValue = _.number 1.0 }+    , { mapKey = "string", mapValue = _.string "ABC" }+    ]
+ tasty/data/toArbitraryJSON_12_0_0.json view
@@ -0,0 +1,7 @@+{+  "array": [],+  "bool": false,+  "null": null,+  "number": 1,+  "string": "ABC"+}
+ tasty/data/toArbitraryJSON_13_0_0.dhall view
@@ -0,0 +1,19 @@+  λ(_ : Type)+→ λ ( _+    : { array : List _ → _@1+      , bool : Bool → _@1+      , null : _+      , double : Double → _@1+      , integer : Integer → _@1+      , object : List { mapKey : Text, mapValue : _ } → _@1+      , string : Text → _@1+      }+    )+→ _.object+    [ { mapKey = "array", mapValue = _.array ([] : List _@1) }+    , { mapKey = "bool", mapValue = _.bool False }+    , { mapKey = "null", mapValue = _.null }+    , { mapKey = "double", mapValue = _.double 1.0 }+    , { mapKey = "integer", mapValue = _.integer +1 }+    , { mapKey = "string", mapValue = _.string "ABC" }+    ]
+ tasty/data/toArbitraryJSON_13_0_0.json view
@@ -0,0 +1,8 @@+{+  "array": [],+  "bool": false,+  "null": null,+  "double": 1,+  "integer": 1,+  "string": "ABC"+}