From da1ca86caf2a5a7a47d1ec7c79fa55a136868e79 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Fri, 4 Feb 2022 10:25:49 -0800 Subject: [PATCH] Delete obsolete type. --- src/DataSource.elm | 31 +++++------ src/DataSource/Http.elm | 4 +- src/Pages/Internal/ApplicationType.elm | 5 -- src/Pages/Internal/Platform/Cli.elm | 21 ++++---- .../Internal/Platform/StaticResponses.elm | 13 ++--- src/Pages/StaticHttpRequest.elm | 53 +++++++++---------- 6 files changed, 55 insertions(+), 72 deletions(-) delete mode 100644 src/Pages/Internal/ApplicationType.elm diff --git a/src/DataSource.elm b/src/DataSource.elm index 55521466..254941f5 100644 --- a/src/DataSource.elm +++ b/src/DataSource.elm @@ -83,7 +83,6 @@ So it's best to use that mental model to avoid confusion. -} -import Pages.Internal.ApplicationType exposing (ApplicationType) import Pages.Internal.StaticHttpBody as Body import Pages.StaticHttp.Request as HashRequest import Pages.StaticHttpRequest exposing (RawRequest(..)) @@ -132,8 +131,8 @@ map fn requestInfo = Request partiallyStripped ( urls, lookupFn ) -> Request partiallyStripped ( urls - , \appType rawResponses -> - map fn (lookupFn appType rawResponses) + , \rawResponses -> + map fn (lookupFn rawResponses) ) ApiRoute stripped value -> @@ -222,28 +221,28 @@ map2 fn request1 request2 = ( Request newDict1 ( urls1, lookupFn1 ), Request newDict2 ( urls2, lookupFn2 ) ) -> Request (combineReducedDicts newDict1 newDict2) ( urls1 ++ urls2 - , \appType rawResponses -> + , \rawResponses -> map2 fn - (lookupFn1 appType rawResponses) - (lookupFn2 appType rawResponses) + (lookupFn1 rawResponses) + (lookupFn2 rawResponses) ) ( Request dict1 ( urls1, lookupFn1 ), ApiRoute stripped2 value2 ) -> Request dict1 ( urls1 - , \appType rawResponses -> + , \rawResponses -> map2 fn - (lookupFn1 appType rawResponses) + (lookupFn1 rawResponses) (ApiRoute stripped2 value2) ) ( ApiRoute stripped2 value2, Request dict1 ( urls1, lookupFn1 ) ) -> Request dict1 ( urls1 - , \appType rawResponses -> + , \rawResponses -> map2 fn (ApiRoute stripped2 value2) - (lookupFn1 appType rawResponses) + (lookupFn1 rawResponses) ) ( ApiRoute stripped1 value1, ApiRoute stripped2 value2 ) -> @@ -261,21 +260,20 @@ combineReducedDicts dict1 dict2 = Set.union dict1 dict2 -lookup : ApplicationType -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Set String, value ) +lookup : DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Set String, value ) lookup = lookupHelp Set.empty -lookupHelp : Set String -> ApplicationType -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Set String, value ) -lookupHelp strippedSoFar appType requestInfo rawResponses = +lookupHelp : Set String -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error ( Set String, value ) +lookupHelp strippedSoFar requestInfo rawResponses = case requestInfo of RequestError error -> Err error Request strippedResponses ( urls, lookupFn ) -> lookupHelp (combineReducedDicts strippedResponses strippedSoFar) - appType - (addUrls urls (lookupFn appType rawResponses)) + (addUrls urls (lookupFn rawResponses)) rawResponses ApiRoute stripped value -> @@ -341,9 +339,8 @@ andThen fn requestInfo = -- TODO should this be non-empty Dict? Or should it be passed down some other way? Request Set.empty ( lookupUrls requestInfo - , \appType rawResponses -> + , \rawResponses -> lookup - appType requestInfo rawResponses |> (\result -> diff --git a/src/DataSource/Http.elm b/src/DataSource/Http.elm index aaab7edb..e1a8ee0d 100644 --- a/src/DataSource/Http.elm +++ b/src/DataSource/Http.elm @@ -209,7 +209,7 @@ request request_ expect = ExpectJson decoder -> Request Set.empty ( [ request_ ] - , \_ rawResponseDict -> + , \rawResponseDict -> rawResponseDict |> RequestsAndPending.get (request_ |> HashRequest.hash) |> (\maybeResponse -> @@ -257,7 +257,7 @@ request request_ expect = ExpectString mapStringFn -> Request Set.empty ( [ request_ ] - , \_ rawResponseDict -> + , \rawResponseDict -> rawResponseDict |> RequestsAndPending.get (request_ |> HashRequest.hash) |> (\maybeResponse -> diff --git a/src/Pages/Internal/ApplicationType.elm b/src/Pages/Internal/ApplicationType.elm deleted file mode 100644 index cc0e8106..00000000 --- a/src/Pages/Internal/ApplicationType.elm +++ /dev/null @@ -1,5 +0,0 @@ -module Pages.Internal.ApplicationType exposing (ApplicationType(..)) - - -type ApplicationType - = Cli diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index 7965a784..c0eb7b9a 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -24,7 +24,6 @@ import Json.Encode import PageServerResponse exposing (PageServerResponse) import Pages.Flags import Pages.Http -import Pages.Internal.ApplicationType as ApplicationType import Pages.Internal.NotFoundReason exposing (NotFoundReason) import Pages.Internal.Platform.Effect as Effect exposing (Effect) import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses) @@ -652,7 +651,7 @@ nextStepToEffect site config model ( updatedStaticResponsesModel, nextStep ) = thing = apiHandler.matchesToResponse path in - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve thing model.allRawResponses |> Result.mapError (StaticHttpRequest.toBuildError "TODO - path from request") @@ -684,7 +683,7 @@ nextStepToEffect site config model ( updatedStaticResponsesModel, nextStep ) = let pageFoundResult : Result BuildError (Maybe NotFoundReason) pageFoundResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve (if model.isDevServer then config.handleRoute payload.frontmatter @@ -717,21 +716,21 @@ nextStepToEffect site config model ( updatedStaticResponsesModel, nextStep ) = pageDataResult : Result BuildError (PageServerResponse pageData) pageDataResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve (config.data (config.urlToRoute currentUrl)) (staticData |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError currentUrl.path) sharedDataResult : Result BuildError sharedData sharedDataResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve config.sharedData (staticData |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError currentUrl.path) siteDataResult : Result BuildError siteData siteDataResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve site.data (staticData |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError "Site.elm") @@ -884,7 +883,7 @@ nextStepToEffect site config model ( updatedStaticResponsesModel, nextStep ) = routeResult |> Result.andThen (\route -> - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve (config.data route) (contentJson |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError "TODO url") @@ -914,7 +913,7 @@ sendSinglePageProgress site contentJson config model = let pageFoundResult : Result BuildError (Maybe NotFoundReason) pageFoundResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve (if model.isDevServer then config.handleRoute route @@ -992,21 +991,21 @@ sendSinglePageProgress site contentJson config model = pageDataResult : Result BuildError (PageServerResponse pageData) pageDataResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve (config.data (config.urlToRoute currentUrl)) (contentJson |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError currentUrl.path) sharedDataResult : Result BuildError sharedData sharedDataResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve config.sharedData (contentJson |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError currentUrl.path) siteDataResult : Result BuildError siteData siteDataResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve site.data (contentJson |> Dict.map (\_ v -> Just v)) |> Result.mapError (StaticHttpRequest.toBuildError "Site.elm") diff --git a/src/Pages/Internal/Platform/StaticResponses.elm b/src/Pages/Internal/Platform/StaticResponses.elm index 18638c5b..eab6f43d 100644 --- a/src/Pages/Internal/Platform/StaticResponses.elm +++ b/src/Pages/Internal/Platform/StaticResponses.elm @@ -10,7 +10,6 @@ import Html exposing (Html) import HtmlPrinter exposing (htmlToString) import Internal.ApiRoute exposing (ApiRoute(..)) import Json.Encode -import Pages.Internal.ApplicationType as ApplicationType import Pages.Internal.NotFoundReason exposing (NotFoundReason) import Pages.SiteConfig exposing (SiteConfig) import Pages.StaticHttp.Request as HashRequest @@ -157,7 +156,7 @@ encode requestsAndPending staticResponses = |> Dict.toList |> List.map (\( key, NotFetched request _ ) -> - StaticHttpRequest.strippedResponsesEncode ApplicationType.Cli request requestsAndPending + StaticHttpRequest.strippedResponsesEncode request requestsAndPending |> Result.map (Tuple.pair key) ) |> combineMultipleErrors @@ -223,7 +222,7 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = staticRequestsStatus : StaticHttpRequest.Status () staticRequestsStatus = allRawResponses - |> StaticHttpRequest.cacheRequestResolution ApplicationType.Cli request + |> StaticHttpRequest.cacheRequestResolution request hasPermanentError : Bool hasPermanentError = @@ -359,7 +358,6 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = staticRequestsStatus : StaticHttpRequest.Status () staticRequestsStatus = StaticHttpRequest.cacheRequestResolution - ApplicationType.Cli request usableRawResponses @@ -395,7 +393,7 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = resolvedGenerateFilesResult : Result StaticHttpRequest.Error (List (Result String { path : List String, content : String })) resolvedGenerateFilesResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve (buildTimeFilesRequest config) (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value)) in @@ -449,7 +447,7 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = let pageFoundResult : Result StaticHttpRequest.Error (Maybe NotFoundReason) pageFoundResult = - StaticHttpRequest.resolve ApplicationType.Cli + StaticHttpRequest.resolve pageFoundDataSource (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value)) in @@ -475,7 +473,6 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = staticRequestsStatus : StaticHttpRequest.Status () staticRequestsStatus = StaticHttpRequest.cacheRequestResolution - ApplicationType.Cli request usableRawResponses @@ -526,7 +523,7 @@ performStaticHttpRequests allRawResponses staticRequests = -- TODO look for performance bottleneck in this double nesting |> List.map (\( _, request ) -> - StaticHttpRequest.resolveUrls ApplicationType.Cli request allRawResponses + StaticHttpRequest.resolveUrls request allRawResponses ) -- TODO prevent duplicates... can't because Set needs comparable -- |> Set.fromList diff --git a/src/Pages/StaticHttpRequest.elm b/src/Pages/StaticHttpRequest.elm index f5481544..a5f6fbd9 100644 --- a/src/Pages/StaticHttpRequest.elm +++ b/src/Pages/StaticHttpRequest.elm @@ -3,7 +3,6 @@ module Pages.StaticHttpRequest exposing (Error(..), RawRequest(..), Status(..), import BuildError exposing (BuildError) import Dict exposing (Dict) import List.Extra -import Pages.Internal.ApplicationType exposing (ApplicationType) import Pages.StaticHttp.Request import RequestsAndPending exposing (RequestsAndPending) import Set exposing (Set) @@ -11,19 +10,19 @@ import TerminalText as Terminal type RawRequest value - = Request (Set String) ( List Pages.StaticHttp.Request.Request, ApplicationType -> RequestsAndPending -> RawRequest value ) + = Request (Set String) ( List Pages.StaticHttp.Request.Request, RequestsAndPending -> RawRequest value ) | RequestError Error | ApiRoute (Set String) value -strippedResponses : ApplicationType -> RawRequest value -> RequestsAndPending -> Set String +strippedResponses : RawRequest value -> RequestsAndPending -> Set String strippedResponses = strippedResponsesHelp Set.empty -strippedResponsesEncode : ApplicationType -> RawRequest value -> RequestsAndPending -> Result (List BuildError) (Dict String String) -strippedResponsesEncode appType rawRequest requestsAndPending = - strippedResponses appType rawRequest requestsAndPending +strippedResponsesEncode : RawRequest value -> RequestsAndPending -> Result (List BuildError) (Dict String String) +strippedResponsesEncode rawRequest requestsAndPending = + strippedResponses rawRequest requestsAndPending |> Set.toList |> List.map (\k -> @@ -65,21 +64,20 @@ combineMultipleErrors results = results -strippedResponsesHelp : Set String -> ApplicationType -> RawRequest value -> RequestsAndPending -> Set String -strippedResponsesHelp usedSoFar appType request rawResponses = +strippedResponsesHelp : Set String -> RawRequest value -> RequestsAndPending -> Set String +strippedResponsesHelp usedSoFar request rawResponses = case request of RequestError _ -> usedSoFar Request partiallyStrippedResponses ( _, lookupFn ) -> - case lookupFn appType rawResponses of + case lookupFn rawResponses of followupRequest -> strippedResponsesHelp (Set.union usedSoFar partiallyStrippedResponses ) - appType followupRequest rawResponses @@ -126,28 +124,28 @@ toBuildError path error = } -resolve : ApplicationType -> RawRequest value -> RequestsAndPending -> Result Error value -resolve appType request rawResponses = +resolve : RawRequest value -> RequestsAndPending -> Result Error value +resolve request rawResponses = case request of RequestError error -> Err error Request _ ( _, lookupFn ) -> - case lookupFn appType rawResponses of + case lookupFn rawResponses of nextRequest -> - resolve appType nextRequest rawResponses + resolve nextRequest rawResponses ApiRoute _ value -> Ok value -resolveUrls : ApplicationType -> RawRequest value -> RequestsAndPending -> List Pages.StaticHttp.Request.Request -resolveUrls appType request rawResponses = - resolveUrlsHelp appType rawResponses [] request +resolveUrls : RawRequest value -> RequestsAndPending -> List Pages.StaticHttp.Request.Request +resolveUrls request rawResponses = + resolveUrlsHelp rawResponses [] request -resolveUrlsHelp : ApplicationType -> RequestsAndPending -> List Pages.StaticHttp.Request.Request -> RawRequest value -> List Pages.StaticHttp.Request.Request -resolveUrlsHelp appType rawResponses soFar request = +resolveUrlsHelp : RequestsAndPending -> List Pages.StaticHttp.Request.Request -> RawRequest value -> List Pages.StaticHttp.Request.Request +resolveUrlsHelp rawResponses soFar request = case request of RequestError error -> case error of @@ -159,22 +157,21 @@ resolveUrlsHelp appType rawResponses soFar request = soFar Request _ ( urlList, lookupFn ) -> - resolveUrlsHelp appType + resolveUrlsHelp rawResponses (soFar ++ urlList) - (lookupFn appType rawResponses) + (lookupFn rawResponses) ApiRoute _ _ -> soFar cacheRequestResolution : - ApplicationType - -> RawRequest value + RawRequest value -> RequestsAndPending -> Status value -cacheRequestResolution appType request rawResponses = - cacheRequestResolutionHelp [] appType rawResponses request +cacheRequestResolution request rawResponses = + cacheRequestResolutionHelp [] rawResponses request type Status value @@ -185,11 +182,10 @@ type Status value cacheRequestResolutionHelp : List Pages.StaticHttp.Request.Request - -> ApplicationType -> RequestsAndPending -> RawRequest value -> Status value -cacheRequestResolutionHelp foundUrls appType rawResponses request = +cacheRequestResolutionHelp foundUrls rawResponses request = case request of RequestError error -> case error of @@ -205,9 +201,8 @@ cacheRequestResolutionHelp foundUrls appType rawResponses request = Request _ ( urlList, lookupFn ) -> cacheRequestResolutionHelp urlList - appType rawResponses - (lookupFn appType rawResponses) + (lookupFn rawResponses) ApiRoute _ _ -> Complete