-- SPDX-FileCopyrightText: 2026 Alexandra de Wit
--
-- SPDX-License-Identifier: MIT

{- | The ecosystem-neutral package model used by admission and rules.
Artifact entry keys retain source coordinates while adapters keep ownership of wire formats.
-}
module Ecluse.Core.Package (
    -- * Scopes
    Scope,
    mkScope,
    unScope,
    renderScope,

    -- * Package identity
    PackageName,
    mkPackageName,
    pkgEcosystem,
    pkgNamespace,
    pkgCanonical,
    pkgBaseName,
    renderPackageName,
    unscopedName,
    WireNameRefusal (..),
    unnamespacedWireName,

    -- * The name charset boundary
    isAsciiNameComponent,

    -- * Canonical keys
    canonicalise,

    -- * Normalised signals
    CodeExecSignal (..),
    DependencySources (..),
    Availability (..),

    -- * Artifacts
    Artifact (..),
    CoreMetadata (..),
    Hash,
    hashAlg,
    hashValue,
    mkHash,
    mkSriHashes,
    HashAlg (..),

    -- * Algorithm vocabulary
    renderHashAlg,
    parseHashAlg,
    sriPrefix,
    sriBody,
    sriAlgorithm,

    -- * Digest computation
    computeDigest,
    isComputable,

    -- * Per-version details
    PackageDetails (..),

    -- * Packument-level view
    PackageInfo (..),

    -- * Dropped entries
    InvalidEntry (invalidKind, invalidKey, invalidValue, invalidReason),
    mkInvalidEntry,
    InvalidEntryKind (..),
    renderInvalidEntryKind,
    dropCountsByKind,
) where

import Data.Char (isAscii, isControl)
import Data.Text qualified as T
import Data.Text.Short (ShortText)
import Data.Text.Short qualified as TS
import Data.Time (UTCTime)

import Ecluse.Core.Ecosystem (Ecosystem (..))
import Ecluse.Core.Package.Cargo (cargoNameKey)
import Ecluse.Core.Package.Entry (EntryKey)
import Ecluse.Core.Package.Hash (
    Hash,
    HashAlg (..),
    computeDigest,
    hashAlg,
    hashValue,
    isComputable,
    mkHash,
    mkSriHashes,
    parseHashAlg,
    renderHashAlg,
    sriAlgorithm,
    sriBody,
    sriPrefix,
 )
import Ecluse.Core.Package.InvalidEntry (
    InvalidEntry (invalidKey, invalidKind, invalidReason, invalidValue),
    InvalidEntryKind (..),
    dropCountsByKind,
    mkInvalidEntry,
    renderInvalidEntryKind,
 )
import Ecluse.Core.Package.Pep503 (normalisePyPI)
import Ecluse.Core.Version (Version)

{- | An npm scope without its leading @\@@. 'mkScope' removes that prefix,
so equality does not depend on how the scope was written.
-}
newtype Scope = Scope ShortText
    deriving stock (Scope -> Scope -> Bool
(Scope -> Scope -> Bool) -> (Scope -> Scope -> Bool) -> Eq Scope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Scope -> Scope -> Bool
== :: Scope -> Scope -> Bool
$c/= :: Scope -> Scope -> Bool
/= :: Scope -> Scope -> Bool
Eq, Eq Scope
Eq Scope =>
(Scope -> Scope -> Ordering)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Scope)
-> (Scope -> Scope -> Scope)
-> Ord Scope
Scope -> Scope -> Bool
Scope -> Scope -> Ordering
Scope -> Scope -> Scope
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Scope -> Scope -> Ordering
compare :: Scope -> Scope -> Ordering
$c< :: Scope -> Scope -> Bool
< :: Scope -> Scope -> Bool
$c<= :: Scope -> Scope -> Bool
<= :: Scope -> Scope -> Bool
$c> :: Scope -> Scope -> Bool
> :: Scope -> Scope -> Bool
$c>= :: Scope -> Scope -> Bool
>= :: Scope -> Scope -> Bool
$cmax :: Scope -> Scope -> Scope
max :: Scope -> Scope -> Scope
$cmin :: Scope -> Scope -> Scope
min :: Scope -> Scope -> Scope
Ord, Int -> Scope -> ShowS
[Scope] -> ShowS
Scope -> String
(Int -> Scope -> ShowS)
-> (Scope -> String) -> ([Scope] -> ShowS) -> Show Scope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Scope -> ShowS
showsPrec :: Int -> Scope -> ShowS
$cshow :: Scope -> String
show :: Scope -> String
$cshowList :: [Scope] -> ShowS
showList :: [Scope] -> ShowS
Show)

-- | Build a 'Scope', tolerating an optional leading @\'\@\'@.
mkScope :: Text -> Scope
mkScope :: Text -> Scope
mkScope Text
raw = ShortText -> Scope
Scope (Text -> ShortText
TS.fromText (Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
raw (Text -> Text -> Maybe Text
T.stripPrefix Text
"@" Text
raw)))

-- | The bare scope text, without the leading @\'\@\'@.
unScope :: Scope -> Text
unScope :: Scope -> Text
unScope (Scope ShortText
s) = ShortText -> Text
TS.toText ShortText
s

-- | Render a scope in npm wire form, with the leading @\'\@\'@.
renderScope :: Scope -> Text
renderScope :: Scope -> Text
renderScope (Scope ShortText
s) = Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ShortText -> Text
TS.toText ShortText
s

{- | A registry-independent identity built with 'mkPackageName'. Equality and ordering use
@('pkgEcosystem', 'pkgNamespace', 'pkgCanonical')@, excluding the display spelling.
-}
data PackageName = PackageName
    { PackageName -> Ecosystem
pkgEcosystem :: Ecosystem
    -- ^ The ecosystem this name belongs to.
    , PackageName -> Maybe Scope
pkgNamespace :: Maybe Scope
    -- ^ The npm scope. Unscoped ecosystems use 'Nothing'.
    , PackageName -> ShortText
pkgCanonical :: ShortText
    -- ^ The lookup key under the ecosystem's name grammar.
    , PackageName -> ShortText
pkgDisplay :: ShortText
    , PackageName -> ShortText
pkgBaseName :: ShortText
    {- ^ The base name with any @\@scope\/@ prefix dropped. It is not part of identity. Read it
    back through 'unscopedName'.
    -}
    }
    deriving stock (Int -> PackageName -> ShowS
[PackageName] -> ShowS
PackageName -> String
(Int -> PackageName -> ShowS)
-> (PackageName -> String)
-> ([PackageName] -> ShowS)
-> Show PackageName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PackageName -> ShowS
showsPrec :: Int -> PackageName -> ShowS
$cshow :: PackageName -> String
show :: PackageName -> String
$cshowList :: [PackageName] -> ShowS
showList :: [PackageName] -> ShowS
Show)

nameKey :: PackageName -> (Ecosystem, Maybe Scope, ShortText)
nameKey :: PackageName -> (Ecosystem, Maybe Scope, ShortText)
nameKey PackageName
n = (PackageName -> Ecosystem
pkgEcosystem PackageName
n, PackageName -> Maybe Scope
pkgNamespace PackageName
n, PackageName -> ShortText
pkgCanonical PackageName
n)

instance Eq PackageName where
    PackageName
a == :: PackageName -> PackageName -> Bool
== PackageName
b = PackageName -> (Ecosystem, Maybe Scope, ShortText)
nameKey PackageName
a (Ecosystem, Maybe Scope, ShortText)
-> (Ecosystem, Maybe Scope, ShortText) -> Bool
forall a. Eq a => a -> a -> Bool
== PackageName -> (Ecosystem, Maybe Scope, ShortText)
nameKey PackageName
b

instance Ord PackageName where
    compare :: PackageName -> PackageName -> Ordering
compare PackageName
a PackageName
b = (Ecosystem, Maybe Scope, ShortText)
-> (Ecosystem, Maybe Scope, ShortText) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (PackageName -> (Ecosystem, Maybe Scope, ShortText)
nameKey PackageName
a) (PackageName -> (Ecosystem, Maybe Scope, ShortText)
nameKey PackageName
b)

-- | Build a name with its ecosystem lookup key, retaining the published spelling.
mkPackageName :: Ecosystem -> Maybe Scope -> Text -> PackageName
mkPackageName :: Ecosystem -> Maybe Scope -> Text -> PackageName
mkPackageName Ecosystem
eco Maybe Scope
ns Text
raw =
    PackageName
        { pkgEcosystem :: Ecosystem
pkgEcosystem = Ecosystem
eco
        , pkgNamespace :: Maybe Scope
pkgNamespace = Maybe Scope
ns
        , pkgCanonical :: ShortText
pkgCanonical = Text -> ShortText
TS.fromText (Ecosystem -> Text -> Text
canonicalise Ecosystem
eco Text
display)
        , pkgDisplay :: ShortText
pkgDisplay = Text -> ShortText
TS.fromText Text
display
        , pkgBaseName :: ShortText
pkgBaseName = Text -> ShortText
TS.fromText Text
raw
        }
  where
    display :: Text
display = case Maybe Scope
ns of
        Just Scope
s -> Scope -> Text
renderScope Scope
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
raw
        Maybe Scope
Nothing -> Text
raw

{- | Normalise a display name into its canonical matching key for an ecosystem. An
ecosystem with a normalisation grammar keeps it in its own module.
-}
canonicalise :: Ecosystem -> Text -> Text
canonicalise :: Ecosystem -> Text -> Text
canonicalise = \case
    Ecosystem
Npm -> Text -> Text
forall a. a -> a
id
    Ecosystem
RubyGems -> Text -> Text
forall a. a -> a
id
    Ecosystem
PyPI -> Text -> Text
normalisePyPI
    Ecosystem
Cargo -> Text -> Text
cargoNameKey

-- | Render a package name in its native wire form (the display name).
renderPackageName :: PackageName -> Text
renderPackageName :: PackageName -> Text
renderPackageName = ShortText -> Text
TS.toText (ShortText -> Text)
-> (PackageName -> ShortText) -> PackageName -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageName -> ShortText
pkgDisplay

-- | The unscoped (base) name as 'Text': @\@babel\/code-frame@ reads back as @code-frame@.
unscopedName :: PackageName -> Text
unscopedName :: PackageName -> Text
unscopedName = ShortText -> Text
TS.toText (ShortText -> Text)
-> (PackageName -> ShortText) -> PackageName -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageName -> ShortText
pkgBaseName

-- | Why a wire name did not yield an unnamespaced package name.
data WireNameRefusal e
    = -- | The wire carried a non-empty namespace.
      WireNamespaced
    | -- | The ecosystem's grammar refused the bare name.
      WireNameUnusable e
    deriving stock (WireNameRefusal e -> WireNameRefusal e -> Bool
(WireNameRefusal e -> WireNameRefusal e -> Bool)
-> (WireNameRefusal e -> WireNameRefusal e -> Bool)
-> Eq (WireNameRefusal e)
forall e. Eq e => WireNameRefusal e -> WireNameRefusal e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall e. Eq e => WireNameRefusal e -> WireNameRefusal e -> Bool
== :: WireNameRefusal e -> WireNameRefusal e -> Bool
$c/= :: forall e. Eq e => WireNameRefusal e -> WireNameRefusal e -> Bool
/= :: WireNameRefusal e -> WireNameRefusal e -> Bool
Eq, Int -> WireNameRefusal e -> ShowS
[WireNameRefusal e] -> ShowS
WireNameRefusal e -> String
(Int -> WireNameRefusal e -> ShowS)
-> (WireNameRefusal e -> String)
-> ([WireNameRefusal e] -> ShowS)
-> Show (WireNameRefusal e)
forall e. Show e => Int -> WireNameRefusal e -> ShowS
forall e. Show e => [WireNameRefusal e] -> ShowS
forall e. Show e => WireNameRefusal e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall e. Show e => Int -> WireNameRefusal e -> ShowS
showsPrec :: Int -> WireNameRefusal e -> ShowS
$cshow :: forall e. Show e => WireNameRefusal e -> String
show :: WireNameRefusal e -> String
$cshowList :: forall e. Show e => [WireNameRefusal e] -> ShowS
showList :: [WireNameRefusal e] -> ShowS
Show)

-- | Refuse a non-empty wire namespace, then read the bare name through the ecosystem's grammar.
unnamespacedWireName :: (Text -> Either e PackageName) -> Maybe Text -> Text -> Either (WireNameRefusal e) PackageName
unnamespacedWireName :: forall e.
(Text -> Either e PackageName)
-> Maybe Text -> Text -> Either (WireNameRefusal e) PackageName
unnamespacedWireName Text -> Either e PackageName
parse Maybe Text
namespace Text
raw = Bool
-> Either (WireNameRefusal e) () -> Either (WireNameRefusal e) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool -> (Text -> Bool) -> Maybe Text -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True Text -> Bool
T.null Maybe Text
namespace) (WireNameRefusal e -> Either (WireNameRefusal e) ()
forall a b. a -> Either a b
Left WireNameRefusal e
forall e. WireNameRefusal e
WireNamespaced) Either (WireNameRefusal e) ()
-> Either (WireNameRefusal e) PackageName
-> Either (WireNameRefusal e) PackageName
forall a b.
Either (WireNameRefusal e) a
-> Either (WireNameRefusal e) b -> Either (WireNameRefusal e) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (e -> WireNameRefusal e)
-> Either e PackageName -> Either (WireNameRefusal e) PackageName
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first e -> WireNameRefusal e
forall e. e -> WireNameRefusal e
WireNameUnusable (Text -> Either e PackageName
parse Text
raw)

{- | Whether one component of a package name is ASCII with no control character: the boundary
every ecosystem's grammar rests on, because an invisible codepoint renders two names as one.
-}
isAsciiNameComponent :: Text -> Bool
isAsciiNameComponent :: Text -> Bool
isAsciiNameComponent = (Char -> Bool) -> Text -> Bool
T.all (\Char
ch -> Char -> Bool
isAscii Char
ch Bool -> Bool -> Bool
&& Bool -> Bool
not (Char -> Bool
isControl Char
ch))

-- | Whether installation executes package-supplied code, including builds and native extensions.
data CodeExecSignal
    = -- | Determined: installation runs no code.
      NoCodeOnInstall
    | -- | Determined: installation runs code. The text says how, for the audit trail.
      RunsCodeOnInstall Text
    | -- | Not determined from registry metadata. Rules that read it abstain.
      CodeExecUnknown
    deriving stock (CodeExecSignal -> CodeExecSignal -> Bool
(CodeExecSignal -> CodeExecSignal -> Bool)
-> (CodeExecSignal -> CodeExecSignal -> Bool) -> Eq CodeExecSignal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeExecSignal -> CodeExecSignal -> Bool
== :: CodeExecSignal -> CodeExecSignal -> Bool
$c/= :: CodeExecSignal -> CodeExecSignal -> Bool
/= :: CodeExecSignal -> CodeExecSignal -> Bool
Eq, Int -> CodeExecSignal -> ShowS
[CodeExecSignal] -> ShowS
CodeExecSignal -> String
(Int -> CodeExecSignal -> ShowS)
-> (CodeExecSignal -> String)
-> ([CodeExecSignal] -> ShowS)
-> Show CodeExecSignal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeExecSignal -> ShowS
showsPrec :: Int -> CodeExecSignal -> ShowS
$cshow :: CodeExecSignal -> String
show :: CodeExecSignal -> String
$cshowList :: [CodeExecSignal] -> ShowS
showList :: [CodeExecSignal] -> ShowS
Show)

-- | Whether installing a version fetches a dependency from somewhere other than the registry.
data DependencySources
    = -- | Every installable dependency resolves through the registry.
      RegistryDependencies
    | -- | A dependency installs from elsewhere, such as a git repository. The text names it, for the audit trail.
      FetchesOutsideRegistry Text
    | -- | Not determined: the adapter does not read dependency sources. Pure rules abstain.
      DependencySourcesUnknown
    deriving stock (DependencySources -> DependencySources -> Bool
(DependencySources -> DependencySources -> Bool)
-> (DependencySources -> DependencySources -> Bool)
-> Eq DependencySources
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DependencySources -> DependencySources -> Bool
== :: DependencySources -> DependencySources -> Bool
$c/= :: DependencySources -> DependencySources -> Bool
/= :: DependencySources -> DependencySources -> Bool
Eq, Int -> DependencySources -> ShowS
[DependencySources] -> ShowS
DependencySources -> String
(Int -> DependencySources -> ShowS)
-> (DependencySources -> String)
-> ([DependencySources] -> ShowS)
-> Show DependencySources
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DependencySources -> ShowS
showsPrec :: Int -> DependencySources -> ShowS
$cshow :: DependencySources -> String
show :: DependencySources -> String
$cshowList :: [DependencySources] -> ShowS
showList :: [DependencySources] -> ShowS
Show)

{- | Whether a version is offered, advisory-deprecated, or withdrawn. The registry's notice text
stays in the served document.
-}
data Availability
    = -- | Offered normally.
      Available
    | -- | Advisory deprecation (npm), still resolvable.
      Deprecated
    | -- | Withdrawn from resolution (PyPI yank keeps the file, RubyGems yank removes it).
      Yanked
    deriving stock (Availability -> Availability -> Bool
(Availability -> Availability -> Bool)
-> (Availability -> Availability -> Bool) -> Eq Availability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Availability -> Availability -> Bool
== :: Availability -> Availability -> Bool
$c/= :: Availability -> Availability -> Bool
/= :: Availability -> Availability -> Bool
Eq, Int -> Availability -> ShowS
[Availability] -> ShowS
Availability -> String
(Int -> Availability -> ShowS)
-> (Availability -> String)
-> ([Availability] -> ShowS)
-> Show Availability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Availability -> ShowS
showsPrec :: Int -> Availability -> ShowS
$cshow :: Availability -> String
show :: Availability -> String
$cshowList :: [Availability] -> ShowS
showList :: [Availability] -> ShowS
Show)

-- | The upstream companion declaration, preserving raw digest names and values.
data CoreMetadata
    = -- | The index declares availability without a digest.
      MetadataAvailable Bool
    | -- | Algorithm names and digest strings exactly as declared by the index.
      MetadataDigests (Map Text Text)
    deriving stock (CoreMetadata -> CoreMetadata -> Bool
(CoreMetadata -> CoreMetadata -> Bool)
-> (CoreMetadata -> CoreMetadata -> Bool) -> Eq CoreMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CoreMetadata -> CoreMetadata -> Bool
== :: CoreMetadata -> CoreMetadata -> Bool
$c/= :: CoreMetadata -> CoreMetadata -> Bool
/= :: CoreMetadata -> CoreMetadata -> Bool
Eq, Int -> CoreMetadata -> ShowS
[CoreMetadata] -> ShowS
CoreMetadata -> String
(Int -> CoreMetadata -> ShowS)
-> (CoreMetadata -> String)
-> ([CoreMetadata] -> ShowS)
-> Show CoreMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CoreMetadata -> ShowS
showsPrec :: Int -> CoreMetadata -> ShowS
$cshow :: CoreMetadata -> String
show :: CoreMetadata -> String
$cshowList :: [CoreMetadata] -> ShowS
showList :: [CoreMetadata] -> ShowS
Show)

-- | One distribution file with its source coordinate and optional metadata companion.
data Artifact = Artifact
    { Artifact -> EntryKey
artEntryKey :: EntryKey
    -- ^ The coordinate in its source snapshot. Admission preserves it unchanged.
    , Artifact -> Text
artFilename :: Text
    , Artifact -> Text
artUrl :: Text
    , Artifact -> [Hash]
artHashes :: [Hash]
    -- ^ Integrity digests. The client verifies the download against these.
    , Artifact -> Maybe CoreMetadata
artCoreMetadata :: Maybe CoreMetadata
    -- ^ The optional companion declaration, independent of distribution integrity.
    , Artifact -> Maybe Int
artSize :: Maybe Int
    {- ^ The registry-declared size, if reported. Not always the tarball byte count: npm populates
    it from @dist.unpackedSize@, the size of the unpacked tree.
    -}
    }
    deriving stock (Artifact -> Artifact -> Bool
(Artifact -> Artifact -> Bool)
-> (Artifact -> Artifact -> Bool) -> Eq Artifact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Artifact -> Artifact -> Bool
== :: Artifact -> Artifact -> Bool
$c/= :: Artifact -> Artifact -> Bool
/= :: Artifact -> Artifact -> Bool
Eq, Int -> Artifact -> ShowS
[Artifact] -> ShowS
Artifact -> String
(Int -> Artifact -> ShowS)
-> (Artifact -> String) -> ([Artifact] -> ShowS) -> Show Artifact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Artifact -> ShowS
showsPrec :: Int -> Artifact -> ShowS
$cshow :: Artifact -> String
show :: Artifact -> String
$cshowList :: [Artifact] -> ShowS
showList :: [Artifact] -> ShowS
Show)

{- | The ecosystem-agnostic snapshot of one package /version/: the signals a rule sees and the
artifact facts that merge, admission, serving and the mirror read. Adapters project into it.
-}
data PackageDetails = PackageDetails
    { PackageDetails -> PackageName
pkgName :: PackageName
    -- ^ The package identity this snapshot belongs to.
    , PackageDetails -> Version
pkgVersion :: Version
    -- ^ The specific version this snapshot describes.
    , PackageDetails -> Maybe UTCTime
pkgPublishedAt :: Maybe UTCTime
    {- ^ When this version was published, if known (absent from some cheap
    metadata views).
    -}
    , PackageDetails -> CodeExecSignal
pkgInstallCode :: CodeExecSignal
    -- ^ Whether installing the version executes code.
    , PackageDetails -> DependencySources
pkgDependencySources :: DependencySources
    -- ^ Whether installing the version fetches a dependency from outside the registry.
    , PackageDetails -> Availability
pkgAvailability :: Availability
    -- ^ Whether the version is offered, deprecated, or withdrawn.
    , PackageDetails -> NonEmpty Artifact
pkgArtifacts :: NonEmpty Artifact
    -- ^ The non-empty distribution set for this version.
    }
    deriving stock (PackageDetails -> PackageDetails -> Bool
(PackageDetails -> PackageDetails -> Bool)
-> (PackageDetails -> PackageDetails -> Bool) -> Eq PackageDetails
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PackageDetails -> PackageDetails -> Bool
== :: PackageDetails -> PackageDetails -> Bool
$c/= :: PackageDetails -> PackageDetails -> Bool
/= :: PackageDetails -> PackageDetails -> Bool
Eq, Int -> PackageDetails -> ShowS
[PackageDetails] -> ShowS
PackageDetails -> String
(Int -> PackageDetails -> ShowS)
-> (PackageDetails -> String)
-> ([PackageDetails] -> ShowS)
-> Show PackageDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PackageDetails -> ShowS
showsPrec :: Int -> PackageDetails -> ShowS
$cshow :: PackageDetails -> String
show :: PackageDetails -> String
$cshowList :: [PackageDetails] -> ShowS
showList :: [PackageDetails] -> ShowS
Show)

{- | A registry-independent package view containing per-version 'PackageDetails'.
Adapters own the wire format and project into this type.
-}
data PackageInfo = PackageInfo
    { PackageInfo -> PackageName
infoName :: PackageName
    -- ^ The package identity this document describes.
    , PackageInfo -> Map Text PackageDetails
infoVersions :: Map Text PackageDetails
    {- ^ Every published version, keyed by its __raw version string__. A 'Version' has no 'Ord',
    so ordering goes through 'Ecluse.Core.Version.compareVersions', never a derived instance.
    -}
    , PackageInfo -> Map Text Version
infoDistTags :: Map Text Version
    -- ^ Distribution tags (e.g. @"latest"@, @"next"@) to the 'Version' they point at.
    , PackageInfo -> [InvalidEntry]
infoInvalidEntries :: [InvalidEntry]
    {- ^ The malformed entries the projection __dropped__ rather than failing the whole
    document, kept so the serve path can surface them to an operator.
    -}
    }
    deriving stock (PackageInfo -> PackageInfo -> Bool
(PackageInfo -> PackageInfo -> Bool)
-> (PackageInfo -> PackageInfo -> Bool) -> Eq PackageInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PackageInfo -> PackageInfo -> Bool
== :: PackageInfo -> PackageInfo -> Bool
$c/= :: PackageInfo -> PackageInfo -> Bool
/= :: PackageInfo -> PackageInfo -> Bool
Eq, Int -> PackageInfo -> ShowS
[PackageInfo] -> ShowS
PackageInfo -> String
(Int -> PackageInfo -> ShowS)
-> (PackageInfo -> String)
-> ([PackageInfo] -> ShowS)
-> Show PackageInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PackageInfo -> ShowS
showsPrec :: Int -> PackageInfo -> ShowS
$cshow :: PackageInfo -> String
show :: PackageInfo -> String
$cshowList :: [PackageInfo] -> ShowS
showList :: [PackageInfo] -> ShowS
Show)