Skip to content

Commit fb4efb2

Browse files
reinstate 'ref' field for compat, refresh lockfile (#732)
1 parent a2c2d16 commit fb4efb2

8 files changed

Lines changed: 217 additions & 136 deletions

File tree

app/src/App/API.purs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,9 @@ publish maybeLegacyContext payload = do
957957

958958
Storage.upload (un Manifest manifest).name (un Manifest manifest).version tarballPath
959959
Log.debug $ "Adding the new version " <> Version.print (un Manifest manifest).version <> " to the package metadata file."
960-
let newPublishedVersion = { hash, compilers: NonEmptyArray.singleton compiler, publishedTime, bytes }
960+
-- NOTE: The `ref` field is DEPRECATED and will be removed after 2027-01-31.
961+
-- We always write `Just ""` for backwards compatibility with older package managers.
962+
let newPublishedVersion = { hash, compilers: NonEmptyArray.singleton compiler, publishedTime, bytes, ref: Just "" }
961963
let newMetadata = metadata { published = Map.insert (un Manifest manifest).version newPublishedVersion metadata.published }
962964

963965
Registry.writeMetadata (un Manifest manifest).name (Metadata newMetadata)

flake.lock

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
mkSpagoDerivation.url = "github:jeslie0/mkSpagoDerivation";
1212
mkSpagoDerivation.inputs.nixpkgs.follows = "nixpkgs";
1313
mkSpagoDerivation.inputs.ps-overlay.follows = "purescript-overlay";
14+
# FIXME: Remove as soon as mkSpagoDerivation has the new registry
15+
mkSpagoDerivation.inputs.registry.url = "github:purescript/registry/a671816865ced88b888f31b8341f987aa7214027";
16+
mkSpagoDerivation.inputs.registry-index.url = "github:purescript/registry-index/d37611d409c5dd95793cc80066ef9400f36f66b0";
1417
};
1518

1619
outputs =

lib/src/Metadata.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ codec = Profunctor.wrapIso Metadata $ CJ.named "Metadata" $ CJ.object
6363
$ CJ.record
6464

6565
-- | Metadata about a published package version.
66+
-- |
67+
-- | NOTE: The `ref` field is DEPRECATED and WILL BE REMOVED after 2027-01-31.
68+
-- | It is only present for backwards compatibility with older package managers.
69+
-- | Do not rely on its presence!
6670
type PublishedMetadata =
6771
{ bytes :: Number
6872
, compilers :: NonEmptyArray Version
6973
, hash :: Sha256
7074
, publishedTime :: DateTime
75+
, ref :: Maybe String
7176
}
7277

7378
publishedMetadataCodec :: CJ.Codec PublishedMetadata
@@ -76,6 +81,7 @@ publishedMetadataCodec = CJ.named "PublishedMetadata" $ CJ.Record.object
7681
, compilers: CJ.Common.nonEmptyArray Version.codec
7782
, hash: Sha256.codec
7883
, publishedTime: Internal.Codec.iso8601DateTime
84+
, ref: CJ.Record.optional CJ.string
7985
}
8086

8187
-- | Metadata about an unpublished package version.

lib/test/Registry/Metadata.purs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ module Test.Registry.Metadata (spec) where
22

33
import Prelude
44

5+
import Codec.JSON.DecodeError as CJ.DecodeError
6+
import Data.Codec.JSON as CJ
7+
import Data.Either (Either(..))
8+
import Data.Maybe (Maybe(..))
9+
import Data.String as String
10+
import JSON as JSON
511
import Registry.Metadata as Metadata
612
import Registry.Test.Assert as Assert
13+
import Registry.Test.Utils as Utils
714
import Test.Spec (Spec)
815
import Test.Spec as Spec
916

@@ -14,6 +21,40 @@ spec = do
1421
[ { label: "record-studio", value: recordStudio }
1522
]
1623

24+
Spec.describe "PublishedMetadata ref field (deprecated)" do
25+
Spec.it "Decodes metadata without ref field" do
26+
let json = Utils.fromRight "Failed to parse JSON" $ JSON.parse publishedWithoutRef
27+
case CJ.decode Metadata.publishedMetadataCodec json of
28+
Left err -> Assert.fail $ "Failed to decode: " <> CJ.DecodeError.print err
29+
Right meta -> meta.ref `Assert.shouldEqual` Nothing
30+
31+
Spec.it "Decodes metadata with ref field" do
32+
let json = Utils.fromRight "Failed to parse JSON" $ JSON.parse publishedWithRef
33+
case CJ.decode Metadata.publishedMetadataCodec json of
34+
Left err -> Assert.fail $ "Failed to decode: " <> CJ.DecodeError.print err
35+
Right meta -> meta.ref `Assert.shouldEqual` (Just "v1.0.0")
36+
37+
Spec.it "Encodes Nothing as missing field (no ref in output)" do
38+
let json = Utils.fromRight "Failed to parse JSON" $ JSON.parse publishedWithoutRef
39+
case CJ.decode Metadata.publishedMetadataCodec json of
40+
Left err -> Assert.fail $ "Failed to decode: " <> CJ.DecodeError.print err
41+
Right meta -> do
42+
let encoded = CJ.encode Metadata.publishedMetadataCodec meta
43+
let jsonStr = JSON.printIndented encoded
44+
-- Nothing should result in the field being omitted
45+
String.contains (String.Pattern "\"ref\"") jsonStr `Assert.shouldEqual` false
46+
47+
Spec.it "Encodes Just \"\" as present field" do
48+
let json = Utils.fromRight "Failed to parse JSON" $ JSON.parse publishedWithRef
49+
case CJ.decode Metadata.publishedMetadataCodec json of
50+
Left err -> Assert.fail $ "Failed to decode: " <> CJ.DecodeError.print err
51+
Right meta -> do
52+
let withEmptyRef = meta { ref = Just "" }
53+
let encoded = CJ.encode Metadata.publishedMetadataCodec withEmptyRef
54+
let jsonStr = JSON.printIndented encoded
55+
-- Just "" should result in the field being present (with "ref": "" pattern)
56+
String.contains (String.Pattern "\"ref\": \"\"") jsonStr `Assert.shouldEqual` true
57+
1758
recordStudio :: String
1859
recordStudio =
1960
"""
@@ -65,3 +106,26 @@ recordStudio =
65106
}
66107
}
67108
}"""
109+
110+
-- PublishedMetadata without ref field (should decode with ref = Nothing)
111+
publishedWithoutRef :: String
112+
publishedWithoutRef =
113+
"""
114+
{
115+
"bytes": 3438,
116+
"compilers": ["0.15.10"],
117+
"hash": "sha256-LPRUC8ozZc7VCeRhKa4CtSgAfNqgAoVs2lH+7mYEcTk=",
118+
"publishedTime": "2021-03-27T10:03:46.000Z"
119+
}"""
120+
121+
-- PublishedMetadata with ref field (should decode with ref = Just "v1.0.0")
122+
publishedWithRef :: String
123+
publishedWithRef =
124+
"""
125+
{
126+
"bytes": 3438,
127+
"compilers": ["0.15.10"],
128+
"hash": "sha256-LPRUC8ozZc7VCeRhKa4CtSgAfNqgAoVs2lH+7mYEcTk=",
129+
"publishedTime": "2021-03-27T10:03:46.000Z",
130+
"ref": "v1.0.0"
131+
}"""

lib/test/Registry/Operation/Validation.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ spec = do
6767
inRange = unsafeDateTime "2022-12-11T12:00:00.000Z"
6868
compilers = NonEmptyArray.singleton (unsafeVersion "0.13.0")
6969

70-
publishedMetadata = { bytes: 100.0, hash: defaultHash, publishedTime: outOfRange, compilers }
70+
publishedMetadata = { bytes: 100.0, hash: defaultHash, publishedTime: outOfRange, compilers, ref: Just "" }
7171

7272
metadata = Metadata
7373
{ location: defaultLocation

0 commit comments

Comments
 (0)