Skip to content

Commit

Permalink
Fail upon encountering unrecognized fields when parsing config struct…
Browse files Browse the repository at this point in the history
…ures (#697)

* Fail upon encountering unrecognized fields when parsing config structures

* Roll back record and spago.yaml changes

* Regenerate lockfile
  • Loading branch information
fsoikin authored Sep 8, 2024
1 parent 087f497 commit 7a42ca1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
24 changes: 12 additions & 12 deletions lib/src/Manifest.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Data.Array as Array
import Data.Array.NonEmpty (NonEmptyArray)
import Data.Codec.JSON as CJ
import Data.Codec.JSON.Common as CJ.Common
import Data.Codec.JSON.Strict as CJS
import Data.Map (Map)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype)
Expand All @@ -40,7 +41,6 @@ import Registry.Range (Range)
import Registry.Range as Range
import Registry.Version (Version)
import Registry.Version as Version
import Type.Proxy (Proxy(..))

-- | The manifest for a package version, which records critical information for
-- | the registry, pursuit, and package managers to use.
Expand Down Expand Up @@ -72,14 +72,14 @@ instance Ord Manifest where
-- | JSON object. The implementation uses explicitly ordered keys instead of
-- | record sugar.
codec :: CJ.Codec Manifest
codec = Profunctor.wrapIso Manifest $ CJ.named "Manifest" $ CJ.object
$ CJ.recordProp (Proxy :: _ "name") PackageName.codec
$ CJ.recordProp (Proxy :: _ "version") Version.codec
$ CJ.recordProp (Proxy :: _ "license") License.codec
$ CJ.recordPropOptional (Proxy :: _ "description") (Internal.Codec.limitedString 300)
$ CJ.recordProp (Proxy :: _ "location") Location.codec
$ CJ.recordPropOptional (Proxy :: _ "owners") (CJ.Common.nonEmptyArray Owner.codec)
$ CJ.recordPropOptional (Proxy :: _ "includeFiles") (CJ.Common.nonEmptyArray CJ.Common.nonEmptyString)
$ CJ.recordPropOptional (Proxy :: _ "excludeFiles") (CJ.Common.nonEmptyArray CJ.Common.nonEmptyString)
$ CJ.recordProp (Proxy :: _ "dependencies") (Internal.Codec.packageMap Range.codec)
$ CJ.record
codec = Profunctor.wrapIso Manifest $ CJ.named "Manifest" $ CJS.objectStrict
$ CJS.recordProp @"name" PackageName.codec
$ CJS.recordProp @"version" Version.codec
$ CJS.recordProp @"license" License.codec
$ CJS.recordPropOptional @"description" (Internal.Codec.limitedString 300)
$ CJS.recordProp @"location" Location.codec
$ CJS.recordPropOptional @"owners" (CJ.Common.nonEmptyArray Owner.codec)
$ CJS.recordPropOptional @"includeFiles" (CJ.Common.nonEmptyArray CJ.Common.nonEmptyString)
$ CJS.recordPropOptional @"excludeFiles" (CJ.Common.nonEmptyArray CJ.Common.nonEmptyString)
$ CJS.recordProp @"dependencies" (Internal.Codec.packageMap Range.codec)
$ CJS.record
14 changes: 7 additions & 7 deletions lib/src/Metadata.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Data.Array.NonEmpty (NonEmptyArray)
import Data.Codec.JSON as CJ
import Data.Codec.JSON.Common as CJ.Common
import Data.Codec.JSON.Record as CJ.Record
import Data.Codec.JSON.Strict as CJS
import Data.DateTime (DateTime)
import Data.Map (Map)
import Data.Maybe (Maybe)
Expand All @@ -37,7 +38,6 @@ import Registry.Owner as Owner
import Registry.Sha256 (Sha256)
import Registry.Sha256 as Sha256
import Registry.Version (Version)
import Type.Proxy (Proxy(..))

-- | A record of all published and unpublished versions of a package, along with
-- | the last-used location and any owners (public keys) authorized to take
Expand All @@ -55,12 +55,12 @@ derive instance Eq Metadata
-- | A codec for encoding and decoding a `Metadata` value as JSON. Represented
-- | as a JSON object. Keys are explicitly ordered.
codec :: CJ.Codec Metadata
codec = Profunctor.wrapIso Metadata $ CJ.named "Metadata" $ CJ.object
$ CJ.recordProp (Proxy :: _ "location") Location.codec
$ CJ.recordPropOptional (Proxy :: _ "owners") (CJ.Common.nonEmptyArray Owner.codec)
$ CJ.recordProp (Proxy :: _ "published") (Internal.Codec.versionMap publishedMetadataCodec)
$ CJ.recordProp (Proxy :: _ "unpublished") (Internal.Codec.versionMap unpublishedMetadataCodec)
$ CJ.record
codec = Profunctor.wrapIso Metadata $ CJ.named "Metadata" $ CJS.objectStrict
$ CJS.recordProp @"location" Location.codec
$ CJS.recordPropOptional @"owners" (CJ.Common.nonEmptyArray Owner.codec)
$ CJS.recordProp @"published" (Internal.Codec.versionMap publishedMetadataCodec)
$ CJS.recordProp @"unpublished" (Internal.Codec.versionMap unpublishedMetadataCodec)
$ CJS.record

-- | Metadata about a published package version.
-- |
Expand Down
14 changes: 7 additions & 7 deletions lib/src/PackageSet.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Registry.PackageSet
import Prelude

import Data.Codec.JSON as CJ
import Data.Codec.JSON.Strict as CJS
import Data.DateTime (Date)
import Data.Map (Map)
import Data.Newtype (class Newtype)
Expand All @@ -23,7 +24,6 @@ import Registry.Internal.Codec as Internal.Codec
import Registry.PackageName (PackageName)
import Registry.Version (Version)
import Registry.Version as Version
import Type.Proxy (Proxy(..))

-- | A Registry package set, which contains a set of packages at specific
-- | versions known to compile together with the given compiler version.
Expand All @@ -41,9 +41,9 @@ derive newtype instance Eq PackageSet
-- | JSON object. We use an explicit ordering instead of record sugar in the
-- | implementation.
codec :: CJ.Codec PackageSet
codec = Profunctor.wrapIso PackageSet $ CJ.named "PackageSet" $ CJ.object
$ CJ.recordProp (Proxy :: _ "version") Version.codec
$ CJ.recordProp (Proxy :: _ "compiler") Version.codec
$ CJ.recordProp (Proxy :: _ "published") Internal.Codec.iso8601Date
$ CJ.recordProp (Proxy :: _ "packages") (Internal.Codec.packageMap Version.codec)
$ CJ.record
codec = Profunctor.wrapIso PackageSet $ CJ.named "PackageSet" $ CJS.objectStrict
$ CJS.recordProp @"version" Version.codec
$ CJS.recordProp @"compiler" Version.codec
$ CJS.recordProp @"published" Internal.Codec.iso8601Date
$ CJS.recordProp @"packages" (Internal.Codec.packageMap Version.codec)
$ CJS.record
28 changes: 14 additions & 14 deletions spago.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ workspace:
- variant
test_dependencies: []
package_set:
registry: 50.10.0
registry: 59.0.0
extra_packages:
codec-json: 1.2.0
dodo-printer:
repo: https://github.com/natefaubion/purescript-dodo-printer.git
version: v2.2.1
Expand Down Expand Up @@ -407,8 +406,8 @@ packages:
- profunctor
codec-json:
type: registry
version: 1.2.0
integrity: sha256-59+uYYe/5uTFa/Q6EqF8ekvP/Y4SOjUNfwIqIYtNiGI=
version: 2.0.0
integrity: sha256-NLm5BmDZKKexQwtnoZ/NI4yI16srsqIe0M7NdlqB96U=
dependencies:
- codec
- foreign-object
Expand Down Expand Up @@ -594,8 +593,8 @@ packages:
- unfoldable
exceptions:
type: registry
version: 6.0.0
integrity: sha256-y/xTAEIZIARCE+50/u1di0ncebJ+CIwNOLswyOWzMTw=
version: 6.1.0
integrity: sha256-K0T89IHtF3vBY7eSAO7eDOqSb2J9kZGAcDN5+IKsF8E=
dependencies:
- effect
- either
Expand Down Expand Up @@ -940,8 +939,8 @@ packages:
- maybe
json:
type: registry
version: 1.0.0
integrity: sha256-UCHdePAoOD19UyCPLU97oZjcdxLlQZQneWFsfoUNNpE=
version: 1.1.0
integrity: sha256-LuN8PyX/gvRR4/7X7M9P+zL7BKbv34NcUE/7MILXQSA=
dependencies:
- either
- foldable-traversable
Expand Down Expand Up @@ -1159,8 +1158,8 @@ packages:
- unsafe-reference
node-fs:
type: registry
version: 9.1.0
integrity: sha256-TzhvGdrwcM0bazDvrWSqh+M/H8GKYf1Na6aGm2Qg4+c=
version: 9.2.0
integrity: sha256-Sg0vkXycEzkEerX6hLccz21Ygd9w1+QSk1thotRZPGI=
dependencies:
- datetime
- effect
Expand Down Expand Up @@ -1619,8 +1618,8 @@ packages:
- unsafe-coerce
spec:
type: registry
version: 7.6.0
integrity: sha256-+merGdQbL9zWONbnt8S8J9afGJ59MQqGtS0qSd3yu4I=
version: 8.0.0
integrity: sha256-Yn7MhDai1YULlQF45+9FTOTf2rcjoda1Jf2IrEFCoeg=
dependencies:
- aff
- ansi
Expand Down Expand Up @@ -1705,8 +1704,8 @@ packages:
- tuples
transformers:
type: registry
version: 6.0.0
integrity: sha256-Pzw40HjthX77tdPAYzjx43LK3X5Bb7ZspYAp27wksFA=
version: 6.1.0
integrity: sha256-3Bm+Z6tsC/paG888XkywDngJ2JMos+JfOhRlkVfb7gI=
dependencies:
- control
- distributive
Expand All @@ -1719,6 +1718,7 @@ packages:
- maybe
- newtype
- prelude
- st
- tailrec
- tuples
- unfoldable
Expand Down
3 changes: 1 addition & 2 deletions spago.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
workspace:
lock: true
package_set:
registry: 50.10.0
registry: 59.0.0
extra_packages:
codec-json: 1.2.0
dodo-printer:
repo: https://github.com/natefaubion/purescript-dodo-printer.git
version: v2.2.1
Expand Down

0 comments on commit 7a42ca1

Please sign in to comment.