diff --git a/examples/docs/src/Site.elm b/examples/docs/src/Site.elm index fd7e2c7f..523797af 100644 --- a/examples/docs/src/Site.elm +++ b/examples/docs/src/Site.elm @@ -1,6 +1,6 @@ module Site exposing (config) -import ApiHandler +import ApiRoute import Cloudinary import DataSource exposing (DataSource) import DataSource.Http @@ -28,9 +28,9 @@ config = } -files : List (Maybe Route) -> List (ApiHandler.Done ApiHandler.Response) +files : List (Maybe Route) -> List (ApiRoute.Done ApiRoute.Response) files allRoutes = - [ ApiHandler.succeed + [ ApiRoute.succeed (\userId -> DataSource.succeed { body = @@ -41,11 +41,11 @@ files allRoutes = |> Json.Encode.encode 2 } ) - |> ApiHandler.literal "users" - |> ApiHandler.slash - |> ApiHandler.capture - |> ApiHandler.literal ".json" - |> ApiHandler.buildTimeRoutes + |> ApiRoute.literal "users" + |> ApiRoute.slash + |> ApiRoute.capture + |> ApiRoute.literal ".json" + |> ApiRoute.buildTimeRoutes (\constructor -> DataSource.succeed [ constructor "1" @@ -53,7 +53,7 @@ files allRoutes = , constructor "3" ] ) - , ApiHandler.succeed + , ApiRoute.succeed (\repoName -> DataSource.Http.get (Secrets.succeed ("https://api.github.com/repos/dillonkearns/" ++ repoName)) @@ -69,17 +69,17 @@ files allRoutes = } ) ) - |> ApiHandler.literal "repo" - |> ApiHandler.slash - |> ApiHandler.capture - |> ApiHandler.literal ".json" - |> ApiHandler.buildTimeRoutes + |> ApiRoute.literal "repo" + |> ApiRoute.slash + |> ApiRoute.capture + |> ApiRoute.literal ".json" + |> ApiRoute.buildTimeRoutes (\constructor -> DataSource.succeed [ constructor "elm-graphql" ] ) - , ApiHandler.succeed + , ApiRoute.succeed (DataSource.succeed { body = allRoutes @@ -93,8 +93,8 @@ files allRoutes = |> Sitemap.build { siteUrl = "https://elm-pages.com" } } ) - |> ApiHandler.literal "sitemap.xml" - |> ApiHandler.singleRoute + |> ApiRoute.literal "sitemap.xml" + |> ApiRoute.singleRoute ] diff --git a/src/ApiHandler.elm b/src/ApiRoute.elm similarity index 99% rename from src/ApiHandler.elm rename to src/ApiRoute.elm index 0d535872..794f6926 100644 --- a/src/ApiHandler.elm +++ b/src/ApiRoute.elm @@ -1,4 +1,4 @@ -module ApiHandler exposing (..) +module ApiRoute exposing (..) import DataSource exposing (DataSource) import Regex exposing (Regex) diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index e678ecb1..e971af01 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -8,7 +8,7 @@ module Pages.Internal.Platform.Cli exposing , update ) -import ApiHandler +import ApiRoute import BuildError exposing (BuildError) import Codec import DataSource exposing (DataSource) @@ -755,7 +755,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt case requestPayload of RenderRequest.Api ( path, apiHandler ) -> let - thing : DataSource (Maybe ApiHandler.Response) + thing : DataSource (Maybe ApiRoute.Response) thing = apiHandler.matchesToResponse path in @@ -814,7 +814,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt case requestPayload of RenderRequest.Api ( path, apiHandler ) -> let - thing : DataSource (Maybe ApiHandler.Response) + thing : DataSource (Maybe ApiRoute.Response) thing = apiHandler.matchesToResponse path in diff --git a/src/Pages/Internal/Platform/StaticResponses.elm b/src/Pages/Internal/Platform/StaticResponses.elm index 94d14b99..5cf957d3 100644 --- a/src/Pages/Internal/Platform/StaticResponses.elm +++ b/src/Pages/Internal/Platform/StaticResponses.elm @@ -1,6 +1,6 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), StaticResponses, error, init, nextStep, renderApiRequest, renderSingleRoute, update) -import ApiHandler +import ApiRoute import BuildError exposing (BuildError) import DataSource exposing (DataSource) import DataSource.Http exposing (RequestDetails) diff --git a/src/Pages/SiteConfig.elm b/src/Pages/SiteConfig.elm index d32d87c7..178d44d8 100644 --- a/src/Pages/SiteConfig.elm +++ b/src/Pages/SiteConfig.elm @@ -1,6 +1,6 @@ module Pages.SiteConfig exposing (SiteConfig) -import ApiHandler +import ApiRoute import DataSource exposing (DataSource) import Head import Pages.Manifest @@ -12,7 +12,7 @@ type alias SiteConfig route data = { data : DataSource data , canonicalUrl : String , manifest : data -> Pages.Manifest.Config - , apiRoutes : List (ApiHandler.Done ApiHandler.Response) + , apiRoutes : List (ApiRoute.Done ApiRoute.Response) , head : data -> List Head.Tag diff --git a/src/RenderRequest.elm b/src/RenderRequest.elm index d3f24b1b..ff5c8656 100644 --- a/src/RenderRequest.elm +++ b/src/RenderRequest.elm @@ -1,6 +1,6 @@ module RenderRequest exposing (..) -import ApiHandler +import ApiRoute import DataSource exposing (DataSource) import Json.Decode as Decode import Json.Encode @@ -12,7 +12,7 @@ import Url exposing (Url) type RequestPayload route = Page { path : PagePath, frontmatter : route } - | Api ( String, ApiHandler.Done ApiHandler.Response ) + | Api ( String, ApiRoute.Done ApiRoute.Response ) | NotFound @@ -106,9 +106,9 @@ requestPayloadDecoder config = route = pathToUrl path |> config.urlToRoute - apiRoute : Maybe (ApiHandler.Done ApiHandler.Response) + apiRoute : Maybe (ApiRoute.Done ApiRoute.Response) apiRoute = - ApiHandler.firstMatch (String.dropLeft 1 path) + ApiRoute.firstMatch (String.dropLeft 1 path) (manifestHandler config :: site.apiRoutes ) @@ -136,9 +136,9 @@ requestPayloadDecoder config = |> Decode.field "payload" -manifestHandler : ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData -> ApiHandler.Done ApiHandler.Response +manifestHandler : ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData -> ApiRoute.Done ApiRoute.Response manifestHandler config = - ApiHandler.succeed + ApiRoute.succeed (config.getStaticRoutes |> DataSource.andThen (\resolvedRoutes -> @@ -151,8 +151,8 @@ manifestHandler config = ) ) ) - |> ApiHandler.literal "manifest.json" - |> ApiHandler.singleRoute + |> ApiRoute.literal "manifest.json" + |> ApiRoute.singleRoute manifestToFile : String -> Manifest.Config -> { body : String } diff --git a/tests/ApiHandlerTests.elm b/tests/ApiRouteTests.elm similarity index 98% rename from tests/ApiHandlerTests.elm rename to tests/ApiRouteTests.elm index 5acf9850..58f29668 100644 --- a/tests/ApiHandlerTests.elm +++ b/tests/ApiRouteTests.elm @@ -1,6 +1,6 @@ -module ApiHandlerTests exposing (..) +module ApiRouteTests exposing (..) -import ApiHandler exposing (..) +import ApiRoute exposing (..) import Expect import Test exposing (describe, only, test) diff --git a/tests/StaticHttpRequestsTests.elm b/tests/StaticHttpRequestsTests.elm index e910bb5e..76941b14 100644 --- a/tests/StaticHttpRequestsTests.elm +++ b/tests/StaticHttpRequestsTests.elm @@ -1,6 +1,6 @@ module StaticHttpRequestsTests exposing (all) -import ApiHandler +import ApiRoute import Codec import DataSource import DataSource.Http @@ -693,7 +693,7 @@ Payload sent back invalid JSON""") [ test "initial requests are sent out" <| \() -> startLowLevel - [ ApiHandler.succeed + [ ApiRoute.succeed (DataSource.Http.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages") (starDecoder |> Decode.map @@ -703,8 +703,8 @@ Payload sent back invalid JSON""") ) ) ) - |> ApiHandler.literal "test.txt" - |> ApiHandler.singleRoute + |> ApiRoute.literal "test.txt" + |> ApiRoute.singleRoute ] (Ok ()) [] @@ -726,7 +726,7 @@ Payload sent back invalid JSON""") , test "it sends success port when no HTTP requests are needed because they're all cached" <| \() -> startLowLevel - [ ApiHandler.succeed + [ ApiRoute.succeed (DataSource.Http.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages-starter") (starDecoder |> Decode.map @@ -736,8 +736,8 @@ Payload sent back invalid JSON""") ) ) ) - |> ApiHandler.literal "test.txt" - |> ApiHandler.singleRoute + |> ApiRoute.literal "test.txt" + |> ApiRoute.singleRoute ] (Ok ()) [ ( { url = "https://api.github.com/repos/dillonkearns/elm-pages" @@ -798,7 +798,7 @@ startWithHttpCache = startLowLevel : - List (ApiHandler.Done ApiHandler.Response) + List (ApiRoute.Done ApiRoute.Response) -> Result String () -> List ( Request.Request, String ) -> List ( List String, DataSource.DataSource a )