Repository navigation
Add facilities to explore the registry package sets from the CLI #1370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,49 +95,118 @@ info { package, json } = do | |
| Left err -> do | ||
| logDebug err | ||
| die $ "Could not find package " <> PackageName.print packageName | ||
| Right meta -> do | ||
| -- We just print out the metadata file | ||
| output case json of | ||
| true -> OutputJson Metadata.codec meta | ||
| false -> OutputYaml Metadata.codec meta | ||
| Right meta@(Metadata.Metadata { published }) -> do | ||
| -- Get package sets for each published version | ||
| { db } <- ask | ||
| let versions = Array.fromFoldable $ Map.keys published | ||
| packageSetsByVersion <- for versions \version -> do | ||
| entries <- liftEffect $ Db.selectPackageSetEntriesByPackage db packageName version | ||
| let setVersions = map _.packageSetVersion entries | ||
| pure { version, packageSets: Array.sort setVersions } | ||
|
|
||
| case json of | ||
| true -> do | ||
| -- For JSON, we include package sets in a combined output | ||
| let | ||
| versionSetsCodec = CJ.named "VersionPackageSets" $ CJ.Record.object | ||
| { version: Version.codec | ||
| , packageSets: CJ.array Version.codec | ||
| } | ||
| combinedCodec = CJ.named "PackageInfoWithSets" $ CJ.Record.object | ||
| { metadata: Metadata.codec | ||
| , packageSets: CJ.array versionSetsCodec | ||
| } | ||
| output $ OutputJson combinedCodec { metadata: meta, packageSets: packageSetsByVersion } | ||
| false -> do | ||
| -- For YAML/text output, print metadata then add package sets table | ||
| output $ OutputYaml Metadata.codec meta | ||
| -- Only show the package sets table if there are any | ||
| let nonEmptySets = Array.filter (\r -> not (Array.null r.packageSets)) packageSetsByVersion | ||
| when (not (Array.null nonEmptySets)) do | ||
| logInfo "" | ||
| logInfo "Package Sets containing each version:" | ||
| output $ OutputTable | ||
| { titles: [ "VERSION", "PACKAGE SETS" ] | ||
| , rows: nonEmptySets # map \{ version, packageSets: sets } -> | ||
| [ Version.print version | ||
| , String.joinWith ", " (map Version.print sets) | ||
| ] | ||
| } | ||
|
|
||
| type RegistryPackageSetsArgs = | ||
| { latest :: Boolean | ||
| , json :: Boolean | ||
| , set :: Maybe String | ||
| } | ||
|
|
||
| packageSets :: ∀ r. RegistryPackageSetsArgs -> Spago (RegistryEnv r) Unit | ||
| packageSets { latest, json } = do | ||
| availableSets <- Registry.listPackageSets | ||
| packageSets { latest, json, set } = do | ||
| case set of | ||
| Just setVersionStr -> do | ||
| -- Query packages in a specific package set | ||
| setVersion <- case parseLenientVersion setVersionStr of | ||
| Left err -> die [ "Could not parse package set version. Error:", show err ] | ||
| Right v -> pure v | ||
|
|
||
| let | ||
| sets = case latest of | ||
| false -> availableSets | ||
| true -> | ||
| -- here we need to keep only the highest version of all the sets with the same compiler version | ||
| Array.fromFoldable | ||
| $ Map.values | ||
| $ | ||
| foldl | ||
| ( \acc newSet -> case Map.lookup newSet.compiler acc of | ||
| Nothing -> Map.insert newSet.compiler newSet acc | ||
| Just { version } -> case newSet.version > version of | ||
| true -> Map.insert newSet.compiler newSet acc | ||
| false -> acc | ||
| ) | ||
| Map.empty | ||
| availableSets | ||
|
|
||
| output case json of | ||
| true -> OutputJson (CJ.array Db.packageSetCodec) sets | ||
| false -> OutputTable | ||
| { titles: [ "VERSION", "DATE", "COMPILER" ] | ||
| , rows: sets # map \{ version, date, compiler } -> | ||
| [ Version.print version | ||
| , DateTime.format Internal.Format.iso8601Date $ DateTime date bottom | ||
| , Version.print compiler | ||
| ] | ||
| } | ||
| { db } <- ask | ||
| entries <- liftEffect $ Db.selectPackageSetEntriesBySet db setVersion | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is reading directly from the database without a prior
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Came back to this to verify, and was able to using an isolated cache:
Could we initialize/refresh the registry before querying these entries? With a fresh cache, querying |
||
|
|
||
| when (Array.null entries) do | ||
| die $ "No packages found in package set " <> Version.print setVersion | ||
|
|
||
| -- Sort entries by package name for consistent output | ||
| let sortedEntries = Array.sortWith _.packageName entries | ||
|
|
||
| output case json of | ||
| true -> | ||
| let | ||
| entryCodec = CJ.named "PackageSetEntryOutput" $ CJ.Record.object | ||
| { packageName: PackageName.codec | ||
| , packageVersion: Version.codec | ||
| } | ||
| toOutput e = { packageName: e.packageName, packageVersion: e.packageVersion } | ||
| in | ||
| OutputJson (CJ.array entryCodec) (map toOutput sortedEntries) | ||
| false -> OutputTable | ||
| { titles: [ "PACKAGE", "VERSION" ] | ||
| , rows: sortedEntries # map \{ packageName, packageVersion } -> | ||
| [ PackageName.print packageName | ||
| , Version.print packageVersion | ||
| ] | ||
| } | ||
|
|
||
| Nothing -> do | ||
| -- Original behavior: list all package sets | ||
| availableSets <- Registry.listPackageSets | ||
|
|
||
| let | ||
| sets = case latest of | ||
| false -> availableSets | ||
| true -> | ||
| -- here we need to keep only the highest version of all the sets with the same compiler version | ||
| Array.fromFoldable | ||
| $ Map.values | ||
| $ | ||
| foldl | ||
| ( \acc newSet -> case Map.lookup newSet.compiler acc of | ||
| Nothing -> Map.insert newSet.compiler newSet acc | ||
| Just { version } -> case newSet.version > version of | ||
| true -> Map.insert newSet.compiler newSet acc | ||
| false -> acc | ||
| ) | ||
| Map.empty | ||
| availableSets | ||
|
|
||
| output case json of | ||
| true -> OutputJson (CJ.array Db.packageSetCodec) sets | ||
| false -> OutputTable | ||
| { titles: [ "VERSION", "DATE", "COMPILER" ] | ||
| , rows: sets # map \{ version, date, compiler } -> | ||
| [ Version.print version | ||
| , DateTime.format Internal.Format.iso8601Date $ DateTime date bottom | ||
| , Version.print compiler | ||
| ] | ||
| } | ||
|
|
||
| type RegistryTransferArgs = { privateKeyPath :: RawFilePath } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| +------------------------------+---------+ | ||
| | PACKAGE | VERSION | | ||
| +------------------------------+---------+ | ||
| | ace | 9.0.0 | | ||
| | aff | 7.1.0 | | ||
| | aff-bus | 6.0.0 | | ||
| | aff-coroutines | 9.0.0 | | ||
| | aff-promise | 4.0.0 | | ||
| | aff-retry | 2.0.0 | | ||
| | affjax | 13.0.0 | | ||
| | affjax-node | 1.0.0 | | ||
| | affjax-web | 1.0.0 | | ||
| | ansi | 7.0.0 | | ||
| | argonaut | 9.0.0 | | ||
| | argonaut-codecs | 9.1.0 | | ||
| | argonaut-core | 7.0.0 | | ||
| | argonaut-generic | 8.0.0 | | ||
| | argonaut-traversals | 10.0.0 | | ||
| | argparse-basic | 2.0.0 | | ||
| | array-builder | 0.1.2 | | ||
| | arraybuffer | 13.0.0 | | ||
| | arraybuffer-builder | 3.0.1 | | ||
| | arraybuffer-types | 3.0.2 | | ||
| | arrays | 7.1.0 | | ||
| | arrays-zipper | 2.0.1 | | ||
| | ask | 1.0.0 | | ||
| | assert | 6.0.0 | | ||
| | avar | 5.0.0 | | ||
| | b64 | 0.0.8 | | ||
| | barbies | 1.0.1 | | ||
| | barlow-lens | 0.9.0 | | ||
| | bifunctors | 6.0.0 | | ||
| | bigints | 7.0.1 | | ||
| | bolson | 0.1.1 | | ||
| | bower-json | 3.0.0 | | ||
| | call-by-name | 4.0.1 | | ||
| | canvas | 6.0.0 | | ||
| | canvas-action | 9.0.0 | | ||
| | cartesian | 1.0.6 | | ||
| | catenable-lists | 7.0.0 | | ||
| | channel | 1.0.0 | | ||
| | checked-exceptions | 3.1.1 | | ||
| | classnames | 2.0.0 | | ||
| | codec | 5.0.0 | | ||
| | codec-argonaut | 9.0.0 | | ||
| | colors | 7.0.1 | | ||
| | concur-core | 0.5.0 | | ||
| | concur-react | 0.5.0 | | ||
| | concurrent-queues | 3.0.0 | | ||
| | console | 6.0.0 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, this changes the released JSON shape by moving
published,location, andunpublishedundermetadata. I don’t know of existing consumers, but keeping those fields at the root and addingpackageSetswould preserve compatibility if we want to be extra-sure not to break anybody's scripting if they have it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(a github search came up with nothing so it's probably fine but I wanted to note it)