From e7ec23d3c81cf873ce01ddcc61f3608fca2569fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Wed, 6 Apr 2022 16:58:22 -0400 Subject: [PATCH] Add separate Share and Local Api modules --- src/Api.elm | 219 --------------------------- src/Env.elm | 12 +- src/UnisonLocal/Api.elm | 101 ++++++++++++ src/UnisonLocal/App.elm | 23 +-- src/UnisonLocal/PreApp.elm | 7 +- src/UnisonShare/Api.elm | 124 +++++++++++++++ src/UnisonShare/App.elm | 13 +- src/UnisonShare/AppModal.elm | 2 +- src/UnisonShare/Page/CatalogPage.elm | 11 +- src/UnisonShare/Page/UserPage.elm | 7 +- src/UnisonShare/PreApp.elm | 5 +- 11 files changed, 262 insertions(+), 262 deletions(-) delete mode 100644 src/Api.elm create mode 100644 src/UnisonLocal/Api.elm create mode 100644 src/UnisonShare/Api.elm diff --git a/src/Api.elm b/src/Api.elm deleted file mode 100644 index f4f0016..0000000 --- a/src/Api.elm +++ /dev/null @@ -1,219 +0,0 @@ -module Api exposing - ( ApiBasePath(..) - , ApiRequest - , codebaseApiEndpointToEndpointUrl - , codebaseHash - , getDefinition - , namespace - , perform - , projects - , toRequest - , toTask - , toUrl - ) - -import Code.CodebaseApi as CodebaseApi -import Code.EntityId as EntityId -import Code.FullyQualifiedName as FQN exposing (FQN) -import Code.Hash as Hash exposing (Hash) -import Code.Perspective as Perspective exposing (Perspective(..)) -import Code.Syntax as Syntax -import Http -import Json.Decode as Decode -import Lib.Api exposing (EndpointUrl(..)) -import Regex -import Task exposing (Task) -import Url.Builder exposing (QueryParameter, absolute, int, string) - - - --- ENDPOINT ------------------------------------------------------------------- - - -type Endpoint - = Endpoint (List String) (List QueryParameter) - - -toUrl : ApiBasePath -> Endpoint -> String -toUrl (ApiBasePath basePath) (Endpoint paths queryParams) = - absolute (basePath ++ paths) queryParams - - -codebaseHash : Endpoint -codebaseHash = - Endpoint [ "list" ] [ string "namespace" "." ] - - -namespace : Perspective -> FQN -> Endpoint -namespace perspective fqn = - let - queryParams = - [ rootBranch (Perspective.codebaseHash perspective) ] - in - Endpoint [ "namespaces", FQN.toString fqn ] queryParams - - -projects : Maybe String -> Endpoint -projects owner = - let - queryParams = - case owner of - Just owner_ -> - [ string "owner" owner_ ] - - Nothing -> - [] - in - Endpoint [ "projects" ] queryParams - - -getDefinition : Perspective -> List String -> Endpoint -getDefinition perspective fqnsOrHashes = - let - re = - Maybe.withDefault Regex.never (Regex.fromString "#[d|a|](\\d+)$") - - stripConstructorPositionFromHash = - Regex.replace re (always "") - in - fqnsOrHashes - |> List.map stripConstructorPositionFromHash - |> List.map (string "names") - |> (\names -> Endpoint [ "getDefinition" ] (names ++ perspectiveToQueryParams perspective)) - - -codebaseApiEndpointToEndpointUrl : CodebaseApi.CodebaseEndpoint -> Lib.Api.EndpointUrl -codebaseApiEndpointToEndpointUrl cbEndpoint = - case cbEndpoint of - CodebaseApi.Find { perspective, withinFqn, limit, sourceWidth, query } -> - let - params = - case withinFqn of - Just fqn -> - [ rootBranch (Perspective.codebaseHash perspective), relativeTo fqn ] - - Nothing -> - perspectiveToQueryParams perspective - - width = - case sourceWidth of - Syntax.Width w -> - w - in - EndpointUrl - [ "find" ] - ([ int "limit" limit - , int "renderWidth" width - , string "query" query - ] - ++ params - ) - - CodebaseApi.Browse { perspective, namespaceId } -> - let - namespace_ = - namespaceId |> Maybe.map EntityId.toString |> Maybe.withDefault "." - in - EndpointUrl [ "list" ] (string "namespace" namespace_ :: perspectiveToQueryParams perspective) - - CodebaseApi.Definition { perspective, definitionId } -> - let - re = - Maybe.withDefault Regex.never (Regex.fromString "#[d|a|](\\d+)$") - - stripConstructorPositionFromHash = - Regex.replace re (always "") - in - [ EntityId.toString definitionId ] - |> List.map stripConstructorPositionFromHash - |> List.map (string "names") - |> (\names -> EndpointUrl [ "getDefinition" ] (names ++ perspectiveToQueryParams perspective)) - - - --- REQUEST -------------------------------------------------------------------- - - -type ApiBasePath - = ApiBasePath (List String) - - -type ApiRequest a msg - = ApiRequest Endpoint (Decode.Decoder a) (Result Http.Error a -> msg) - - -toRequest : Decode.Decoder a -> (Result Http.Error a -> msg) -> Endpoint -> ApiRequest a msg -toRequest decoder toMsg endpoint = - ApiRequest endpoint decoder toMsg - - -perform : ApiBasePath -> ApiRequest a msg -> Cmd msg -perform basePath (ApiRequest endpoint decoder toMsg) = - Http.get - { url = toUrl basePath endpoint - , expect = Http.expectJson toMsg decoder - } - - - ---- TASK ---------------------------------------------------------------------- - - -{-| TODO Perhaps this API should be merged into ApiRequest fully?? | --} -toTask : ApiBasePath -> Decode.Decoder a -> Endpoint -> Task Http.Error a -toTask basePath decoder endpoint = - Http.task - { method = "GET" - , headers = [] - , url = toUrl basePath endpoint - , body = Http.emptyBody - , resolver = Http.stringResolver (httpJsonBodyResolver decoder) - , timeout = Nothing - } - - -httpJsonBodyResolver : Decode.Decoder a -> Http.Response String -> Result Http.Error a -httpJsonBodyResolver decoder resp = - case resp of - Http.GoodStatus_ _ s -> - Decode.decodeString decoder s - |> Result.mapError (Decode.errorToString >> Http.BadBody) - - Http.BadUrl_ s -> - Err (Http.BadUrl s) - - Http.Timeout_ -> - Err Http.Timeout - - Http.NetworkError_ -> - Err Http.NetworkError - - Http.BadStatus_ m s -> - Decode.decodeString decoder s - -- just trying; if our decoder understands the response body, great - |> Result.mapError (\_ -> Http.BadStatus m.statusCode) - - - --- QUERY PARAMS --------------------------------------------------------------- - - -perspectiveToQueryParams : Perspective -> List QueryParameter -perspectiveToQueryParams perspective = - case perspective of - Codebase h -> - [ rootBranch h ] - - Namespace d -> - [ rootBranch d.codebaseHash, relativeTo d.fqn ] - - -rootBranch : Hash -> QueryParameter -rootBranch hash = - string "rootBranch" (hash |> Hash.toString) - - -relativeTo : FQN -> QueryParameter -relativeTo fqn = - string "relativeTo" (fqn |> FQN.toString) diff --git a/src/Env.elm b/src/Env.elm index c1159ee..aea8865 100644 --- a/src/Env.elm +++ b/src/Env.elm @@ -1,11 +1,10 @@ module Env exposing (..) -import Api exposing (ApiBasePath(..)) import Browser.Navigation as Nav import Code.CodebaseApi as CodebaseApi import Code.Config import Code.Perspective exposing (Perspective) -import Lib.Api +import Lib.Api exposing (ApiBasePath(..)) import Lib.OperatingSystem as OS exposing (OperatingSystem) @@ -37,15 +36,8 @@ init flags navKey perspective = toCodeConfig : CodebaseApi.ToApiEndpointUrl -> Env -> Code.Config.Config toCodeConfig toApiEndpointUrl env = - let - (ApiBasePath path) = - env.apiBasePath - - apiBasePath = - Lib.Api.ApiBasePath path - in { operatingSystem = env.operatingSystem , perspective = env.perspective , toApiEndpointUrl = toApiEndpointUrl - , apiBasePath = apiBasePath + , apiBasePath = env.apiBasePath } diff --git a/src/UnisonLocal/Api.elm b/src/UnisonLocal/Api.elm new file mode 100644 index 0000000..b585970 --- /dev/null +++ b/src/UnisonLocal/Api.elm @@ -0,0 +1,101 @@ +module UnisonLocal.Api exposing + ( codebaseApiEndpointToEndpointUrl + , codebaseHash + , namespace + ) + +import Code.CodebaseApi as CodebaseApi +import Code.EntityId as EntityId +import Code.FullyQualifiedName as FQN exposing (FQN) +import Code.Hash as Hash exposing (Hash) +import Code.Perspective as Perspective exposing (Perspective(..)) +import Code.Syntax as Syntax +import Lib.Api as Api exposing (EndpointUrl(..)) +import Regex +import Url.Builder exposing (QueryParameter, int, string) + + +codebaseHash : EndpointUrl +codebaseHash = + EndpointUrl [ "list" ] [ string "namespace" "." ] + + +namespace : Perspective -> FQN -> EndpointUrl +namespace perspective fqn = + let + queryParams = + [ rootBranch (Perspective.codebaseHash perspective) ] + in + EndpointUrl [ "namespaces", FQN.toString fqn ] queryParams + + +codebaseApiEndpointToEndpointUrl : CodebaseApi.CodebaseEndpoint -> EndpointUrl +codebaseApiEndpointToEndpointUrl cbEndpoint = + case cbEndpoint of + CodebaseApi.Find { perspective, withinFqn, limit, sourceWidth, query } -> + let + params = + case withinFqn of + Just fqn -> + [ rootBranch (Perspective.codebaseHash perspective), relativeTo fqn ] + + Nothing -> + perspectiveToQueryParams perspective + + width = + case sourceWidth of + Syntax.Width w -> + w + in + EndpointUrl + [ "find" ] + ([ int "limit" limit + , int "renderWidth" width + , string "query" query + ] + ++ params + ) + + CodebaseApi.Browse { perspective, namespaceId } -> + let + namespace_ = + namespaceId |> Maybe.map EntityId.toString |> Maybe.withDefault "." + in + EndpointUrl [ "list" ] (string "namespace" namespace_ :: perspectiveToQueryParams perspective) + + CodebaseApi.Definition { perspective, definitionId } -> + let + re = + Maybe.withDefault Regex.never (Regex.fromString "#[d|a|](\\d+)$") + + stripConstructorPositionFromHash = + Regex.replace re (always "") + in + [ EntityId.toString definitionId ] + |> List.map stripConstructorPositionFromHash + |> List.map (string "names") + |> (\names -> EndpointUrl [ "getDefinition" ] (names ++ perspectiveToQueryParams perspective)) + + + +-- QUERY PARAMS --------------------------------------------------------------- + + +perspectiveToQueryParams : Perspective -> List QueryParameter +perspectiveToQueryParams perspective = + case perspective of + Codebase h -> + [ rootBranch h ] + + Namespace d -> + [ rootBranch d.codebaseHash, relativeTo d.fqn ] + + +rootBranch : Hash -> QueryParameter +rootBranch hash = + string "rootBranch" (hash |> Hash.toString) + + +relativeTo : FQN -> QueryParameter +relativeTo fqn = + string "relativeTo" (fqn |> FQN.toString) diff --git a/src/UnisonLocal/App.elm b/src/UnisonLocal/App.elm index 046b260..5ab4d89 100644 --- a/src/UnisonLocal/App.elm +++ b/src/UnisonLocal/App.elm @@ -1,6 +1,5 @@ module UnisonLocal.App exposing (..) -import Api import Browser import Browser.Navigation as Nav import Code.CodebaseTree as CodebaseTree @@ -18,6 +17,7 @@ import Html exposing (Html, a, div, h1, h2, h3, nav, p, section, span, strong, t import Html.Attributes exposing (class, classList, href, id, rel, target, title) import Html.Events exposing (onClick) import Http +import Lib.Api as HttpApi import Lib.OperatingSystem exposing (OperatingSystem(..)) import Lib.Util as Util import RemoteData @@ -33,6 +33,7 @@ import UI.Modal as Modal import UI.PageLayout as PageLayout import UI.Sidebar as Sidebar import UI.Tooltip as Tooltip +import UnisonLocal.Api as LocalApi import UnisonLocal.PerspectiveLanding as PerspectiveLanding import UnisonLocal.Route as Route exposing (Route) import Url exposing (Url) @@ -69,7 +70,7 @@ init : Env -> Route -> ( Model, Cmd Msg ) init env route = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl env + Env.toCodeConfig LocalApi.codebaseApiEndpointToEndpointUrl env ( workspace, workspaceCmd ) = case route of @@ -85,7 +86,7 @@ init env route = fetchNamespaceDetailsCmd = env.perspective |> fetchNamespaceDetails - |> Maybe.map (Api.perform env.apiBasePath) + |> Maybe.map (HttpApi.perform env.apiBasePath) |> Maybe.withDefault Cmd.none model = @@ -134,7 +135,7 @@ update : Msg -> Model -> ( Model, Cmd Msg ) update msg ({ env } as model) = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl env + Env.toCodeConfig LocalApi.codebaseApiEndpointToEndpointUrl env in case msg of LinkClicked urlRequest -> @@ -162,7 +163,7 @@ update msg ({ env } as model) = Route.Definition params ref -> let codebaseConfig_ = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl (newEnv params) + Env.toCodeConfig LocalApi.codebaseApiEndpointToEndpointUrl (newEnv params) ( workspace, cmd ) = Workspace.open codebaseConfig_ model.workspace ref @@ -338,7 +339,7 @@ fetchPerspectiveAndCodebaseTree : Perspective -> Model -> ( Model, Cmd Msg ) fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl model.env + Env.toCodeConfig LocalApi.codebaseApiEndpointToEndpointUrl model.env ( codebaseTree, codebaseTreeCmd ) = CodebaseTree.init codebaseConfig @@ -346,7 +347,7 @@ fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) = fetchNamespaceDetailsCmd = env.perspective |> fetchNamespaceDetails - |> Maybe.map (Api.perform env.apiBasePath) + |> Maybe.map (HttpApi.perform env.apiBasePath) |> Maybe.withDefault Cmd.none in if Perspective.needsFetching env.perspective then @@ -425,7 +426,7 @@ showFinder : showFinder model withinNamespace = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl model.env + Env.toCodeConfig LocalApi.codebaseApiEndpointToEndpointUrl model.env options = SearchOptions.init model.env.perspective withinNamespace @@ -440,13 +441,13 @@ showFinder model withinNamespace = -- EFFECTS -fetchNamespaceDetails : Perspective -> Maybe (Api.ApiRequest NamespaceDetails Msg) +fetchNamespaceDetails : Perspective -> Maybe (HttpApi.ApiRequest NamespaceDetails Msg) fetchNamespaceDetails perspective = case perspective of Namespace { fqn } -> fqn - |> Api.namespace perspective - |> Api.toRequest Namespace.decodeDetails (FetchPerspectiveNamespaceDetailsFinished fqn) + |> LocalApi.namespace perspective + |> HttpApi.toRequest Namespace.decodeDetails (FetchPerspectiveNamespaceDetailsFinished fqn) |> Just _ -> diff --git a/src/UnisonLocal/PreApp.elm b/src/UnisonLocal/PreApp.elm index 838af1e..13287bd 100644 --- a/src/UnisonLocal/PreApp.elm +++ b/src/UnisonLocal/PreApp.elm @@ -1,12 +1,13 @@ module UnisonLocal.PreApp exposing (..) -import Api exposing (ApiBasePath(..), ApiRequest) import Browser import Browser.Navigation as Nav import Code.Perspective as Perspective exposing (Perspective, PerspectiveParams) import Env exposing (Flags) import Html import Http +import Lib.Api as HttpApi exposing (ApiBasePath(..), ApiRequest) +import UnisonLocal.Api as LocalApi import UnisonLocal.App as App import UnisonLocal.Route as Route exposing (Route) import Url exposing (Url) @@ -50,7 +51,7 @@ init flags url navKey = ( Initialized app, Cmd.map AppMsg cmd ) fetchPerspective_ = - ( Initializing preEnv, Api.perform (ApiBasePath flags.apiBasePath) (fetchPerspective preEnv) ) + ( Initializing preEnv, HttpApi.perform (ApiBasePath flags.apiBasePath) (fetchPerspective preEnv) ) in -- If we have a codebase hash we can construct a full perspective, -- otherwise we have to fetch the hash before being able to start up the @@ -63,7 +64,7 @@ init flags url navKey = fetchPerspective : PreEnv -> ApiRequest Perspective Msg fetchPerspective preEnv = - Api.codebaseHash |> Api.toRequest (Perspective.decode preEnv.perspectiveParams) (FetchPerspectiveFinished preEnv) + LocalApi.codebaseHash |> HttpApi.toRequest (Perspective.decode preEnv.perspectiveParams) (FetchPerspectiveFinished preEnv) type Msg diff --git a/src/UnisonShare/Api.elm b/src/UnisonShare/Api.elm new file mode 100644 index 0000000..68eb044 --- /dev/null +++ b/src/UnisonShare/Api.elm @@ -0,0 +1,124 @@ +module UnisonShare.Api exposing + ( catalog + , codebaseApiEndpointToEndpointUrl + , codebaseHash + , namespace + , projects + ) + +import Code.CodebaseApi as CodebaseApi +import Code.EntityId as EntityId +import Code.FullyQualifiedName as FQN exposing (FQN) +import Code.Hash as Hash exposing (Hash) +import Code.Perspective as Perspective exposing (Perspective(..)) +import Code.Syntax as Syntax +import Lib.Api as Api exposing (EndpointUrl(..)) +import Regex +import Url.Builder exposing (QueryParameter, int, string) + + +codebaseHash : EndpointUrl +codebaseHash = + EndpointUrl [ "list" ] [ string "namespace" "." ] + + +namespace : Perspective -> FQN -> EndpointUrl +namespace perspective fqn = + let + queryParams = + [ rootBranch (Perspective.codebaseHash perspective) ] + in + EndpointUrl [ "namespaces", FQN.toString fqn ] queryParams + + +projects : Maybe String -> EndpointUrl +projects owner = + let + queryParams = + case owner of + Just owner_ -> + [ string "owner" owner_ ] + + Nothing -> + [] + in + EndpointUrl [ "projects" ] queryParams + + +catalog : Api.EndpointUrl +catalog = + [ "_catalog" ] + |> List.map (string "names") + |> (\names -> Api.EndpointUrl [ "getDefinition" ] names) + + +codebaseApiEndpointToEndpointUrl : CodebaseApi.CodebaseEndpoint -> EndpointUrl +codebaseApiEndpointToEndpointUrl cbEndpoint = + case cbEndpoint of + CodebaseApi.Find { perspective, withinFqn, limit, sourceWidth, query } -> + let + params = + case withinFqn of + Just fqn -> + [ rootBranch (Perspective.codebaseHash perspective), relativeTo fqn ] + + Nothing -> + perspectiveToQueryParams perspective + + width = + case sourceWidth of + Syntax.Width w -> + w + in + EndpointUrl + [ "find" ] + ([ int "limit" limit + , int "renderWidth" width + , string "query" query + ] + ++ params + ) + + CodebaseApi.Browse { perspective, namespaceId } -> + let + namespace_ = + namespaceId |> Maybe.map EntityId.toString |> Maybe.withDefault "." + in + EndpointUrl [ "list" ] (string "namespace" namespace_ :: perspectiveToQueryParams perspective) + + CodebaseApi.Definition { perspective, definitionId } -> + let + re = + Maybe.withDefault Regex.never (Regex.fromString "#[d|a|](\\d+)$") + + stripConstructorPositionFromHash = + Regex.replace re (always "") + in + [ EntityId.toString definitionId ] + |> List.map stripConstructorPositionFromHash + |> List.map (string "names") + |> (\names -> EndpointUrl [ "getDefinition" ] (names ++ perspectiveToQueryParams perspective)) + + + +-- QUERY PARAMS --------------------------------------------------------------- + + +perspectiveToQueryParams : Perspective -> List QueryParameter +perspectiveToQueryParams perspective = + case perspective of + Codebase h -> + [ rootBranch h ] + + Namespace d -> + [ rootBranch d.codebaseHash, relativeTo d.fqn ] + + +rootBranch : Hash -> QueryParameter +rootBranch hash = + string "rootBranch" (hash |> Hash.toString) + + +relativeTo : FQN -> QueryParameter +relativeTo fqn = + string "relativeTo" (fqn |> FQN.toString) diff --git a/src/UnisonShare/App.elm b/src/UnisonShare/App.elm index 09da5ff..bb0cc22 100644 --- a/src/UnisonShare/App.elm +++ b/src/UnisonShare/App.elm @@ -1,6 +1,5 @@ module UnisonShare.App exposing (..) -import Api import Browser import Browser.Navigation as Nav import Code.CodebaseTree as CodebaseTree @@ -16,6 +15,7 @@ import Html exposing (Html, a, div, h1, h2, nav, p, span, text) import Html.Attributes exposing (class, classList, id, title) import Html.Events exposing (onClick) import Http +import Lib.Api as Api import Lib.Util as Util import RemoteData exposing (RemoteData(..)) import UI @@ -30,6 +30,7 @@ import UI.KeyboardShortcut.KeyboardEvent as KeyboardEvent exposing (KeyboardEven import UI.PageLayout as PageLayout import UI.Sidebar as Sidebar import UI.Tooltip as Tooltip +import UnisonShare.Api as ShareApi import UnisonShare.AppModal as AppModal import UnisonShare.Page.CatalogPage as CatalogPage import UnisonShare.Page.UserPage as UserPage @@ -63,7 +64,7 @@ init : Env -> Route -> ( Model, Cmd Msg ) init env route = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl env + Env.toCodeConfig ShareApi.codebaseApiEndpointToEndpointUrl env -- TODO: This whole thing should be route driven ( workspace, workspaceCmd ) = @@ -150,7 +151,7 @@ update : Msg -> Model -> ( Model, Cmd Msg ) update msg ({ env } as model) = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl env + Env.toCodeConfig ShareApi.codebaseApiEndpointToEndpointUrl env in case ( model.route, msg ) of ( _, LinkClicked urlRequest ) -> @@ -192,7 +193,7 @@ update msg ({ env } as model) = Route.Project params (Route.ProjectDefinition ref) -> let codebaseConfig_ = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl (newEnv params) + Env.toCodeConfig ShareApi.codebaseApiEndpointToEndpointUrl (newEnv params) ( workspace, cmd ) = Workspace.open codebaseConfig_ model.workspace ref @@ -381,7 +382,7 @@ fetchPerspectiveAndCodebaseTree : Perspective -> Model -> ( Model, Cmd Msg ) fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) = let codebaseConfig = - Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl model.env + Env.toCodeConfig ShareApi.codebaseApiEndpointToEndpointUrl model.env ( codebaseTree, codebaseTreeCmd ) = CodebaseTree.init codebaseConfig @@ -484,7 +485,7 @@ fetchNamespaceDetails perspective = case perspective of Namespace { fqn } -> fqn - |> Api.namespace perspective + |> ShareApi.namespace perspective |> Api.toRequest Namespace.decodeDetails (FetchPerspectiveNamespaceDetailsFinished fqn) |> Just diff --git a/src/UnisonShare/AppModal.elm b/src/UnisonShare/AppModal.elm index 42d6dcb..b28cfcc 100644 --- a/src/UnisonShare/AppModal.elm +++ b/src/UnisonShare/AppModal.elm @@ -1,6 +1,5 @@ module UnisonShare.AppModal exposing (..) -import Api import Code.Definition.Reference exposing (Reference) import Code.Finder as Finder import Code.Finder.SearchOptions as SearchOptions @@ -15,6 +14,7 @@ import UI.CopyField as CopyField import UI.KeyboardShortcut as KeyboardShortcut import UI.KeyboardShortcut.Key as Key exposing (Key(..)) import UI.Modal as Modal +import UnisonShare.Api as Api diff --git a/src/UnisonShare/Page/CatalogPage.elm b/src/UnisonShare/Page/CatalogPage.elm index 9a8601d..3f15c70 100644 --- a/src/UnisonShare/Page/CatalogPage.elm +++ b/src/UnisonShare/Page/CatalogPage.elm @@ -1,6 +1,5 @@ module UnisonShare.Page.CatalogPage exposing (..) -import Api import Code.Perspective as Perspective import Code.Project as Project exposing (ProjectListing) import Env exposing (Env) @@ -8,6 +7,7 @@ import Html exposing (Html, div, h1, input, strong, table, tbody, td, text, tr) import Html.Attributes exposing (autofocus, class, classList, placeholder) import Html.Events exposing (onBlur, onFocus, onInput, onMouseDown) import Http +import Lib.Api as Api import Lib.SearchResults as SearchResults exposing (SearchResults(..)) import List.Extra as ListE import Maybe.Extra as MaybeE @@ -22,6 +22,7 @@ import UI.KeyboardShortcut as KeyboardShortcut exposing (KeyboardShortcut(..)) import UI.KeyboardShortcut.Key as Key exposing (Key(..)) import UI.KeyboardShortcut.KeyboardEvent as KeyboardEvent exposing (KeyboardEvent) import UI.PageLayout as PageLayout exposing (PageLayout) +import UnisonShare.Api as ShareApi import UnisonShare.Catalog as Catalog exposing (Catalog) import UnisonShare.Catalog.CatalogMask exposing (CatalogMask) import UnisonShare.Route as Route @@ -73,15 +74,11 @@ projectListings and finally merging them into a Catalog -} fetch : Env -> Cmd Msg fetch env = - let - perspective = - Perspective.toCodebasePerspective env.perspective - in - Api.getDefinition perspective [ "_catalog" ] + ShareApi.catalog |> Api.toTask env.apiBasePath Catalog.decodeCatalogMask |> Task.andThen (\catalog -> - Api.projects Nothing + ShareApi.projects Nothing |> Api.toTask env.apiBasePath Project.decodeListings |> Task.map (\projects -> ( catalog, projects )) ) diff --git a/src/UnisonShare/Page/UserPage.elm b/src/UnisonShare/Page/UserPage.elm index ff2f1ff..53c6bf8 100644 --- a/src/UnisonShare/Page/UserPage.elm +++ b/src/UnisonShare/Page/UserPage.elm @@ -1,6 +1,5 @@ module UnisonShare.Page.UserPage exposing (..) -import Api import Code.Definition.Doc as Doc import Code.Definition.Readme as Readme import Code.Definition.Reference exposing (Reference) @@ -11,12 +10,14 @@ import Env exposing (Env) import Html exposing (Html, div, h1, text) import Html.Attributes exposing (class) import Http +import Lib.Api as Api import RemoteData exposing (RemoteData(..), WebData) import Task import UI import UI.Card as Card import UI.Click as Click import UI.PageLayout as PageLayout exposing (PageLayout) +import UnisonShare.Api as ShareApi import UnisonShare.Route as Route import UnisonShare.User as User exposing (UserDetails, Username) @@ -53,11 +54,11 @@ fetchUser env username = usernameFqn = username |> User.usernameToString |> FQN.fromString in - Api.namespace perspective usernameFqn + ShareApi.namespace perspective usernameFqn |> Api.toTask env.apiBasePath User.decodeDetails |> Task.andThen (\userDetails -> - Api.projects (username |> User.usernameToString |> Just) + ShareApi.projects (username |> User.usernameToString |> Just) |> Api.toTask env.apiBasePath Project.decodeListings |> Task.map (\projects -> ( userDetails, projects )) ) diff --git a/src/UnisonShare/PreApp.elm b/src/UnisonShare/PreApp.elm index e993f7b..376359c 100644 --- a/src/UnisonShare/PreApp.elm +++ b/src/UnisonShare/PreApp.elm @@ -1,12 +1,13 @@ module UnisonShare.PreApp exposing (..) -import Api exposing (ApiBasePath(..), ApiRequest) import Browser import Browser.Navigation as Nav import Code.Perspective as Perspective exposing (Perspective, PerspectiveParams) import Env exposing (Flags) import Html import Http +import Lib.Api as Api exposing (ApiBasePath(..), ApiRequest) +import UnisonShare.Api as ShareApi import UnisonShare.App as App import UnisonShare.Route as Route exposing (Route) import Url exposing (Url) @@ -68,7 +69,7 @@ init flags url navKey = fetchPerspective : PreEnv -> ApiRequest Perspective Msg fetchPerspective preEnv = - Api.codebaseHash |> Api.toRequest (Perspective.decode preEnv.perspectiveParams) (FetchPerspectiveFinished preEnv) + ShareApi.codebaseHash |> Api.toRequest (Perspective.decode preEnv.perspectiveParams) (FetchPerspectiveFinished preEnv) type Msg