{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Unison.Server.Local.Endpoints.NamespaceListing (serve, NamespaceListingAPI, NamespaceListing (..), NamespaceObject (..), NamedNamespace (..), NamedPatch (..), KindExpression (..)) where
import Data.Aeson
import Data.OpenApi (ToSchema)
import Servant
( QueryParam,
(:>),
)
import Servant.Docs
( DocQueryParam (..),
ParamKind (Normal),
ToParam (..),
ToSample (..),
)
import Servant.OpenApi ()
import U.Codebase.Branch (NamespaceStats (..))
import U.Codebase.Causal qualified as V2Causal
import U.Codebase.HashTags (CausalHash (..))
import Unison.Codebase (Codebase)
import Unison.Codebase qualified as Codebase
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.ShortCausalHash (ShortCausalHash)
import Unison.Hash qualified as Hash
import Unison.Parser.Ann (Ann)
import Unison.Prelude
import Unison.PrettyPrintEnv qualified as PPE
import Unison.Server.Backend (Backend)
import Unison.Server.Backend qualified as Backend
import Unison.Server.Types
( APIGet,
HashQualifiedName,
NamedTerm (..),
NamedType (..),
UnisonHash,
UnisonName,
v2CausalBranchToUnisonHash,
)
import Unison.Symbol (Symbol)
import Unison.Syntax.NameSegment qualified as NameSegment
import Unison.Util.Pretty (Width)
import Unison.Var (Var)
type NamespaceListingAPI =
"list"
:> QueryParam "relativeTo" Path.Path
:> QueryParam "namespace" Path.Path
:> APIGet NamespaceListing
instance ToParam (QueryParam "namespace" Text) where
toParam :: Proxy (QueryParam "namespace" Text) -> DocQueryParam
toParam Proxy (QueryParam "namespace" Text)
_ =
String -> [String] -> String -> ParamKind -> DocQueryParam
DocQueryParam
String
"namespace"
[String
".", String
".base.List", String
"foo.bar"]
String
"The fully qualified name of a namespace. The leading `.` is optional."
ParamKind
Normal
instance ToSample NamespaceListing where
toSamples :: Proxy NamespaceListing -> [(Text, NamespaceListing)]
toSamples Proxy NamespaceListing
_ =
[ ( Text
"When no value is provided for `namespace`, the root namespace `.` is "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"listed by default",
Text -> Text -> [NamespaceObject] -> NamespaceListing
NamespaceListing
Text
"."
Text
"#gjlk0dna8dongct6lsd19d1o9hi5n642t8jttga5e81e91fviqjdffem0tlddj7ahodjo5"
[NamedNamespace -> NamespaceObject
Subnamespace (NamedNamespace -> NamespaceObject)
-> NamedNamespace -> NamespaceObject
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Int -> NamedNamespace
NamedNamespace Text
"base" Text
"#19d1o9hi5n642t8jttg" Int
237]
)
]
data NamespaceListing = NamespaceListing
{ NamespaceListing -> Text
namespaceListingFQN :: UnisonName,
NamespaceListing -> Text
namespaceListingHash :: UnisonHash,
NamespaceListing -> [NamespaceObject]
namespaceListingChildren :: [NamespaceObject]
}
deriving stock ((forall x. NamespaceListing -> Rep NamespaceListing x)
-> (forall x. Rep NamespaceListing x -> NamespaceListing)
-> Generic NamespaceListing
forall x. Rep NamespaceListing x -> NamespaceListing
forall x. NamespaceListing -> Rep NamespaceListing x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NamespaceListing -> Rep NamespaceListing x
from :: forall x. NamespaceListing -> Rep NamespaceListing x
$cto :: forall x. Rep NamespaceListing x -> NamespaceListing
to :: forall x. Rep NamespaceListing x -> NamespaceListing
Generic, Int -> NamespaceListing -> ShowS
[NamespaceListing] -> ShowS
NamespaceListing -> String
(Int -> NamespaceListing -> ShowS)
-> (NamespaceListing -> String)
-> ([NamespaceListing] -> ShowS)
-> Show NamespaceListing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NamespaceListing -> ShowS
showsPrec :: Int -> NamespaceListing -> ShowS
$cshow :: NamespaceListing -> String
show :: NamespaceListing -> String
$cshowList :: [NamespaceListing] -> ShowS
showList :: [NamespaceListing] -> ShowS
Show)
instance ToJSON NamespaceListing where
toJSON :: NamespaceListing -> Value
toJSON NamespaceListing {[NamespaceObject]
Text
namespaceListingFQN :: NamespaceListing -> Text
namespaceListingHash :: NamespaceListing -> Text
namespaceListingChildren :: NamespaceListing -> [NamespaceObject]
namespaceListingFQN :: Text
namespaceListingHash :: Text
namespaceListingChildren :: [NamespaceObject]
..} =
[Pair] -> Value
object
[ Key
"namespaceListingFQN" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
namespaceListingFQN,
Key
"namespaceListingHash" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
namespaceListingHash,
Key
"namespaceListingChildren" Key -> [NamespaceObject] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [NamespaceObject]
namespaceListingChildren
]
instance FromJSON NamespaceListing where
parseJSON :: Value -> Parser NamespaceListing
parseJSON = String
-> (Object -> Parser NamespaceListing)
-> Value
-> Parser NamespaceListing
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"NamespaceListing" ((Object -> Parser NamespaceListing)
-> Value -> Parser NamespaceListing)
-> (Object -> Parser NamespaceListing)
-> Value
-> Parser NamespaceListing
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
namespaceListingFQN <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"namespaceListingFQN"
namespaceListingHash <- o .: "namespaceListingHash"
namespaceListingChildren <- o .: "namespaceListingChildren"
pure NamespaceListing {..}
deriving instance ToSchema NamespaceListing
data NamespaceObject
= Subnamespace NamedNamespace
| TermObject NamedTerm
| TypeObject NamedType
| PatchObject NamedPatch
deriving ((forall x. NamespaceObject -> Rep NamespaceObject x)
-> (forall x. Rep NamespaceObject x -> NamespaceObject)
-> Generic NamespaceObject
forall x. Rep NamespaceObject x -> NamespaceObject
forall x. NamespaceObject -> Rep NamespaceObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NamespaceObject -> Rep NamespaceObject x
from :: forall x. NamespaceObject -> Rep NamespaceObject x
$cto :: forall x. Rep NamespaceObject x -> NamespaceObject
to :: forall x. Rep NamespaceObject x -> NamespaceObject
Generic, Int -> NamespaceObject -> ShowS
[NamespaceObject] -> ShowS
NamespaceObject -> String
(Int -> NamespaceObject -> ShowS)
-> (NamespaceObject -> String)
-> ([NamespaceObject] -> ShowS)
-> Show NamespaceObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NamespaceObject -> ShowS
showsPrec :: Int -> NamespaceObject -> ShowS
$cshow :: NamespaceObject -> String
show :: NamespaceObject -> String
$cshowList :: [NamespaceObject] -> ShowS
showList :: [NamespaceObject] -> ShowS
Show)
instance ToJSON NamespaceObject where
toJSON :: NamespaceObject -> Value
toJSON = \case
Subnamespace NamedNamespace
ns -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"Subnamespace", Key
"contents" Key -> NamedNamespace -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= NamedNamespace
ns]
TermObject NamedTerm
t -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"TermObject", Key
"contents" Key -> NamedTerm -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= NamedTerm
t]
TypeObject NamedType
t -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"TypeObject", Key
"contents" Key -> NamedType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= NamedType
t]
PatchObject NamedPatch
p -> [Pair] -> Value
object [Key
"tag" Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"PatchObject", Key
"contents" Key -> NamedPatch -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= NamedPatch
p]
instance FromJSON NamespaceObject where
parseJSON :: Value -> Parser NamespaceObject
parseJSON = String
-> (Object -> Parser NamespaceObject)
-> Value
-> Parser NamespaceObject
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"NamespaceObject" ((Object -> Parser NamespaceObject)
-> Value -> Parser NamespaceObject)
-> (Object -> Parser NamespaceObject)
-> Value
-> Parser NamespaceObject
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
tag <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tag"
case tag :: Text of
Text
"Subnamespace" -> NamedNamespace -> NamespaceObject
Subnamespace (NamedNamespace -> NamespaceObject)
-> Parser NamedNamespace -> Parser NamespaceObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser NamedNamespace
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
"TermObject" -> NamedTerm -> NamespaceObject
TermObject (NamedTerm -> NamespaceObject)
-> Parser NamedTerm -> Parser NamespaceObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser NamedTerm
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
"TypeObject" -> NamedType -> NamespaceObject
TypeObject (NamedType -> NamespaceObject)
-> Parser NamedType -> Parser NamespaceObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser NamedType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
"PatchObject" -> NamedPatch -> NamespaceObject
PatchObject (NamedPatch -> NamespaceObject)
-> Parser NamedPatch -> Parser NamespaceObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser NamedPatch
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"contents"
Text
_ -> String -> Parser NamespaceObject
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid NamespaceObject"
deriving instance ToSchema NamespaceObject
data NamedNamespace = NamedNamespace
{ NamedNamespace -> Text
namespaceName :: UnisonName,
NamedNamespace -> Text
namespaceHash :: UnisonHash,
NamedNamespace -> Int
namespaceSize :: Int
}
deriving ((forall x. NamedNamespace -> Rep NamedNamespace x)
-> (forall x. Rep NamedNamespace x -> NamedNamespace)
-> Generic NamedNamespace
forall x. Rep NamedNamespace x -> NamedNamespace
forall x. NamedNamespace -> Rep NamedNamespace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NamedNamespace -> Rep NamedNamespace x
from :: forall x. NamedNamespace -> Rep NamedNamespace x
$cto :: forall x. Rep NamedNamespace x -> NamedNamespace
to :: forall x. Rep NamedNamespace x -> NamedNamespace
Generic, Int -> NamedNamespace -> ShowS
[NamedNamespace] -> ShowS
NamedNamespace -> String
(Int -> NamedNamespace -> ShowS)
-> (NamedNamespace -> String)
-> ([NamedNamespace] -> ShowS)
-> Show NamedNamespace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NamedNamespace -> ShowS
showsPrec :: Int -> NamedNamespace -> ShowS
$cshow :: NamedNamespace -> String
show :: NamedNamespace -> String
$cshowList :: [NamedNamespace] -> ShowS
showList :: [NamedNamespace] -> ShowS
Show)
instance ToJSON NamedNamespace where
toJSON :: NamedNamespace -> Value
toJSON NamedNamespace {Int
Text
namespaceName :: NamedNamespace -> Text
namespaceHash :: NamedNamespace -> Text
namespaceSize :: NamedNamespace -> Int
namespaceName :: Text
namespaceHash :: Text
namespaceSize :: Int
..} =
[Pair] -> Value
object
[ Key
"namespaceName" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
namespaceName,
Key
"namespaceHash" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
namespaceHash,
Key
"namespaceSize" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
namespaceSize
]
instance FromJSON NamedNamespace where
parseJSON :: Value -> Parser NamedNamespace
parseJSON = String
-> (Object -> Parser NamedNamespace)
-> Value
-> Parser NamedNamespace
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"NamedNamespace" ((Object -> Parser NamedNamespace)
-> Value -> Parser NamedNamespace)
-> (Object -> Parser NamedNamespace)
-> Value
-> Parser NamedNamespace
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
namespaceName <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"namespaceName"
namespaceHash <- o .: "namespaceHash"
namespaceSize <- o .: "namespaceSize"
pure NamedNamespace {..}
deriving instance ToSchema NamedNamespace
newtype NamedPatch = NamedPatch {NamedPatch -> Text
patchName :: HashQualifiedName}
deriving stock ((forall x. NamedPatch -> Rep NamedPatch x)
-> (forall x. Rep NamedPatch x -> NamedPatch) -> Generic NamedPatch
forall x. Rep NamedPatch x -> NamedPatch
forall x. NamedPatch -> Rep NamedPatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NamedPatch -> Rep NamedPatch x
from :: forall x. NamedPatch -> Rep NamedPatch x
$cto :: forall x. Rep NamedPatch x -> NamedPatch
to :: forall x. Rep NamedPatch x -> NamedPatch
Generic, Int -> NamedPatch -> ShowS
[NamedPatch] -> ShowS
NamedPatch -> String
(Int -> NamedPatch -> ShowS)
-> (NamedPatch -> String)
-> ([NamedPatch] -> ShowS)
-> Show NamedPatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NamedPatch -> ShowS
showsPrec :: Int -> NamedPatch -> ShowS
$cshow :: NamedPatch -> String
show :: NamedPatch -> String
$cshowList :: [NamedPatch] -> ShowS
showList :: [NamedPatch] -> ShowS
Show)
deriving anyclass (Typeable NamedPatch
Typeable NamedPatch =>
(Proxy NamedPatch -> Declare (Definitions Schema) NamedSchema)
-> ToSchema NamedPatch
Proxy NamedPatch -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy NamedPatch -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy NamedPatch -> Declare (Definitions Schema) NamedSchema
ToSchema)
instance ToJSON NamedPatch where
toJSON :: NamedPatch -> Value
toJSON NamedPatch {Text
patchName :: NamedPatch -> Text
patchName :: Text
..} =
[Pair] -> Value
object
[ Key
"patchName" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
patchName
]
instance FromJSON NamedPatch where
parseJSON :: Value -> Parser NamedPatch
parseJSON = String
-> (Object -> Parser NamedPatch) -> Value -> Parser NamedPatch
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"NamedPatch" ((Object -> Parser NamedPatch) -> Value -> Parser NamedPatch)
-> (Object -> Parser NamedPatch) -> Value -> Parser NamedPatch
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
patchName <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"patchName"
pure NamedPatch {..}
newtype KindExpression = KindExpression {KindExpression -> Text
kindExpressionText :: Text}
deriving stock ((forall x. KindExpression -> Rep KindExpression x)
-> (forall x. Rep KindExpression x -> KindExpression)
-> Generic KindExpression
forall x. Rep KindExpression x -> KindExpression
forall x. KindExpression -> Rep KindExpression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. KindExpression -> Rep KindExpression x
from :: forall x. KindExpression -> Rep KindExpression x
$cto :: forall x. Rep KindExpression x -> KindExpression
to :: forall x. Rep KindExpression x -> KindExpression
Generic, Int -> KindExpression -> ShowS
[KindExpression] -> ShowS
KindExpression -> String
(Int -> KindExpression -> ShowS)
-> (KindExpression -> String)
-> ([KindExpression] -> ShowS)
-> Show KindExpression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KindExpression -> ShowS
showsPrec :: Int -> KindExpression -> ShowS
$cshow :: KindExpression -> String
show :: KindExpression -> String
$cshowList :: [KindExpression] -> ShowS
showList :: [KindExpression] -> ShowS
Show)
deriving anyclass (Typeable KindExpression
Typeable KindExpression =>
(Proxy KindExpression -> Declare (Definitions Schema) NamedSchema)
-> ToSchema KindExpression
Proxy KindExpression -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy KindExpression -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy KindExpression -> Declare (Definitions Schema) NamedSchema
ToSchema)
instance ToJSON KindExpression where
toJSON :: KindExpression -> Value
toJSON KindExpression {Text
kindExpressionText :: KindExpression -> Text
kindExpressionText :: Text
..} =
[Pair] -> Value
object
[ Key
"kindExpressionText" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
kindExpressionText
]
backendListEntryToNamespaceObject ::
(Var v) =>
PPE.PrettyPrintEnv ->
Maybe Width ->
Backend.ShallowListEntry v a ->
NamespaceObject
backendListEntryToNamespaceObject :: forall v a.
Var v =>
PrettyPrintEnv
-> Maybe Width -> ShallowListEntry v a -> NamespaceObject
backendListEntryToNamespaceObject PrettyPrintEnv
ppe Maybe Width
typeWidth = \case
Backend.ShallowTermEntry TermEntry v a
te ->
NamedTerm -> NamespaceObject
TermObject (NamedTerm -> NamespaceObject) -> NamedTerm -> NamespaceObject
forall a b. (a -> b) -> a -> b
$ PrettyPrintEnv -> Maybe Width -> TermEntry v a -> NamedTerm
forall v a.
Var v =>
PrettyPrintEnv -> Maybe Width -> TermEntry v a -> NamedTerm
Backend.termEntryToNamedTerm PrettyPrintEnv
ppe Maybe Width
typeWidth TermEntry v a
te
Backend.ShallowTypeEntry TypeEntry
te -> NamedType -> NamespaceObject
TypeObject (NamedType -> NamespaceObject) -> NamedType -> NamespaceObject
forall a b. (a -> b) -> a -> b
$ TypeEntry -> NamedType
Backend.typeEntryToNamedType TypeEntry
te
Backend.ShallowBranchEntry NameSegment
name CausalHash
hash (NamespaceStats {Int
numContainedTerms :: Int
numContainedTerms :: NamespaceStats -> Int
numContainedTerms, Int
numContainedTypes :: Int
numContainedTypes :: NamespaceStats -> Int
numContainedTypes, Int
numContainedPatches :: Int
numContainedPatches :: NamespaceStats -> Int
numContainedPatches}) ->
NamedNamespace -> NamespaceObject
Subnamespace (NamedNamespace -> NamespaceObject)
-> NamedNamespace -> NamespaceObject
forall a b. (a -> b) -> a -> b
$
NamedNamespace
{ namespaceName :: Text
namespaceName = NameSegment -> Text
NameSegment.toEscapedText NameSegment
name,
namespaceHash :: Text
namespaceHash = Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Hash -> Text
Hash.toBase32HexText (CausalHash -> Hash
unCausalHash CausalHash
hash),
namespaceSize :: Int
namespaceSize = Int
numContainedTerms Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
numContainedTypes Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
numContainedPatches
}
Backend.ShallowPatchEntry NameSegment
name ->
NamedPatch -> NamespaceObject
PatchObject (NamedPatch -> NamespaceObject)
-> (Text -> NamedPatch) -> Text -> NamespaceObject
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NamedPatch
NamedPatch (Text -> NamespaceObject) -> Text -> NamespaceObject
forall a b. (a -> b) -> a -> b
$ NameSegment -> Text
NameSegment.toEscapedText NameSegment
name
serve ::
Codebase IO Symbol Ann ->
Either ShortCausalHash CausalHash ->
Maybe Path.Path ->
Maybe Path.Path ->
Backend.Backend IO NamespaceListing
serve :: Codebase IO Symbol Ann
-> Either ShortCausalHash CausalHash
-> Maybe Path
-> Maybe Path
-> Backend IO NamespaceListing
serve Codebase IO Symbol Ann
codebase Either ShortCausalHash CausalHash
root Maybe Path
mayRelativeTo Maybe Path
mayNamespaceName = do
rootCausal <- (forall x. Transaction x -> IO x)
-> Backend Transaction (CausalBranch Transaction)
-> Backend IO (CausalBranch Transaction)
forall (m :: * -> *) (n :: * -> *) a.
(forall x. m x -> n x) -> Backend m a -> Backend n a
Backend.hoistBackend (Codebase IO Symbol Ann -> Transaction x -> IO x
forall (m :: * -> *) v a b.
MonadIO m =>
Codebase m v a -> Transaction b -> m b
Codebase.runTransaction Codebase IO Symbol Ann
codebase) (Backend Transaction (CausalBranch Transaction)
-> Backend IO (CausalBranch Transaction))
-> Backend Transaction (CausalBranch Transaction)
-> Backend IO (CausalBranch Transaction)
forall a b. (a -> b) -> a -> b
$ Either ShortCausalHash CausalHash
-> Backend Transaction (CausalBranch Transaction)
Backend.normaliseRootCausalHash Either ShortCausalHash CausalHash
root
let relativeToPath = Path -> Maybe Path -> Path
forall a. a -> Maybe a -> a
fromMaybe Path
forall a. Monoid a => a
mempty Maybe Path
mayRelativeTo
let namespacePath = Path -> Maybe Path -> Path
forall a. a -> Maybe a -> a
fromMaybe Path
forall a. Monoid a => a
mempty Maybe Path
mayNamespaceName
let path = Path
relativeToPath Path -> Path -> Path
forall a. Semigroup a => a -> a -> a
<> Path
namespacePath
(listingCausal, listingBranch) <-
(lift . Codebase.runTransaction codebase) do
listingCausal <- Codebase.getShallowCausalAtPath path rootCausal
listingBranch <- V2Causal.value listingCausal
pure (listingCausal, listingBranch)
let shallowPPE = PrettyPrintEnv
PPE.empty
let listingFQN = Path -> Text
forall path. Pathy path => path -> Text
Path.toText Path
path
let listingHash = CausalBranch Transaction -> Text
forall (m :: * -> *). CausalBranch m -> Text
v2CausalBranchToUnisonHash CausalBranch Transaction
listingCausal
listingEntries <- lift (Backend.lsBranch codebase listingBranch)
makeNamespaceListing shallowPPE listingFQN listingHash listingEntries
makeNamespaceListing ::
( PPE.PrettyPrintEnv ->
UnisonName ->
UnisonHash ->
[Backend.ShallowListEntry Symbol a] ->
Backend IO NamespaceListing
)
makeNamespaceListing :: forall a.
PrettyPrintEnv
-> Text
-> Text
-> [ShallowListEntry Symbol a]
-> Backend IO NamespaceListing
makeNamespaceListing PrettyPrintEnv
ppe Text
fqn Text
hash [ShallowListEntry Symbol a]
entries =
NamespaceListing -> Backend IO NamespaceListing
forall a. a -> Backend IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NamespaceListing -> Backend IO NamespaceListing)
-> ([NamespaceObject] -> NamespaceListing)
-> [NamespaceObject]
-> Backend IO NamespaceListing
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [NamespaceObject] -> NamespaceListing
NamespaceListing Text
fqn Text
hash ([NamespaceObject] -> Backend IO NamespaceListing)
-> [NamespaceObject] -> Backend IO NamespaceListing
forall a b. (a -> b) -> a -> b
$
(ShallowListEntry Symbol a -> NamespaceObject)
-> [ShallowListEntry Symbol a] -> [NamespaceObject]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
(PrettyPrintEnv
-> Maybe Width -> ShallowListEntry Symbol a -> NamespaceObject
forall v a.
Var v =>
PrettyPrintEnv
-> Maybe Width -> ShallowListEntry v a -> NamespaceObject
backendListEntryToNamespaceObject PrettyPrintEnv
ppe Maybe Width
forall a. Maybe a
Nothing)
[ShallowListEntry Symbol a]
entries