mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-03 17:51:46 +03:00
Make Throwable/Catchable exceptions.
This commit is contained in:
parent
d78a3ca91d
commit
c982947c7d
@ -665,7 +665,7 @@ otherFile routes phaseString =
|
|||||||
}
|
}
|
||||||
|> Elm.withType
|
|> Elm.withType
|
||||||
(Gen.DataSource.annotation_.dataSource
|
(Gen.DataSource.annotation_.dataSource
|
||||||
(Type.named [ "BuildError" ] "BuildError")
|
(Type.named [ "Exception" ] "Throwable")
|
||||||
(Gen.Server.Response.annotation_.response
|
(Gen.Server.Response.annotation_.response
|
||||||
(Type.named [] "PageData")
|
(Type.named [] "PageData")
|
||||||
(Type.named [ "ErrorPage" ] "ErrorPage")
|
(Type.named [ "ErrorPage" ] "ErrorPage")
|
||||||
@ -715,7 +715,7 @@ otherFile routes phaseString =
|
|||||||
}
|
}
|
||||||
|> Elm.withType
|
|> Elm.withType
|
||||||
(Gen.DataSource.annotation_.dataSource
|
(Gen.DataSource.annotation_.dataSource
|
||||||
(Type.named [ "BuildError" ] "BuildError")
|
(Type.named [ "Exception" ] "Throwable")
|
||||||
(Gen.Server.Response.annotation_.response
|
(Gen.Server.Response.annotation_.response
|
||||||
(Type.named [] "ActionData")
|
(Type.named [] "ActionData")
|
||||||
(Type.named [ "ErrorPage" ] "ErrorPage")
|
(Type.named [ "ErrorPage" ] "ErrorPage")
|
||||||
@ -1429,7 +1429,7 @@ otherFile routes phaseString =
|
|||||||
}
|
}
|
||||||
|> Elm.withType
|
|> Elm.withType
|
||||||
(Gen.DataSource.annotation_.dataSource
|
(Gen.DataSource.annotation_.dataSource
|
||||||
(Type.named [ "BuildError" ] "BuildError")
|
(Type.named [ "Exception" ] "Throwable")
|
||||||
(Type.maybe Gen.Pages.Internal.NotFoundReason.annotation_.notFoundReason)
|
(Type.maybe Gen.Pages.Internal.NotFoundReason.annotation_.notFoundReason)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1869,7 +1869,7 @@ otherFile routes phaseString =
|
|||||||
|> Gen.DataSource.call_.map Gen.List.values_.concat
|
|> Gen.DataSource.call_.map Gen.List.values_.concat
|
||||||
|> Elm.withType
|
|> Elm.withType
|
||||||
(Gen.DataSource.annotation_.dataSource
|
(Gen.DataSource.annotation_.dataSource
|
||||||
(Type.named [ "BuildError" ] "BuildError")
|
(Type.named [ "Exception" ] "Throwable")
|
||||||
(Type.list Gen.Head.annotation_.tag)
|
(Type.list Gen.Head.annotation_.tag)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1991,7 +1991,7 @@ otherFile routes phaseString =
|
|||||||
|> Gen.DataSource.call_.map Gen.List.values_.concat
|
|> Gen.DataSource.call_.map Gen.List.values_.concat
|
||||||
|> Elm.withType
|
|> Elm.withType
|
||||||
(Gen.DataSource.annotation_.dataSource
|
(Gen.DataSource.annotation_.dataSource
|
||||||
(Type.named [ "BuildError" ] "BuildError")
|
(Type.named [ "Exception" ] "Throwable")
|
||||||
(Type.list (Type.named [ "Route" ] "Route"))
|
(Type.list (Type.named [ "Route" ] "Route"))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -2,9 +2,9 @@ module Api exposing (routes)
|
|||||||
|
|
||||||
import ApiRoute
|
import ApiRoute
|
||||||
import Article
|
import Article
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Http
|
import DataSource.Http
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
@ -21,7 +21,7 @@ import Time
|
|||||||
|
|
||||||
|
|
||||||
routes :
|
routes :
|
||||||
DataSource BuildError (List Route)
|
DataSource Throwable (List Route)
|
||||||
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
|
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
|
||||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||||
routes getStaticRoutes htmlToString =
|
routes getStaticRoutes htmlToString =
|
||||||
@ -64,7 +64,7 @@ routes getStaticRoutes htmlToString =
|
|||||||
]
|
]
|
||||||
|> Json.Encode.encode 2
|
|> Json.Encode.encode 2
|
||||||
)
|
)
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
|> ApiRoute.literal "repo"
|
|> ApiRoute.literal "repo"
|
||||||
|> ApiRoute.slash
|
|> ApiRoute.slash
|
||||||
@ -105,7 +105,7 @@ routes getStaticRoutes htmlToString =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
postsDataSource : DataSource BuildError (List Rss.Item)
|
postsDataSource : DataSource Throwable (List Rss.Item)
|
||||||
postsDataSource =
|
postsDataSource =
|
||||||
Article.allMetadata
|
Article.allMetadata
|
||||||
|> DataSource.map
|
|> DataSource.map
|
||||||
@ -126,7 +126,7 @@ postsDataSource =
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|
|
||||||
|
|
||||||
rss :
|
rss :
|
||||||
@ -136,7 +136,7 @@ rss :
|
|||||||
, builtAt : Time.Posix
|
, builtAt : Time.Posix
|
||||||
, indexPage : List String
|
, indexPage : List String
|
||||||
}
|
}
|
||||||
-> DataSource BuildError (List Rss.Item)
|
-> DataSource Throwable (List Rss.Item)
|
||||||
-> ApiRoute.ApiRoute ApiRoute.Response
|
-> ApiRoute.ApiRoute ApiRoute.Response
|
||||||
rss options itemsRequest =
|
rss options itemsRequest =
|
||||||
ApiRoute.succeed
|
ApiRoute.succeed
|
||||||
|
@ -4,6 +4,7 @@ import Article
|
|||||||
import BuildError exposing (BuildError)
|
import BuildError exposing (BuildError)
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Date
|
import Date
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled exposing (..)
|
import Html.Styled exposing (..)
|
||||||
@ -34,10 +35,10 @@ route =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
Article.allMetadata
|
Article.allMetadata
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|
|
||||||
|
|
||||||
type alias Data =
|
type alias Data =
|
||||||
|
@ -7,6 +7,7 @@ import Data.Author as Author exposing (Author)
|
|||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Date exposing (Date)
|
import Date exposing (Date)
|
||||||
import DateOrDateTime
|
import DateOrDateTime
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled exposing (..)
|
import Html.Styled exposing (..)
|
||||||
@ -52,7 +53,7 @@ route =
|
|||||||
|> RouteBuilder.buildNoState { view = view }
|
|> RouteBuilder.buildNoState { view = view }
|
||||||
|
|
||||||
|
|
||||||
pages : DataSource BuildError (List RouteParams)
|
pages : DataSource Throwable (List RouteParams)
|
||||||
pages =
|
pages =
|
||||||
Article.blogPostsGlob
|
Article.blogPostsGlob
|
||||||
|> DataSource.map
|
|> DataSource.map
|
||||||
@ -240,7 +241,7 @@ type alias ActionData =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> DataSource BuildError Data
|
data : RouteParams -> DataSource Throwable Data
|
||||||
data routeParams =
|
data routeParams =
|
||||||
MarkdownCodec.withFrontmatter Data
|
MarkdownCodec.withFrontmatter Data
|
||||||
frontmatterDecoder
|
frontmatterDecoder
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Route.Docs.Section__ exposing (ActionData, Data, Model, Msg, route)
|
module Route.Docs.Section__ exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Css
|
import Css
|
||||||
import Css.Global
|
import Css.Global
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
import DataSource.Glob as Glob exposing (Glob)
|
import DataSource.Glob as Glob exposing (Glob)
|
||||||
import DocsSection exposing (Section)
|
import DocsSection exposing (Section)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Heroicon
|
import Heroicon
|
||||||
@ -55,7 +55,7 @@ route =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pages : DataSource BuildError (List RouteParams)
|
pages : DataSource Throwable (List RouteParams)
|
||||||
pages =
|
pages =
|
||||||
DocsSection.all
|
DocsSection.all
|
||||||
|> DataSource.map
|
|> DataSource.map
|
||||||
@ -70,7 +70,7 @@ pages =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> DataSource BuildError Data
|
data : RouteParams -> DataSource Throwable Data
|
||||||
data routeParams =
|
data routeParams =
|
||||||
DataSource.map4 Data
|
DataSource.map4 Data
|
||||||
(pageBody routeParams)
|
(pageBody routeParams)
|
||||||
@ -80,7 +80,7 @@ data routeParams =
|
|||||||
|> findBySlug
|
|> findBySlug
|
||||||
|> Glob.expectUniqueMatch
|
|> Glob.expectUniqueMatch
|
||||||
|> DataSource.map filePathToEditUrl
|
|> DataSource.map filePathToEditUrl
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
(routeParams |> filePathDataSource |> DataSource.andThen MarkdownCodec.titleAndDescription)
|
(routeParams |> filePathDataSource |> DataSource.andThen MarkdownCodec.titleAndDescription)
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ filePathToEditUrl filePath =
|
|||||||
"https://github.com/dillonkearns/elm-pages/edit/master/examples/docs/" ++ filePath
|
"https://github.com/dillonkearns/elm-pages/edit/master/examples/docs/" ++ filePath
|
||||||
|
|
||||||
|
|
||||||
previousAndNextData : RouteParams -> DataSource BuildError { title : String, previousAndNext : ( Maybe NextPrevious.Item, Maybe NextPrevious.Item ) }
|
previousAndNextData : RouteParams -> DataSource Throwable { title : String, previousAndNext : ( Maybe NextPrevious.Item, Maybe NextPrevious.Item ) }
|
||||||
previousAndNextData current =
|
previousAndNextData current =
|
||||||
DocsSection.all
|
DocsSection.all
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
@ -105,7 +105,7 @@ previousAndNextData current =
|
|||||||
DataSource.map2 (\title previousAndNext -> { title = title, previousAndNext = previousAndNext })
|
DataSource.map2 (\title previousAndNext -> { title = title, previousAndNext = previousAndNext })
|
||||||
(List.Extra.getAt index sections
|
(List.Extra.getAt index sections
|
||||||
|> maybeDataSource titleForSection
|
|> maybeDataSource titleForSection
|
||||||
|> DataSource.map (Result.fromMaybe (BuildError.internal "Couldn't find section"))
|
|> DataSource.map (Result.fromMaybe (Exception.fromString "Couldn't find section"))
|
||||||
|> DataSource.andThen DataSource.fromResult
|
|> DataSource.andThen DataSource.fromResult
|
||||||
|> DataSource.map .title
|
|> DataSource.map .title
|
||||||
)
|
)
|
||||||
@ -130,14 +130,14 @@ maybeDataSource fn maybe =
|
|||||||
DataSource.succeed Nothing
|
DataSource.succeed Nothing
|
||||||
|
|
||||||
|
|
||||||
titleForSection : Section -> DataSource BuildError NextPrevious.Item
|
titleForSection : Section -> DataSource Throwable NextPrevious.Item
|
||||||
titleForSection section =
|
titleForSection section =
|
||||||
Glob.expectUniqueMatch (findBySlug section.slug)
|
Glob.expectUniqueMatch (findBySlug section.slug)
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\filePath ->
|
(\filePath ->
|
||||||
DataSource.File.bodyWithoutFrontmatter filePath
|
DataSource.File.bodyWithoutFrontmatter filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen markdownBodyDecoder2
|
|> DataSource.andThen markdownBodyDecoder2
|
||||||
|> DataSource.map
|
|> DataSource.map
|
||||||
(\blocks ->
|
(\blocks ->
|
||||||
@ -159,7 +159,7 @@ titleForSection section =
|
|||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\maybeTitle ->
|
(\maybeTitle ->
|
||||||
maybeTitle
|
maybeTitle
|
||||||
|> Result.fromMaybe (BuildError.internal "Expected to find an H1 heading in this markdown.")
|
|> Result.fromMaybe (Exception.fromString "Expected to find an H1 heading in this markdown.")
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ view maybeUrl sharedModel static =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
filePathDataSource : RouteParams -> DataSource BuildError String
|
filePathDataSource : RouteParams -> DataSource Throwable String
|
||||||
filePathDataSource routeParams =
|
filePathDataSource routeParams =
|
||||||
let
|
let
|
||||||
slug : String
|
slug : String
|
||||||
@ -294,10 +294,10 @@ filePathDataSource routeParams =
|
|||||||
|> Maybe.withDefault "what-is-elm-pages"
|
|> Maybe.withDefault "what-is-elm-pages"
|
||||||
in
|
in
|
||||||
Glob.expectUniqueMatch (findBySlug slug)
|
Glob.expectUniqueMatch (findBySlug slug)
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|
|
||||||
|
|
||||||
pageBody : RouteParams -> DataSource BuildError (List Block)
|
pageBody : RouteParams -> DataSource Throwable (List Block)
|
||||||
pageBody routeParams =
|
pageBody routeParams =
|
||||||
routeParams
|
routeParams
|
||||||
|> filePathDataSource
|
|> filePathDataSource
|
||||||
@ -316,9 +316,9 @@ findBySlug slug =
|
|||||||
|> Glob.match (Glob.literal ".md")
|
|> Glob.match (Glob.literal ".md")
|
||||||
|
|
||||||
|
|
||||||
markdownBodyDecoder2 : String -> DataSource BuildError (List Block)
|
markdownBodyDecoder2 : String -> DataSource Throwable (List Block)
|
||||||
markdownBodyDecoder2 rawBody =
|
markdownBodyDecoder2 rawBody =
|
||||||
rawBody
|
rawBody
|
||||||
|> Markdown.Parser.parse
|
|> Markdown.Parser.parse
|
||||||
|> Result.mapError (\_ -> BuildError.internal "Markdown parsing error")
|
|> Result.mapError (\_ -> Exception.fromString "Markdown parsing error")
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Css
|
import Css
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled as Html exposing (..)
|
import Html.Styled as Html exposing (..)
|
||||||
@ -86,7 +86,7 @@ view maybeUrl sharedModel static =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.succeed ()
|
DataSource.succeed ()
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Route.Showcase exposing (ActionData, Data, Model, Msg, route)
|
module Route.Showcase exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Css
|
import Css
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Catchable, Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled exposing (..)
|
import Html.Styled exposing (..)
|
||||||
@ -40,7 +40,7 @@ route =
|
|||||||
|> RouteBuilder.buildNoState { view = view }
|
|> RouteBuilder.buildNoState { view = view }
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
Showcase.staticRequest
|
Showcase.staticRequest
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Shared exposing (Data, Model, Msg, template)
|
module Shared exposing (Data, Model, Msg, template)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DocsSection
|
import DocsSection
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Html.Styled
|
import Html.Styled
|
||||||
import Pages.Flags
|
import Pages.Flags
|
||||||
@ -86,7 +86,7 @@ subscriptions _ _ =
|
|||||||
Sub.none
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
TableOfContents.dataSource DocsSection.all
|
TableOfContents.dataSource DocsSection.all
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Site exposing (canonicalUrl, config)
|
module Site exposing (canonicalUrl, config)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Cloudinary
|
import Cloudinary
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import MimeType
|
import MimeType
|
||||||
import Pages.Url
|
import Pages.Url
|
||||||
@ -16,7 +16,7 @@ config =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
head : DataSource BuildError (List Head.Tag)
|
head : DataSource Throwable (List Head.Tag)
|
||||||
head =
|
head =
|
||||||
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
|
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
|
||||||
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")
|
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")
|
||||||
|
@ -5,6 +5,7 @@ import DataSource
|
|||||||
import DataSource.File as File
|
import DataSource.File as File
|
||||||
import DataSource.Glob as Glob
|
import DataSource.Glob as Glob
|
||||||
import Date exposing (Date)
|
import Date exposing (Date)
|
||||||
|
import Exception exposing (Catchable, Throwable)
|
||||||
import Json.Decode as Decode exposing (Decoder)
|
import Json.Decode as Decode exposing (Decoder)
|
||||||
import Pages.Url exposing (Url)
|
import Pages.Url exposing (Url)
|
||||||
import Route
|
import Route
|
||||||
@ -26,7 +27,7 @@ blogPostsGlob =
|
|||||||
|> Glob.toDataSource
|
|> Glob.toDataSource
|
||||||
|
|
||||||
|
|
||||||
allMetadata : DataSource.DataSource (File.FileReadError Decode.Error) (List ( Route.Route, ArticleMetadata ))
|
allMetadata : DataSource.DataSource (Catchable (File.FileReadError Decode.Error)) (List ( Route.Route, ArticleMetadata ))
|
||||||
allMetadata =
|
allMetadata =
|
||||||
blogPostsGlob
|
blogPostsGlob
|
||||||
|> DataSource.map
|
|> DataSource.map
|
||||||
|
@ -12,7 +12,7 @@ type alias Section =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
all : DataSource BuildError (List Section)
|
all : DataSource error (List Section)
|
||||||
all =
|
all =
|
||||||
Glob.succeed Section
|
Glob.succeed Section
|
||||||
|> Glob.captureFilePath
|
|> Glob.captureFilePath
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
module Manifest exposing (config)
|
module Manifest exposing (config)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Cloudinary
|
import Cloudinary
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import MimeType
|
import MimeType
|
||||||
@ -9,7 +8,7 @@ import Pages.Url
|
|||||||
import Route
|
import Route
|
||||||
|
|
||||||
|
|
||||||
config : DataSource BuildError Manifest.Config
|
config : DataSource error Manifest.Config
|
||||||
config =
|
config =
|
||||||
Manifest.init
|
Manifest.init
|
||||||
{ name = "elm-pages"
|
{ name = "elm-pages"
|
||||||
|
@ -4,6 +4,7 @@ import BuildError exposing (BuildError)
|
|||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Env as Env
|
import DataSource.Env as Env
|
||||||
import DataSource.Http
|
import DataSource.Http
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Json.Decode as Decode exposing (Decoder)
|
import Json.Decode as Decode exposing (Decoder)
|
||||||
import Json.Decode.Extra
|
import Json.Decode.Extra
|
||||||
|
|
||||||
@ -38,10 +39,10 @@ entryDecoder =
|
|||||||
(Decode.maybe (Decode.field "Repository URL" Decode.string))
|
(Decode.maybe (Decode.field "Repository URL" Decode.string))
|
||||||
|
|
||||||
|
|
||||||
staticRequest : DataSource BuildError (List Entry)
|
staticRequest : DataSource Throwable (List Entry)
|
||||||
staticRequest =
|
staticRequest =
|
||||||
Env.expect "AIRTABLE_TOKEN"
|
Env.expect "AIRTABLE_TOKEN"
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\airtableToken ->
|
(\airtableToken ->
|
||||||
DataSource.Http.request
|
DataSource.Http.request
|
||||||
@ -51,7 +52,7 @@ staticRequest =
|
|||||||
, body = DataSource.Http.emptyBody
|
, body = DataSource.Http.emptyBody
|
||||||
}
|
}
|
||||||
(DataSource.Http.expectJson decoder)
|
(DataSource.Http.expectJson decoder)
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module TableOfContents exposing (..)
|
module TableOfContents exposing (..)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Css
|
import Css
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Html.Styled exposing (..)
|
import Html.Styled exposing (..)
|
||||||
import Html.Styled.Attributes as Attr exposing (css)
|
import Html.Styled.Attributes as Attr exposing (css)
|
||||||
import List.Extra
|
import List.Extra
|
||||||
@ -14,8 +14,8 @@ import Tailwind.Utilities as Tw
|
|||||||
|
|
||||||
|
|
||||||
dataSource :
|
dataSource :
|
||||||
DataSource BuildError (List { file | filePath : String, slug : String })
|
DataSource Throwable (List { file | filePath : String, slug : String })
|
||||||
-> DataSource BuildError (TableOfContents Data)
|
-> DataSource Throwable (TableOfContents Data)
|
||||||
dataSource docFiles =
|
dataSource docFiles =
|
||||||
docFiles
|
docFiles
|
||||||
|> DataSource.map
|
|> DataSource.map
|
||||||
@ -25,20 +25,20 @@ dataSource docFiles =
|
|||||||
(\section ->
|
(\section ->
|
||||||
DataSource.File.bodyWithoutFrontmatter
|
DataSource.File.bodyWithoutFrontmatter
|
||||||
section.filePath
|
section.filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen (headingsDecoder section.slug)
|
|> DataSource.andThen (headingsDecoder section.slug)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> DataSource.resolve
|
|> DataSource.resolve
|
||||||
|
|
||||||
|
|
||||||
headingsDecoder : String -> String -> DataSource BuildError (Entry Data)
|
headingsDecoder : String -> String -> DataSource Throwable (Entry Data)
|
||||||
headingsDecoder slug rawBody =
|
headingsDecoder slug rawBody =
|
||||||
rawBody
|
rawBody
|
||||||
|> Markdown.Parser.parse
|
|> Markdown.Parser.parse
|
||||||
|> Result.mapError (\_ -> BuildError.internal "Markdown parsing error")
|
|> Result.mapError (\_ -> Exception.fromString "Markdown parsing error")
|
||||||
|> Result.map gatherHeadings
|
|> Result.map gatherHeadings
|
||||||
|> Result.andThen (nameAndTopLevel slug >> Result.mapError BuildError.internal)
|
|> Result.andThen (nameAndTopLevel slug >> Result.mapError Exception.fromString)
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Api exposing (routes)
|
module Api exposing (routes)
|
||||||
|
|
||||||
import ApiRoute exposing (ApiRoute)
|
import ApiRoute exposing (ApiRoute)
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form
|
import Form
|
||||||
import Form.Field as Field
|
import Form.Field as Field
|
||||||
import Form.Validation as Validation
|
import Form.Validation as Validation
|
||||||
@ -22,7 +22,7 @@ import Xml.Decode
|
|||||||
|
|
||||||
|
|
||||||
routes :
|
routes :
|
||||||
DataSource BuildError (List Route)
|
DataSource Throwable (List Route)
|
||||||
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
|
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
|
||||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||||
routes getStaticRoutes htmlToString =
|
routes getStaticRoutes htmlToString =
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
|
module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
@ -38,7 +38,7 @@ route =
|
|||||||
|> RouteBuilder.buildNoState { view = view }
|
|> RouteBuilder.buildNoState { view = view }
|
||||||
|
|
||||||
|
|
||||||
pages : DataSource BuildError (List RouteParams)
|
pages : DataSource Throwable (List RouteParams)
|
||||||
pages =
|
pages =
|
||||||
DataSource.succeed []
|
DataSource.succeed []
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ type alias Data =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> DataSource BuildError Data
|
data : RouteParams -> DataSource Throwable Data
|
||||||
data routeParams =
|
data routeParams =
|
||||||
DataSource.succeed {}
|
DataSource.succeed {}
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
module Route.CookieTest exposing (ActionData, Data, Model, Msg, route)
|
module Route.CookieTest exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
|
||||||
import Html.Styled exposing (text)
|
import Html.Styled exposing (text)
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
import Pages.PageUrl exposing (PageUrl)
|
import Pages.PageUrl exposing (PageUrl)
|
||||||
import Pages.Url
|
|
||||||
import RouteBuilder exposing (StatefulRoute, StatelessRoute, StaticPayload)
|
import RouteBuilder exposing (StatefulRoute, StatelessRoute, StaticPayload)
|
||||||
import Server.Request as Request exposing (Parser)
|
import Server.Request as Request exposing (Parser)
|
||||||
import Server.Response as Response exposing (Response)
|
import Server.Response as Response exposing (Response)
|
||||||
@ -46,7 +44,7 @@ type alias Data =
|
|||||||
{ darkMode : Maybe String }
|
{ darkMode : Maybe String }
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.oneOf
|
Request.oneOf
|
||||||
[ Request.expectCookie "dark-mode"
|
[ Request.expectCookie "dark-mode"
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
module Route.Counter exposing (ActionData, Data, Model, Msg, route)
|
module Route.Counter exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import Browser.Navigation
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled as Html
|
import Html.Styled as Html
|
||||||
@ -86,7 +85,7 @@ type alias Data =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.succeed Data
|
DataSource.succeed Data
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@ module Route.DarkMode exposing (..)
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Css
|
import Css
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Effect
|
import Effect
|
||||||
import ErrorPage
|
import ErrorPage
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form
|
import Form
|
||||||
import Form.Field as Field
|
import Form.Field as Field
|
||||||
import Form.Validation as Validation
|
import Form.Validation as Validation
|
||||||
@ -102,7 +102,7 @@ sessionOptions =
|
|||||||
|
|
||||||
data :
|
data :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Server.Request.Parser (DataSource BuildError (Server.Response.Response Data ErrorPage.ErrorPage))
|
-> Server.Request.Parser (DataSource Throwable (Server.Response.Response Data ErrorPage.ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Server.Request.succeed ()
|
Server.Request.succeed ()
|
||||||
|> Session.withSession sessionOptions
|
|> Session.withSession sessionOptions
|
||||||
@ -128,7 +128,7 @@ data routeParams =
|
|||||||
|
|
||||||
action :
|
action :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Server.Request.Parser (DataSource BuildError (Server.Response.Response ActionData ErrorPage.ErrorPage))
|
-> Server.Request.Parser (DataSource Throwable (Server.Response.Response ActionData ErrorPage.ErrorPage))
|
||||||
action routeParams =
|
action routeParams =
|
||||||
Server.Request.formData
|
Server.Request.formData
|
||||||
(form
|
(form
|
||||||
|
@ -2,12 +2,12 @@ module Route.Fetcher exposing (ActionData, Data, Model, Msg, RouteParams, route)
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Port
|
import DataSource.Port
|
||||||
import Dict
|
import Dict
|
||||||
import Effect
|
import Effect
|
||||||
import ErrorPage
|
import ErrorPage
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form
|
import Form
|
||||||
import Form.Field as Field
|
import Form.Field as Field
|
||||||
import Form.FieldView as FieldView
|
import Form.FieldView as FieldView
|
||||||
@ -94,7 +94,7 @@ type alias ActionData =
|
|||||||
|
|
||||||
data :
|
data :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Server.Request.Parser (DataSource BuildError (Server.Response.Response Data ErrorPage.ErrorPage))
|
-> Server.Request.Parser (DataSource Throwable (Server.Response.Response Data ErrorPage.ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Server.Request.succeed
|
Server.Request.succeed
|
||||||
(DataSource.Port.get "getItems"
|
(DataSource.Port.get "getItems"
|
||||||
@ -116,7 +116,7 @@ type Action
|
|||||||
|
|
||||||
action :
|
action :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Server.Request.Parser (DataSource BuildError (Server.Response.Response ActionData ErrorPage.ErrorPage))
|
-> Server.Request.Parser (DataSource Throwable (Server.Response.Response ActionData ErrorPage.ErrorPage))
|
||||||
action routeParams =
|
action routeParams =
|
||||||
Server.Request.formData
|
Server.Request.formData
|
||||||
forms
|
forms
|
||||||
|
@ -3,6 +3,7 @@ module Route.FileData exposing (ActionData, Data, Model, Msg, route)
|
|||||||
import BuildError exposing (BuildError)
|
import BuildError exposing (BuildError)
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled exposing (text)
|
import Html.Styled exposing (text)
|
||||||
@ -45,11 +46,11 @@ type alias Data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
"my-json-data.json"
|
"my-json-data.json"
|
||||||
|> DataSource.File.jsonFile (Decode.field "greeting" Decode.string)
|
|> DataSource.File.jsonFile (Decode.field "greeting" Decode.string)
|
||||||
|> DataSource.mapError DataSource.File.toBuildError
|
|> DataSource.throw
|
||||||
|> DataSource.map Data
|
|> DataSource.map Data
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
module Route.Form exposing (ActionData, Data, Model, Msg, route)
|
module Route.Form exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Date exposing (Date)
|
import Date exposing (Date)
|
||||||
import Dict
|
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form
|
import Form
|
||||||
import Form.Field as Field
|
import Form.Field as Field
|
||||||
import Form.FieldView
|
import Form.FieldView
|
||||||
@ -15,11 +14,9 @@ import Head.Seo as Seo
|
|||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Html.Attributes as Attr
|
import Html.Attributes as Attr
|
||||||
import Html.Styled
|
import Html.Styled
|
||||||
import Html.Styled.Attributes as StyledAttr
|
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
import Pages.PageUrl exposing (PageUrl)
|
import Pages.PageUrl exposing (PageUrl)
|
||||||
import Pages.Url
|
import Pages.Url
|
||||||
import Route
|
|
||||||
import RouteBuilder exposing (StatelessRoute, StaticPayload)
|
import RouteBuilder exposing (StatelessRoute, StaticPayload)
|
||||||
import Server.Request as Request exposing (Parser)
|
import Server.Request as Request exposing (Parser)
|
||||||
import Server.Response
|
import Server.Response
|
||||||
@ -188,7 +185,7 @@ type alias Data =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Parser (DataSource BuildError (Server.Response.Response Data ErrorPage))
|
data : RouteParams -> Parser (DataSource Throwable (Server.Response.Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Data
|
Data
|
||||||
|> Server.Response.render
|
|> Server.Response.render
|
||||||
@ -196,7 +193,7 @@ data routeParams =
|
|||||||
|> Request.succeed
|
|> Request.succeed
|
||||||
|
|
||||||
|
|
||||||
action : RouteParams -> Parser (DataSource BuildError (Server.Response.Response ActionData ErrorPage))
|
action : RouteParams -> Parser (DataSource Throwable (Server.Response.Response ActionData ErrorPage))
|
||||||
action routeParams =
|
action routeParams =
|
||||||
Request.formData (form |> Form.initCombined identity)
|
Request.formData (form |> Form.initCombined identity)
|
||||||
|> Request.map
|
|> Request.map
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
module Route.Greet exposing (ActionData, Data, Model, Msg, route)
|
module Route.Greet exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled as Html exposing (Html)
|
import Html.Styled as Html exposing (Html)
|
||||||
import Html.Styled.Attributes as Attr
|
import Html.Styled.Attributes as Attr
|
||||||
import Html.Styled.Events exposing (onSubmit)
|
|
||||||
import MySession
|
import MySession
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
import Pages.PageUrl exposing (PageUrl)
|
import Pages.PageUrl exposing (PageUrl)
|
||||||
@ -82,7 +81,7 @@ type alias Data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Request.Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Request.Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.oneOf
|
Request.oneOf
|
||||||
[ Request.map2 (\a b -> Data a b Nothing)
|
[ Request.map2 (\a b -> Data a b Nothing)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Route.Hello exposing (ActionData, Data, Model, Msg, route)
|
module Route.Hello exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
@ -45,7 +45,7 @@ type alias Data =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Request.Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Request.Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.succeed (DataSource.succeed (Response.render Data))
|
Request.succeed (DataSource.succeed (Response.render Data))
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
import DataSource.Port
|
import DataSource.Port
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled exposing (a, div, text)
|
import Html.Styled exposing (a, div, text)
|
||||||
@ -49,10 +49,10 @@ type alias Data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.map2 Data
|
DataSource.map2 Data
|
||||||
(DataSource.File.rawFile "greeting.txt" |> DataSource.mapError DataSource.File.toBuildError)
|
(DataSource.File.rawFile "greeting.txt" |> DataSource.throw)
|
||||||
(DataSource.Port.get "hello" (Encode.string "Jane") Decode.string)
|
(DataSource.Port.get "hello" (Encode.string "Jane") Decode.string)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Route.Links exposing (ActionData, Data, Model, Msg, route)
|
module Route.Links exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled as Html exposing (text)
|
import Html.Styled as Html exposing (text)
|
||||||
@ -43,7 +43,7 @@ type alias Data =
|
|||||||
()
|
()
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.succeed ()
|
DataSource.succeed ()
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Route.Login exposing (ActionData, Data, Model, Msg, route)
|
module Route.Login exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form
|
import Form
|
||||||
import Form.Field as Field
|
import Form.Field as Field
|
||||||
import Form.FieldView
|
import Form.FieldView
|
||||||
@ -51,7 +51,7 @@ route =
|
|||||||
|> RouteBuilder.buildNoState { view = view }
|
|> RouteBuilder.buildNoState { view = view }
|
||||||
|
|
||||||
|
|
||||||
action : RouteParams -> Request.Parser (DataSource BuildError (Response ActionData ErrorPage))
|
action : RouteParams -> Request.Parser (DataSource Throwable (Response ActionData ErrorPage))
|
||||||
action routeParams =
|
action routeParams =
|
||||||
Request.formDataWithServerValidation (form |> Form.initCombinedServer identity)
|
Request.formDataWithServerValidation (form |> Form.initCombinedServer identity)
|
||||||
|> MySession.withSession
|
|> MySession.withSession
|
||||||
@ -162,7 +162,7 @@ form =
|
|||||||
|> Form.field "name" (Field.text |> Field.required "Required")
|
|> Form.field "name" (Field.text |> Field.required "Required")
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Request.Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Request.Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.oneOf
|
Request.oneOf
|
||||||
[ Request.succeed ()
|
[ Request.succeed ()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Route.Logout exposing (ActionData, Data, Model, Msg, route)
|
module Route.Logout exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import MySession
|
import MySession
|
||||||
@ -44,7 +44,7 @@ route =
|
|||||||
|> RouteBuilder.buildNoState { view = view }
|
|> RouteBuilder.buildNoState { view = view }
|
||||||
|
|
||||||
|
|
||||||
action : RouteParams -> Request.Parser (DataSource BuildError (Response ActionData ErrorPage))
|
action : RouteParams -> Request.Parser (DataSource Throwable (Response ActionData ErrorPage))
|
||||||
action _ =
|
action _ =
|
||||||
Request.succeed ()
|
Request.succeed ()
|
||||||
|> MySession.withSession
|
|> MySession.withSession
|
||||||
@ -61,7 +61,7 @@ type alias Data =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Request.Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Request.Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.succeed (DataSource.succeed (Response.render {}))
|
Request.succeed (DataSource.succeed (Response.render {}))
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
module Route.Redirect exposing (ActionData, Data, Model, Msg, route)
|
module Route.Redirect exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import Browser.Navigation
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form.FormData exposing (Method(..))
|
import Form.FormData exposing (Method(..))
|
||||||
import FormDecoder
|
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
@ -94,7 +92,7 @@ type alias Data =
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Request.Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Request.Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.oneOf
|
Request.oneOf
|
||||||
[ Request.acceptMethod ( Request.Post, [] )
|
[ Request.acceptMethod ( Request.Post, [] )
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Route.Test.BasicAuth exposing (ActionData, Data, Model, Msg, route)
|
module Route.Test.BasicAuth exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import Base64
|
import Base64
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Html.Styled exposing (div, text)
|
import Html.Styled exposing (div, text)
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
@ -46,7 +46,7 @@ type alias Data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
withBasicAuth
|
withBasicAuth
|
||||||
(\{ username, password } ->
|
(\{ username, password } ->
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
module Route.Test.ResponseHeaders exposing (ActionData, Data, Model, Msg, route)
|
module Route.Test.ResponseHeaders exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import Base64
|
|
||||||
import BuildError exposing (BuildError)
|
import BuildError exposing (BuildError)
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Html.Styled exposing (div, text)
|
import Html.Styled exposing (div, text)
|
||||||
import Pages.Msg
|
import Pages.Msg
|
||||||
@ -47,11 +47,11 @@ type alias Data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : RouteParams -> Parser (DataSource BuildError (Response Data ErrorPage))
|
data : RouteParams -> Parser (DataSource Throwable (Response Data ErrorPage))
|
||||||
data routeParams =
|
data routeParams =
|
||||||
Request.succeed
|
Request.succeed
|
||||||
(DataSource.succeed Data
|
(DataSource.succeed Data
|
||||||
|> DataSource.andMap (DataSource.File.rawFile "greeting.txt" |> DataSource.mapError DataSource.File.toBuildError)
|
|> DataSource.andMap (DataSource.File.rawFile "greeting.txt" |> DataSource.throw)
|
||||||
|> DataSource.map Response.render
|
|> DataSource.map Response.render
|
||||||
|> DataSource.map (Response.withHeader "x-powered-by" "my-framework")
|
|> DataSource.map (Response.withHeader "x-powered-by" "my-framework")
|
||||||
)
|
)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
|
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Html.Styled
|
import Html.Styled
|
||||||
import Pages.Flags
|
import Pages.Flags
|
||||||
@ -76,7 +76,7 @@ subscriptions _ _ =
|
|||||||
Sub.none
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.succeed ()
|
DataSource.succeed ()
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module Site exposing (config)
|
module Site exposing (config)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Pages.Manifest as Manifest
|
import Pages.Manifest as Manifest
|
||||||
import Route
|
import Route
|
||||||
@ -19,7 +19,7 @@ config =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
head : DataSource BuildError (List Head.Tag)
|
head : DataSource Throwable (List Head.Tag)
|
||||||
head =
|
head =
|
||||||
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
|
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
|
||||||
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")
|
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module MySession exposing (..)
|
module MySession exposing (..)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Codec
|
import Codec
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Env as Env
|
import DataSource.Env as Env
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Route
|
import Route
|
||||||
import Server.Request exposing (Parser)
|
import Server.Request exposing (Parser)
|
||||||
import Server.Response as Response exposing (Response)
|
import Server.Response exposing (Response)
|
||||||
import Server.Session as Session
|
import Server.Session as Session
|
||||||
import Server.SetCookie as SetCookie
|
import Server.SetCookie as SetCookie
|
||||||
|
|
||||||
@ -19,9 +19,9 @@ cookieOptions =
|
|||||||
|
|
||||||
|
|
||||||
withSession :
|
withSession :
|
||||||
(request -> Result Session.NotLoadedReason Session.Session -> DataSource BuildError ( Session.Session, Response data errorPage ))
|
(request -> Result Session.NotLoadedReason Session.Session -> DataSource Throwable ( Session.Session, Response data errorPage ))
|
||||||
-> Parser request
|
-> Parser request
|
||||||
-> Parser (DataSource BuildError (Response data errorPage))
|
-> Parser (DataSource Throwable (Response data errorPage))
|
||||||
withSession =
|
withSession =
|
||||||
Session.withSession
|
Session.withSession
|
||||||
{ name = "mysession"
|
{ name = "mysession"
|
||||||
@ -31,9 +31,9 @@ withSession =
|
|||||||
|
|
||||||
|
|
||||||
withSessionOrRedirect :
|
withSessionOrRedirect :
|
||||||
(request -> Session.Session -> DataSource BuildError ( Session.Session, Response data errorPage ))
|
(request -> Session.Session -> DataSource Throwable ( Session.Session, Response data errorPage ))
|
||||||
-> Parser request
|
-> Parser request
|
||||||
-> Parser (DataSource BuildError (Response data errorPage))
|
-> Parser (DataSource Throwable (Response data errorPage))
|
||||||
withSessionOrRedirect toRequest handler =
|
withSessionOrRedirect toRequest handler =
|
||||||
Session.withSession
|
Session.withSession
|
||||||
{ name = "mysession"
|
{ name = "mysession"
|
||||||
@ -53,17 +53,17 @@ withSessionOrRedirect toRequest handler =
|
|||||||
handler
|
handler
|
||||||
|
|
||||||
|
|
||||||
secrets : DataSource BuildError (List String)
|
secrets : DataSource Throwable (List String)
|
||||||
secrets =
|
secrets =
|
||||||
Env.expect "SESSION_SECRET"
|
Env.expect "SESSION_SECRET"
|
||||||
|
|> DataSource.throw
|
||||||
|> DataSource.map List.singleton
|
|> DataSource.map List.singleton
|
||||||
|> DataSource.mapError Env.toBuildError
|
|
||||||
|
|
||||||
|
|
||||||
expectSessionOrRedirect :
|
expectSessionOrRedirect :
|
||||||
(request -> Session.Session -> DataSource BuildError ( Session.Session, Response data errorPage ))
|
(request -> Session.Session -> DataSource Throwable ( Session.Session, Response data errorPage ))
|
||||||
-> Parser request
|
-> Parser request
|
||||||
-> Parser (DataSource BuildError (Response data errorPage))
|
-> Parser (DataSource Throwable (Response data errorPage))
|
||||||
expectSessionOrRedirect toRequest handler =
|
expectSessionOrRedirect toRequest handler =
|
||||||
Session.withSession
|
Session.withSession
|
||||||
{ name = "mysession"
|
{ name = "mysession"
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
module Route.Escaping exposing (ActionData, Data, Model, Msg, route)
|
module Route.Escaping exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Css exposing (..)
|
import Css exposing (..)
|
||||||
import Css.Global
|
import Css.Global
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled as Html exposing (..)
|
import Html.Styled as Html exposing (..)
|
||||||
@ -48,10 +48,10 @@ type alias Data =
|
|||||||
String
|
String
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.File.rawFile "unsafe-script-tag.txt"
|
DataSource.File.rawFile "unsafe-script-tag.txt"
|
||||||
|> DataSource.mapError DataSource.File.toBuildError
|
|> DataSource.throw
|
||||||
|
|
||||||
|
|
||||||
head :
|
head :
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
module Route.Index exposing (ActionData, Data, Model, Msg, route)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Head.Seo as Seo
|
import Head.Seo as Seo
|
||||||
import Html.Styled as Html exposing (text)
|
import Html.Styled as Html exposing (text)
|
||||||
@ -44,7 +43,7 @@ type alias Data =
|
|||||||
()
|
()
|
||||||
|
|
||||||
|
|
||||||
data : DataSource BuildError Data
|
data : DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.succeed ()
|
DataSource.succeed ()
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
module Api exposing (routes)
|
module Api exposing (routes)
|
||||||
|
|
||||||
import ApiRoute
|
import ApiRoute
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Route exposing (Route)
|
import Route exposing (Route)
|
||||||
|
|
||||||
|
|
||||||
routes :
|
routes :
|
||||||
DataSource BuildError (List Route)
|
DataSource Throwable (List Route)
|
||||||
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
|
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
|
||||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||||
routes getStaticRoutes htmlToString =
|
routes getStaticRoutes htmlToString =
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
|
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource
|
import DataSource
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Html.Styled
|
import Html.Styled
|
||||||
import Pages.Flags
|
import Pages.Flags
|
||||||
@ -76,7 +76,7 @@ subscriptions _ _ =
|
|||||||
Sub.none
|
Sub.none
|
||||||
|
|
||||||
|
|
||||||
data : DataSource.DataSource BuildError Data
|
data : DataSource.DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.succeed ()
|
DataSource.succeed ()
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Site exposing (config)
|
module Site exposing (config)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Cloudinary
|
import Cloudinary
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import MimeType
|
import MimeType
|
||||||
import Pages.Manifest as Manifest
|
import Pages.Manifest as Manifest
|
||||||
@ -23,14 +23,14 @@ type alias Data =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data : DataSource.DataSource BuildError Data
|
data : DataSource.DataSource Throwable Data
|
||||||
data =
|
data =
|
||||||
DataSource.map Data
|
DataSource.map Data
|
||||||
--(StaticFile.request "site-name.txt" StaticFile.body)
|
--(StaticFile.request "site-name.txt" StaticFile.body)
|
||||||
(DataSource.succeed "site-name")
|
(DataSource.succeed "site-name")
|
||||||
|
|
||||||
|
|
||||||
head : DataSource BuildError (List Head.Tag)
|
head : DataSource Throwable (List Head.Tag)
|
||||||
head =
|
head =
|
||||||
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
|
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
|
||||||
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")
|
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")
|
||||||
|
@ -134,8 +134,8 @@ declarationVisitor node context =
|
|||||||
-- TODO need to replace `action` as well
|
-- TODO need to replace `action` as well
|
||||||
[ ("data = "
|
[ ("data = "
|
||||||
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
||||||
-- TODO add `import BuildError` if not present (and use alias if present)
|
-- TODO add `import Exception` if not present (and use alias if present)
|
||||||
++ " (BuildError.internal \"\")\n "
|
++ " (Exception.fromString \"\")\n "
|
||||||
)
|
)
|
||||||
|> Review.Fix.replaceRangeBy (Node.range dataValue)
|
|> Review.Fix.replaceRangeBy (Node.range dataValue)
|
||||||
]
|
]
|
||||||
@ -193,12 +193,12 @@ expressionVisitor node context =
|
|||||||
"preRender" ->
|
"preRender" ->
|
||||||
"\\_ -> "
|
"\\_ -> "
|
||||||
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
||||||
++ " (BuildError.internal \"\")"
|
++ " (Exception.fromString \"\")"
|
||||||
|
|
||||||
"preRenderWithFallback" ->
|
"preRenderWithFallback" ->
|
||||||
"\\_ -> "
|
"\\_ -> "
|
||||||
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
||||||
++ " (BuildError.internal \"\")"
|
++ " (Exception.fromString \"\")"
|
||||||
|
|
||||||
"serverRender" ->
|
"serverRender" ->
|
||||||
"\\_ -> "
|
"\\_ -> "
|
||||||
@ -207,7 +207,7 @@ expressionVisitor node context =
|
|||||||
|
|
||||||
"single" ->
|
"single" ->
|
||||||
referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
||||||
++ " (BuildError.internal \"\")\n "
|
++ " (Exception.fromString \"\")\n "
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
"data"
|
"data"
|
||||||
|
@ -85,11 +85,11 @@ When there are Dynamic Route Segments, you need to tell `elm-pages` which pages
|
|||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
import ErrorPage exposing (ErrorPage)
|
import ErrorPage exposing (ErrorPage)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Http
|
import Http
|
||||||
import Json.Decode
|
import Json.Decode
|
||||||
@ -109,9 +109,9 @@ import View exposing (View)
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
type alias StatefulRoute routeParams data action model msg =
|
type alias StatefulRoute routeParams data action model msg =
|
||||||
{ data : Json.Decode.Value -> routeParams -> DataSource BuildError (Server.Response.Response data ErrorPage)
|
{ data : Json.Decode.Value -> routeParams -> DataSource Throwable (Server.Response.Response data ErrorPage)
|
||||||
, action : Json.Decode.Value -> routeParams -> DataSource BuildError (Server.Response.Response action ErrorPage)
|
, action : Json.Decode.Value -> routeParams -> DataSource Throwable (Server.Response.Response action ErrorPage)
|
||||||
, staticRoutes : DataSource BuildError (List routeParams)
|
, staticRoutes : DataSource Throwable (List routeParams)
|
||||||
, view :
|
, view :
|
||||||
Maybe PageUrl
|
Maybe PageUrl
|
||||||
-> Shared.Model
|
-> Shared.Model
|
||||||
@ -124,7 +124,7 @@ type alias StatefulRoute routeParams data action model msg =
|
|||||||
, init : Maybe PageUrl -> Shared.Model -> StaticPayload data action routeParams -> ( model, Effect msg )
|
, init : Maybe PageUrl -> Shared.Model -> StaticPayload data action routeParams -> ( model, Effect msg )
|
||||||
, update : PageUrl -> StaticPayload data action routeParams -> msg -> model -> Shared.Model -> ( model, Effect msg, Maybe Shared.Msg )
|
, update : PageUrl -> StaticPayload data action routeParams -> msg -> model -> Shared.Model -> ( model, Effect msg, Maybe Shared.Msg )
|
||||||
, subscriptions : Maybe PageUrl -> routeParams -> Path -> model -> Shared.Model -> Sub msg
|
, subscriptions : Maybe PageUrl -> routeParams -> Path -> model -> Shared.Model -> Sub msg
|
||||||
, handleRoute : { moduleName : List String, routePattern : RoutePattern } -> (routeParams -> List ( String, String )) -> routeParams -> DataSource BuildError (Maybe NotFoundReason)
|
, handleRoute : { moduleName : List String, routePattern : RoutePattern } -> (routeParams -> List ( String, String )) -> routeParams -> DataSource Throwable (Maybe NotFoundReason)
|
||||||
, kind : String
|
, kind : String
|
||||||
, onAction : Maybe (action -> msg)
|
, onAction : Maybe (action -> msg)
|
||||||
}
|
}
|
||||||
@ -154,9 +154,9 @@ type alias StaticPayload data action routeParams =
|
|||||||
{-| -}
|
{-| -}
|
||||||
type Builder routeParams data action
|
type Builder routeParams data action
|
||||||
= WithData
|
= WithData
|
||||||
{ data : Json.Decode.Value -> routeParams -> DataSource BuildError (Server.Response.Response data ErrorPage)
|
{ data : Json.Decode.Value -> routeParams -> DataSource Throwable (Server.Response.Response data ErrorPage)
|
||||||
, action : Json.Decode.Value -> routeParams -> DataSource BuildError (Server.Response.Response action ErrorPage)
|
, action : Json.Decode.Value -> routeParams -> DataSource Throwable (Server.Response.Response action ErrorPage)
|
||||||
, staticRoutes : DataSource BuildError (List routeParams)
|
, staticRoutes : DataSource Throwable (List routeParams)
|
||||||
, head :
|
, head :
|
||||||
StaticPayload data action routeParams
|
StaticPayload data action routeParams
|
||||||
-> List Head.Tag
|
-> List Head.Tag
|
||||||
@ -165,7 +165,7 @@ type Builder routeParams data action
|
|||||||
{ moduleName : List String, routePattern : RoutePattern }
|
{ moduleName : List String, routePattern : RoutePattern }
|
||||||
-> (routeParams -> List ( String, String ))
|
-> (routeParams -> List ( String, String ))
|
||||||
-> routeParams
|
-> routeParams
|
||||||
-> DataSource BuildError (Maybe NotFoundReason)
|
-> DataSource Throwable (Maybe NotFoundReason)
|
||||||
, kind : String
|
, kind : String
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,14 +292,14 @@ buildWithSharedState config builderState =
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
single :
|
single :
|
||||||
{ data : DataSource BuildError data
|
{ data : DataSource Throwable data
|
||||||
, head : StaticPayload data action {} -> List Head.Tag
|
, head : StaticPayload data action {} -> List Head.Tag
|
||||||
}
|
}
|
||||||
-> Builder {} data action
|
-> Builder {} data action
|
||||||
single { data, head } =
|
single { data, head } =
|
||||||
WithData
|
WithData
|
||||||
{ data = \_ _ -> data |> DataSource.map Server.Response.render
|
{ data = \_ _ -> data |> DataSource.map Server.Response.render
|
||||||
, action = \_ _ -> DataSource.fail (BuildError.internal "Internal Error - actions should never be called for statically generated pages.")
|
, action = \_ _ -> DataSource.fail (Exception.fromString "Internal Error - actions should never be called for statically generated pages.")
|
||||||
, staticRoutes = DataSource.succeed [ {} ]
|
, staticRoutes = DataSource.succeed [ {} ]
|
||||||
, head = head
|
, head = head
|
||||||
, serverless = False
|
, serverless = False
|
||||||
@ -310,15 +310,15 @@ single { data, head } =
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
preRender :
|
preRender :
|
||||||
{ data : routeParams -> DataSource BuildError data
|
{ data : routeParams -> DataSource Throwable data
|
||||||
, pages : DataSource BuildError (List routeParams)
|
, pages : DataSource Throwable (List routeParams)
|
||||||
, head : StaticPayload data action routeParams -> List Head.Tag
|
, head : StaticPayload data action routeParams -> List Head.Tag
|
||||||
}
|
}
|
||||||
-> Builder routeParams data action
|
-> Builder routeParams data action
|
||||||
preRender { data, head, pages } =
|
preRender { data, head, pages } =
|
||||||
WithData
|
WithData
|
||||||
{ data = \_ -> data >> DataSource.map Server.Response.render
|
{ data = \_ -> data >> DataSource.map Server.Response.render
|
||||||
, action = \_ _ -> DataSource.fail (BuildError.internal "Internal Error - actions should never be called for statically generated pages.")
|
, action = \_ _ -> DataSource.fail (Exception.fromString "Internal Error - actions should never be called for statically generated pages.")
|
||||||
, staticRoutes = pages
|
, staticRoutes = pages
|
||||||
, head = head
|
, head = head
|
||||||
, serverless = False
|
, serverless = False
|
||||||
@ -348,15 +348,15 @@ preRender { data, head, pages } =
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
preRenderWithFallback :
|
preRenderWithFallback :
|
||||||
{ data : routeParams -> DataSource BuildError (Server.Response.Response data ErrorPage)
|
{ data : routeParams -> DataSource Throwable (Server.Response.Response data ErrorPage)
|
||||||
, pages : DataSource BuildError (List routeParams)
|
, pages : DataSource Throwable (List routeParams)
|
||||||
, head : StaticPayload data action routeParams -> List Head.Tag
|
, head : StaticPayload data action routeParams -> List Head.Tag
|
||||||
}
|
}
|
||||||
-> Builder routeParams data action
|
-> Builder routeParams data action
|
||||||
preRenderWithFallback { data, head, pages } =
|
preRenderWithFallback { data, head, pages } =
|
||||||
WithData
|
WithData
|
||||||
{ data = \_ -> data
|
{ data = \_ -> data
|
||||||
, action = \_ _ -> DataSource.fail (BuildError.internal "Internal Error - actions should never be called for statically generated pages.")
|
, action = \_ _ -> DataSource.fail (Exception.fromString "Internal Error - actions should never be called for statically generated pages.")
|
||||||
, staticRoutes = pages
|
, staticRoutes = pages
|
||||||
, head = head
|
, head = head
|
||||||
, serverless = False
|
, serverless = False
|
||||||
@ -369,8 +369,8 @@ preRenderWithFallback { data, head, pages } =
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
serverRender :
|
serverRender :
|
||||||
{ data : routeParams -> Server.Request.Parser (DataSource BuildError (Server.Response.Response data ErrorPage))
|
{ data : routeParams -> Server.Request.Parser (DataSource Throwable (Server.Response.Response data ErrorPage))
|
||||||
, action : routeParams -> Server.Request.Parser (DataSource BuildError (Server.Response.Response action ErrorPage))
|
, action : routeParams -> Server.Request.Parser (DataSource Throwable (Server.Response.Response action ErrorPage))
|
||||||
, head : StaticPayload data action routeParams -> List Head.Tag
|
, head : StaticPayload data action routeParams -> List Head.Tag
|
||||||
}
|
}
|
||||||
-> Builder routeParams data action
|
-> Builder routeParams data action
|
||||||
@ -396,7 +396,7 @@ serverRender { data, action, head } =
|
|||||||
|
|
||||||
Err error ->
|
Err error ->
|
||||||
Server.Request.errorsToString error
|
Server.Request.errorsToString error
|
||||||
|> BuildError.internal
|
|> Exception.fromString
|
||||||
|> DataSource.fail
|
|> DataSource.fail
|
||||||
)
|
)
|
||||||
, action =
|
, action =
|
||||||
@ -419,7 +419,7 @@ serverRender { data, action, head } =
|
|||||||
|
|
||||||
Err error ->
|
Err error ->
|
||||||
Server.Request.errorsToString error
|
Server.Request.errorsToString error
|
||||||
|> BuildError.internal
|
|> Exception.fromString
|
||||||
|> DataSource.fail
|
|> DataSource.fail
|
||||||
)
|
)
|
||||||
, staticRoutes = DataSource.succeed []
|
, staticRoutes = DataSource.succeed []
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module SharedTemplate exposing (SharedTemplate)
|
module SharedTemplate exposing (SharedTemplate)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource
|
import DataSource
|
||||||
import Effect exposing (Effect)
|
import Effect exposing (Effect)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import Pages.Flags exposing (Flags)
|
import Pages.Flags exposing (Flags)
|
||||||
import Pages.PageUrl exposing (PageUrl)
|
import Pages.PageUrl exposing (PageUrl)
|
||||||
@ -36,7 +36,7 @@ type alias SharedTemplate msg sharedModel sharedData mappedMsg =
|
|||||||
-> (msg -> mappedMsg)
|
-> (msg -> mappedMsg)
|
||||||
-> View mappedMsg
|
-> View mappedMsg
|
||||||
-> { body : List (Html mappedMsg), title : String }
|
-> { body : List (Html mappedMsg), title : String }
|
||||||
, data : DataSource.DataSource BuildError sharedData
|
, data : DataSource.DataSource Throwable sharedData
|
||||||
, subscriptions : Path -> sharedModel -> Sub msg
|
, subscriptions : Path -> sharedModel -> Sub msg
|
||||||
, onPageChange :
|
, onPageChange :
|
||||||
Maybe
|
Maybe
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module SiteConfig exposing (SiteConfig)
|
module SiteConfig exposing (SiteConfig)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
|
|
||||||
|
|
||||||
type alias SiteConfig =
|
type alias SiteConfig =
|
||||||
{ canonicalUrl : String
|
{ canonicalUrl : String
|
||||||
, head : DataSource BuildError (List Head.Tag)
|
, head : DataSource Throwable (List Head.Tag)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module MarkdownCodec exposing (isPlaceholder, noteTitle, titleAndDescription, withFrontmatter, withoutFrontmatter)
|
module MarkdownCodec exposing (isPlaceholder, noteTitle, titleAndDescription, withFrontmatter, withoutFrontmatter)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File as StaticFile
|
import DataSource.File as StaticFile
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Json.Decode as Decode exposing (Decoder)
|
import Json.Decode as Decode exposing (Decoder)
|
||||||
import Json.Decode.Extra
|
import Json.Decode.Extra
|
||||||
import List.Extra
|
import List.Extra
|
||||||
@ -12,15 +12,15 @@ import Markdown.Renderer
|
|||||||
import MarkdownExtra
|
import MarkdownExtra
|
||||||
|
|
||||||
|
|
||||||
isPlaceholder : String -> DataSource BuildError (Maybe ())
|
isPlaceholder : String -> DataSource Throwable (Maybe ())
|
||||||
isPlaceholder filePath =
|
isPlaceholder filePath =
|
||||||
filePath
|
filePath
|
||||||
|> StaticFile.bodyWithoutFrontmatter
|
|> StaticFile.bodyWithoutFrontmatter
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\rawContent ->
|
(\rawContent ->
|
||||||
Markdown.Parser.parse rawContent
|
Markdown.Parser.parse rawContent
|
||||||
|> Result.mapError (\_ -> BuildError.internal "Markdown error")
|
|> Result.mapError (\_ -> Exception.fromString "Markdown error")
|
||||||
|> Result.map
|
|> Result.map
|
||||||
(\blocks ->
|
(\blocks ->
|
||||||
List.any
|
List.any
|
||||||
@ -47,7 +47,7 @@ isPlaceholder filePath =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
noteTitle : String -> DataSource BuildError String
|
noteTitle : String -> DataSource Throwable String
|
||||||
noteTitle filePath =
|
noteTitle filePath =
|
||||||
titleFromFrontmatter filePath
|
titleFromFrontmatter filePath
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
@ -56,7 +56,7 @@ noteTitle filePath =
|
|||||||
|> Maybe.map DataSource.succeed
|
|> Maybe.map DataSource.succeed
|
||||||
|> Maybe.withDefault
|
|> Maybe.withDefault
|
||||||
(StaticFile.bodyWithoutFrontmatter filePath
|
(StaticFile.bodyWithoutFrontmatter filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\rawContent ->
|
(\rawContent ->
|
||||||
Markdown.Parser.parse rawContent
|
Markdown.Parser.parse rawContent
|
||||||
@ -76,13 +76,13 @@ noteTitle filePath =
|
|||||||
)
|
)
|
||||||
|> Result.andThen (Result.fromMaybe <| "Expected to find an H1 heading for page " ++ filePath)
|
|> Result.andThen (Result.fromMaybe <| "Expected to find an H1 heading for page " ++ filePath)
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
titleAndDescription : String -> DataSource BuildError { title : String, description : String }
|
titleAndDescription : String -> DataSource Throwable { title : String, description : String }
|
||||||
titleAndDescription filePath =
|
titleAndDescription filePath =
|
||||||
filePath
|
filePath
|
||||||
|> StaticFile.onlyFrontmatter
|
|> StaticFile.onlyFrontmatter
|
||||||
@ -90,7 +90,7 @@ titleAndDescription filePath =
|
|||||||
(Json.Decode.Extra.optionalField "title" Decode.string)
|
(Json.Decode.Extra.optionalField "title" Decode.string)
|
||||||
(Json.Decode.Extra.optionalField "description" Decode.string)
|
(Json.Decode.Extra.optionalField "description" Decode.string)
|
||||||
)
|
)
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\metadata ->
|
(\metadata ->
|
||||||
Maybe.map2 (\title description -> { title = title, description = description })
|
Maybe.map2 (\title description -> { title = title, description = description })
|
||||||
@ -99,7 +99,7 @@ titleAndDescription filePath =
|
|||||||
|> Maybe.map DataSource.succeed
|
|> Maybe.map DataSource.succeed
|
||||||
|> Maybe.withDefault
|
|> Maybe.withDefault
|
||||||
(StaticFile.bodyWithoutFrontmatter filePath
|
(StaticFile.bodyWithoutFrontmatter filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\rawContent ->
|
(\rawContent ->
|
||||||
Markdown.Parser.parse rawContent
|
Markdown.Parser.parse rawContent
|
||||||
@ -127,8 +127,8 @@ titleAndDescription filePath =
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> Result.andThen (Result.fromMaybe <| "Expected to find an H1 heading for page " ++ filePath)
|
|> Result.andThen (Result.fromMaybe <| "Expected to find an H1 heading for page " ++ filePath)
|
||||||
|
|> Result.mapError Exception.fromString
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -163,27 +163,27 @@ findDescription blocks =
|
|||||||
|> Maybe.withDefault ""
|
|> Maybe.withDefault ""
|
||||||
|
|
||||||
|
|
||||||
titleFromFrontmatter : String -> DataSource BuildError (Maybe String)
|
titleFromFrontmatter : String -> DataSource Throwable (Maybe String)
|
||||||
titleFromFrontmatter filePath =
|
titleFromFrontmatter filePath =
|
||||||
StaticFile.onlyFrontmatter
|
StaticFile.onlyFrontmatter
|
||||||
(Json.Decode.Extra.optionalField "title" Decode.string)
|
(Json.Decode.Extra.optionalField "title" Decode.string)
|
||||||
filePath
|
filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|
|
||||||
|
|
||||||
withoutFrontmatter :
|
withoutFrontmatter :
|
||||||
Markdown.Renderer.Renderer view
|
Markdown.Renderer.Renderer view
|
||||||
-> String
|
-> String
|
||||||
-> DataSource BuildError (List Block)
|
-> DataSource Throwable (List Block)
|
||||||
withoutFrontmatter renderer filePath =
|
withoutFrontmatter renderer filePath =
|
||||||
(filePath
|
(filePath
|
||||||
|> StaticFile.bodyWithoutFrontmatter
|
|> StaticFile.bodyWithoutFrontmatter
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\rawBody ->
|
(\rawBody ->
|
||||||
rawBody
|
rawBody
|
||||||
|> Markdown.Parser.parse
|
|> Markdown.Parser.parse
|
||||||
|> Result.mapError (\_ -> BuildError.internal "Couldn't parse markdown.")
|
|> Result.mapError (\_ -> Exception.fromString "Couldn't parse markdown.")
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -195,7 +195,7 @@ withoutFrontmatter renderer filePath =
|
|||||||
-- but we can at least make sure there are no errors turning it into HTML before encoding it
|
-- but we can at least make sure there are no errors turning it into HTML before encoding it
|
||||||
|> Result.map (\_ -> blocks)
|
|> Result.map (\_ -> blocks)
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -204,22 +204,22 @@ withFrontmatter :
|
|||||||
-> Decoder frontmatter
|
-> Decoder frontmatter
|
||||||
-> Markdown.Renderer.Renderer view
|
-> Markdown.Renderer.Renderer view
|
||||||
-> String
|
-> String
|
||||||
-> DataSource BuildError value
|
-> DataSource Throwable value
|
||||||
withFrontmatter constructor frontmatterDecoder_ renderer filePath =
|
withFrontmatter constructor frontmatterDecoder_ renderer filePath =
|
||||||
DataSource.map2 constructor
|
DataSource.map2 constructor
|
||||||
(StaticFile.onlyFrontmatter
|
(StaticFile.onlyFrontmatter
|
||||||
frontmatterDecoder_
|
frontmatterDecoder_
|
||||||
filePath
|
filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
(StaticFile.bodyWithoutFrontmatter
|
(StaticFile.bodyWithoutFrontmatter
|
||||||
filePath
|
filePath
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
(\rawBody ->
|
(\rawBody ->
|
||||||
rawBody
|
rawBody
|
||||||
|> Markdown.Parser.parse
|
|> Markdown.Parser.parse
|
||||||
|> Result.mapError (\_ -> BuildError.internal "Couldn't parse markdown.")
|
|> Result.mapError (\_ -> Exception.fromString "Couldn't parse markdown.")
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
)
|
)
|
||||||
|> DataSource.andThen
|
|> DataSource.andThen
|
||||||
@ -230,6 +230,6 @@ withFrontmatter constructor frontmatterDecoder_ renderer filePath =
|
|||||||
-- but we can at least make sure there are no errors turning it into HTML before encoding it
|
-- but we can at least make sure there are no errors turning it into HTML before encoding it
|
||||||
|> Result.map (\_ -> blocks)
|
|> Result.map (\_ -> blocks)
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (BuildError.internal "TODO map to more informative error"))
|
|> DataSource.throw
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -172,8 +172,8 @@ You define your ApiRoute's in `app/Api.elm`. Here's a simple example:
|
|||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Internal.ApiRoute exposing (ApiRoute(..), ApiRouteBuilder(..))
|
import Internal.ApiRoute exposing (ApiRoute(..), ApiRouteBuilder(..))
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
@ -192,7 +192,7 @@ type alias ApiRoute response =
|
|||||||
{-| Same as [`preRender`](#preRender), but for an ApiRoute that has no dynamic segments. This is just a bit simpler because
|
{-| Same as [`preRender`](#preRender), but for an ApiRoute that has no dynamic segments. This is just a bit simpler because
|
||||||
since there are no dynamic segments, you don't need to provide a DataSource with the list of dynamic segments to pre-render because there is only a single possible route.
|
since there are no dynamic segments, you don't need to provide a DataSource with the list of dynamic segments to pre-render because there is only a single possible route.
|
||||||
-}
|
-}
|
||||||
single : ApiRouteBuilder (DataSource BuildError String) (List String) -> ApiRoute Response
|
single : ApiRouteBuilder (DataSource Throwable String) (List String) -> ApiRoute Response
|
||||||
single handler =
|
single handler =
|
||||||
handler
|
handler
|
||||||
|> preRender (\constructor -> DataSource.succeed [ constructor ])
|
|> preRender (\constructor -> DataSource.succeed [ constructor ])
|
||||||
@ -259,10 +259,10 @@ serverRender ((ApiRouteBuilder patterns pattern _ _ _) as fullHandler) =
|
|||||||
|
|
||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
preRenderWithFallback : (constructor -> DataSource BuildError (List (List String))) -> ApiRouteBuilder (DataSource BuildError (Server.Response.Response Never Never)) constructor -> ApiRoute Response
|
preRenderWithFallback : (constructor -> DataSource Throwable (List (List String))) -> ApiRouteBuilder (DataSource Throwable (Server.Response.Response Never Never)) constructor -> ApiRoute Response
|
||||||
preRenderWithFallback buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) =
|
preRenderWithFallback buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) =
|
||||||
let
|
let
|
||||||
buildTimeRoutes__ : DataSource BuildError (List String)
|
buildTimeRoutes__ : DataSource Throwable (List String)
|
||||||
buildTimeRoutes__ =
|
buildTimeRoutes__ =
|
||||||
buildUrls (constructor [])
|
buildUrls (constructor [])
|
||||||
|> DataSource.map (List.map toString)
|
|> DataSource.map (List.map toString)
|
||||||
@ -301,15 +301,15 @@ encodeStaticFileBody fileBody =
|
|||||||
|
|
||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
preRender : (constructor -> DataSource BuildError (List (List String))) -> ApiRouteBuilder (DataSource BuildError String) constructor -> ApiRoute Response
|
preRender : (constructor -> DataSource Throwable (List (List String))) -> ApiRouteBuilder (DataSource Throwable String) constructor -> ApiRoute Response
|
||||||
preRender buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) =
|
preRender buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) =
|
||||||
let
|
let
|
||||||
buildTimeRoutes__ : DataSource BuildError (List String)
|
buildTimeRoutes__ : DataSource Throwable (List String)
|
||||||
buildTimeRoutes__ =
|
buildTimeRoutes__ =
|
||||||
buildUrls (constructor [])
|
buildUrls (constructor [])
|
||||||
|> DataSource.map (List.map toString)
|
|> DataSource.map (List.map toString)
|
||||||
|
|
||||||
preBuiltMatches : DataSource BuildError (List (List String))
|
preBuiltMatches : DataSource Throwable (List (List String))
|
||||||
preBuiltMatches =
|
preBuiltMatches =
|
||||||
buildUrls (constructor [])
|
buildUrls (constructor [])
|
||||||
in
|
in
|
||||||
@ -322,7 +322,7 @@ preRender buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) a
|
|||||||
matches =
|
matches =
|
||||||
Internal.ApiRoute.pathToMatches path fullHandler
|
Internal.ApiRoute.pathToMatches path fullHandler
|
||||||
|
|
||||||
routeFound : DataSource BuildError Bool
|
routeFound : DataSource Throwable Bool
|
||||||
routeFound =
|
routeFound =
|
||||||
preBuiltMatches
|
preBuiltMatches
|
||||||
|> DataSource.map (List.member matches)
|
|> DataSource.map (List.member matches)
|
||||||
@ -431,20 +431,20 @@ capture (ApiRouteBuilder patterns pattern previousHandler toString constructor)
|
|||||||
|
|
||||||
{-| For internal use by generated code. Not so useful in user-land.
|
{-| For internal use by generated code. Not so useful in user-land.
|
||||||
-}
|
-}
|
||||||
getBuildTimeRoutes : ApiRoute response -> DataSource BuildError (List String)
|
getBuildTimeRoutes : ApiRoute response -> DataSource Throwable (List String)
|
||||||
getBuildTimeRoutes (ApiRoute handler) =
|
getBuildTimeRoutes (ApiRoute handler) =
|
||||||
handler.buildTimeRoutes
|
handler.buildTimeRoutes
|
||||||
|
|
||||||
|
|
||||||
{-| Include head tags on every page's HTML.
|
{-| Include head tags on every page's HTML.
|
||||||
-}
|
-}
|
||||||
withGlobalHeadTags : DataSource BuildError (List Head.Tag) -> ApiRoute response -> ApiRoute response
|
withGlobalHeadTags : DataSource Throwable (List Head.Tag) -> ApiRoute response -> ApiRoute response
|
||||||
withGlobalHeadTags globalHeadTags (ApiRoute handler) =
|
withGlobalHeadTags globalHeadTags (ApiRoute handler) =
|
||||||
ApiRoute { handler | globalHeadTags = Just globalHeadTags }
|
ApiRoute { handler | globalHeadTags = Just globalHeadTags }
|
||||||
|
|
||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
getGlobalHeadTagsDataSource : ApiRoute response -> Maybe (DataSource BuildError (List Head.Tag))
|
getGlobalHeadTagsDataSource : ApiRoute response -> Maybe (DataSource Throwable (List Head.Tag))
|
||||||
getGlobalHeadTagsDataSource (ApiRoute handler) =
|
getGlobalHeadTagsDataSource (ApiRoute handler) =
|
||||||
handler.globalHeadTags
|
handler.globalHeadTags
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ module DataSource exposing
|
|||||||
, andThen, resolve, combine
|
, andThen, resolve, combine
|
||||||
, andMap
|
, andMap
|
||||||
, map2, map3, map4, map5, map6, map7, map8, map9
|
, map2, map3, map4, map5, map6, map7, map8, map9
|
||||||
, mapError, onError
|
, catch, mapError, onError, throw
|
||||||
)
|
)
|
||||||
|
|
||||||
{-| In an `elm-pages` app, each Route Module can define a value `data` which is a `DataSource` that will be resolved **before** `init` is called. That means it is also available
|
{-| In an `elm-pages` app, each Route Module can define a value `data` which is a `DataSource` that will be resolved **before** `init` is called. That means it is also available
|
||||||
@ -82,6 +82,7 @@ Any place in your `elm-pages` app where the framework lets you pass in a value o
|
|||||||
-}
|
-}
|
||||||
|
|
||||||
import Dict
|
import Dict
|
||||||
|
import Exception exposing (Catchable(..), Throwable)
|
||||||
import Pages.StaticHttpRequest exposing (RawRequest(..))
|
import Pages.StaticHttpRequest exposing (RawRequest(..))
|
||||||
|
|
||||||
|
|
||||||
@ -524,3 +525,20 @@ map9 combineFn request1 request2 request3 request4 request5 request6 request7 re
|
|||||||
|> map2 (|>) request7
|
|> map2 (|>) request7
|
||||||
|> map2 (|>) request8
|
|> map2 (|>) request8
|
||||||
|> map2 (|>) request9
|
|> map2 (|>) request9
|
||||||
|
|
||||||
|
|
||||||
|
catch : DataSource (Catchable error) value -> DataSource error value
|
||||||
|
catch ds =
|
||||||
|
ds
|
||||||
|
|> onError
|
||||||
|
(\exception ->
|
||||||
|
case exception of
|
||||||
|
Catchable error string ->
|
||||||
|
fail error
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
throw : DataSource (Catchable error) data -> DataSource Throwable data
|
||||||
|
throw dataSource =
|
||||||
|
dataSource
|
||||||
|
|> onError (Exception.throw >> fail)
|
||||||
|
@ -35,6 +35,7 @@ import BuildError exposing (BuildError)
|
|||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Http
|
import DataSource.Http
|
||||||
import DataSource.Internal.Request
|
import DataSource.Internal.Request
|
||||||
|
import Exception exposing (Catchable)
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
import Json.Encode as Encode
|
import Json.Encode as Encode
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ toBuildError (MissingEnvVariable errorName) =
|
|||||||
|
|
||||||
{-| Get an environment variable, or a DataSource failure if there is no environment variable matching that name.
|
{-| Get an environment variable, or a DataSource failure if there is no environment variable matching that name.
|
||||||
-}
|
-}
|
||||||
expect : String -> DataSource Error String
|
expect : String -> DataSource (Catchable Error) String
|
||||||
expect envVariableName =
|
expect envVariableName =
|
||||||
envVariableName
|
envVariableName
|
||||||
|> get
|
|> get
|
||||||
@ -73,5 +74,5 @@ expect envVariableName =
|
|||||||
maybeValue
|
maybeValue
|
||||||
|> Result.fromMaybe ("DataSource.Env.expect was expecting a variable `" ++ envVariableName ++ "` but couldn't find a variable with that name.")
|
|> Result.fromMaybe ("DataSource.Env.expect was expecting a variable `" ++ envVariableName ++ "` but couldn't find a variable with that name.")
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|> DataSource.onError (\_ -> DataSource.fail (MissingEnvVariable envVariableName))
|
|> DataSource.onError (\_ -> DataSource.fail (Exception.Catchable (MissingEnvVariable envVariableName) "TODO"))
|
||||||
)
|
)
|
||||||
|
@ -47,6 +47,7 @@ import BuildError exposing (BuildError)
|
|||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Http
|
import DataSource.Http
|
||||||
import DataSource.Internal.Request
|
import DataSource.Internal.Request
|
||||||
|
import Exception exposing (Catchable, Throwable)
|
||||||
import Json.Decode as Decode exposing (Decoder)
|
import Json.Decode as Decode exposing (Decoder)
|
||||||
|
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ It's common to parse the body with a markdown parser or other format.
|
|||||||
)
|
)
|
||||||
|
|
||||||
-}
|
-}
|
||||||
bodyWithFrontmatter : (String -> Decoder frontmatter) -> String -> DataSource (FileReadError Decode.Error) frontmatter
|
bodyWithFrontmatter : (String -> Decoder frontmatter) -> String -> DataSource (Catchable (FileReadError Decode.Error)) frontmatter
|
||||||
bodyWithFrontmatter frontmatterDecoder filePath =
|
bodyWithFrontmatter frontmatterDecoder filePath =
|
||||||
read filePath
|
read filePath
|
||||||
(body
|
(body
|
||||||
@ -206,7 +207,7 @@ the [`DataSource`](DataSource) API along with [`DataSource.Glob`](DataSource-Glo
|
|||||||
|> DataSource.resolve
|
|> DataSource.resolve
|
||||||
|
|
||||||
-}
|
-}
|
||||||
onlyFrontmatter : Decoder frontmatter -> String -> DataSource (FileReadError Decode.Error) frontmatter
|
onlyFrontmatter : Decoder frontmatter -> String -> DataSource (Catchable (FileReadError Decode.Error)) frontmatter
|
||||||
onlyFrontmatter frontmatterDecoder filePath =
|
onlyFrontmatter frontmatterDecoder filePath =
|
||||||
read filePath
|
read filePath
|
||||||
(frontmatter frontmatterDecoder)
|
(frontmatter frontmatterDecoder)
|
||||||
@ -233,7 +234,7 @@ Hey there! This is my first post :)
|
|||||||
Then data will yield the value `"Hey there! This is my first post :)"`.
|
Then data will yield the value `"Hey there! This is my first post :)"`.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
bodyWithoutFrontmatter : String -> DataSource (FileReadError decoderError) String
|
bodyWithoutFrontmatter : String -> DataSource (Catchable (FileReadError decoderError)) String
|
||||||
bodyWithoutFrontmatter filePath =
|
bodyWithoutFrontmatter filePath =
|
||||||
read filePath
|
read filePath
|
||||||
body
|
body
|
||||||
@ -257,7 +258,7 @@ You could read a file called `hello.txt` in your root project directory like thi
|
|||||||
File.rawFile "hello.txt"
|
File.rawFile "hello.txt"
|
||||||
|
|
||||||
-}
|
-}
|
||||||
rawFile : String -> DataSource (FileReadError decoderError) String
|
rawFile : String -> DataSource (Catchable (FileReadError decoderError)) String
|
||||||
rawFile filePath =
|
rawFile filePath =
|
||||||
read filePath (Decode.field "rawFile" Decode.string)
|
read filePath (Decode.field "rawFile" Decode.string)
|
||||||
|
|
||||||
@ -285,7 +286,7 @@ The Decode will strip off any unused JSON data.
|
|||||||
"elm.json"
|
"elm.json"
|
||||||
|
|
||||||
-}
|
-}
|
||||||
jsonFile : Decoder a -> String -> DataSource (FileReadError Decode.Error) a
|
jsonFile : Decoder a -> String -> DataSource (Catchable (FileReadError Decode.Error)) a
|
||||||
jsonFile jsonFileDecoder filePath =
|
jsonFile jsonFileDecoder filePath =
|
||||||
rawFile filePath
|
rawFile filePath
|
||||||
|> DataSource.onError (\foo -> Debug.todo "TODO: Not handled yet")
|
|> DataSource.onError (\foo -> Debug.todo "TODO: Not handled yet")
|
||||||
@ -294,8 +295,8 @@ jsonFile jsonFileDecoder filePath =
|
|||||||
jsonString
|
jsonString
|
||||||
|> Decode.decodeString jsonFileDecoder
|
|> Decode.decodeString jsonFileDecoder
|
||||||
|> Result.mapError DecodingError
|
|> Result.mapError DecodingError
|
||||||
--|> Result.mapError Decode.errorToString
|
|
||||||
|> DataSource.fromResult
|
|> DataSource.fromResult
|
||||||
|
|> DataSource.onError (\error -> DataSource.fail <| Exception.Catchable error "TODO error message here")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -306,7 +307,7 @@ body =
|
|||||||
Decode.field "withoutFrontmatter" Decode.string
|
Decode.field "withoutFrontmatter" Decode.string
|
||||||
|
|
||||||
|
|
||||||
read : String -> Decoder a -> DataSource (FileReadError error) a
|
read : String -> Decoder a -> DataSource (Catchable (FileReadError error)) a
|
||||||
read filePath decoder =
|
read filePath decoder =
|
||||||
DataSource.Internal.Request.request
|
DataSource.Internal.Request.request
|
||||||
{ name = "read-file"
|
{ name = "read-file"
|
||||||
@ -321,6 +322,7 @@ read filePath decoder =
|
|||||||
}
|
}
|
||||||
|> DataSource.onError (\_ -> Debug.todo "TODO: not handled")
|
|> DataSource.onError (\_ -> Debug.todo "TODO: not handled")
|
||||||
|> DataSource.andThen DataSource.fromResult
|
|> DataSource.andThen DataSource.fromResult
|
||||||
|
|> DataSource.onError (\error -> DataSource.fail <| Exception.Catchable error "TODO error message here")
|
||||||
|
|
||||||
|
|
||||||
errorDecoder : Decoder (FileReadError decoding)
|
errorDecoder : Decoder (FileReadError decoding)
|
||||||
|
@ -229,6 +229,7 @@ import DataSource exposing (DataSource)
|
|||||||
import DataSource.Http
|
import DataSource.Http
|
||||||
import DataSource.Internal.Glob exposing (Glob(..))
|
import DataSource.Internal.Glob exposing (Glob(..))
|
||||||
import DataSource.Internal.Request
|
import DataSource.Internal.Request
|
||||||
|
import Exception exposing (Catchable, Throwable)
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
import Json.Encode as Encode
|
import Json.Encode as Encode
|
||||||
import List.Extra
|
import List.Extra
|
||||||
@ -1053,7 +1054,7 @@ so it's ideal to make this kind of assertion rather than having fallback behavio
|
|||||||
issues (like if we had instead ignored the case where there are two or more matching blog post files).
|
issues (like if we had instead ignored the case where there are two or more matching blog post files).
|
||||||
|
|
||||||
-}
|
-}
|
||||||
expectUniqueMatch : Glob a -> DataSource String a
|
expectUniqueMatch : Glob a -> DataSource (Catchable String) a
|
||||||
expectUniqueMatch glob =
|
expectUniqueMatch glob =
|
||||||
glob
|
glob
|
||||||
|> toDataSource
|
|> toDataSource
|
||||||
@ -1064,10 +1065,16 @@ expectUniqueMatch glob =
|
|||||||
DataSource.succeed file
|
DataSource.succeed file
|
||||||
|
|
||||||
[] ->
|
[] ->
|
||||||
DataSource.fail <| "No files matched the pattern: " ++ toPatternString glob
|
DataSource.fail <|
|
||||||
|
Exception.fromStringWithValue
|
||||||
|
("No files matched the pattern: " ++ toPatternString glob)
|
||||||
|
("No files matched the pattern: " ++ toPatternString glob)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
DataSource.fail "More than one file matched."
|
DataSource.fail <|
|
||||||
|
Exception.fromStringWithValue
|
||||||
|
"More than one file matched."
|
||||||
|
"More than one file matched."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ import Bytes exposing (Bytes)
|
|||||||
import Bytes.Decode
|
import Bytes.Decode
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
|
import Exception exposing (Catchable)
|
||||||
import Json.Decode
|
import Json.Decode
|
||||||
import Json.Encode as Encode
|
import Json.Encode as Encode
|
||||||
import Pages.Internal.StaticHttpBody as Body
|
import Pages.Internal.StaticHttpBody as Body
|
||||||
@ -126,7 +127,7 @@ type alias Body =
|
|||||||
get :
|
get :
|
||||||
String
|
String
|
||||||
-> Json.Decode.Decoder a
|
-> Json.Decode.Decoder a
|
||||||
-> DataSource Pages.StaticHttpRequest.Error a
|
-> DataSource (Catchable Pages.StaticHttpRequest.Error) a
|
||||||
get url decoder =
|
get url decoder =
|
||||||
request
|
request
|
||||||
((\okUrl ->
|
((\okUrl ->
|
||||||
@ -253,7 +254,7 @@ expectToString expect =
|
|||||||
request :
|
request :
|
||||||
RequestDetails
|
RequestDetails
|
||||||
-> Expect a
|
-> Expect a
|
||||||
-> DataSource Pages.StaticHttpRequest.Error a
|
-> DataSource (Catchable Pages.StaticHttpRequest.Error) a
|
||||||
request request__ expect =
|
request request__ expect =
|
||||||
let
|
let
|
||||||
request_ : HashRequest.Request
|
request_ : HashRequest.Request
|
||||||
@ -272,7 +273,7 @@ request request__ expect =
|
|||||||
uncachedRequest :
|
uncachedRequest :
|
||||||
RequestDetails
|
RequestDetails
|
||||||
-> Expect a
|
-> Expect a
|
||||||
-> DataSource Pages.StaticHttpRequest.Error a
|
-> DataSource (Catchable Pages.StaticHttpRequest.Error) a
|
||||||
uncachedRequest request__ expect =
|
uncachedRequest request__ expect =
|
||||||
let
|
let
|
||||||
request_ : HashRequest.Request
|
request_ : HashRequest.Request
|
||||||
@ -294,7 +295,7 @@ with this as a low-level detail, or you can use functions like [DataSource.Http.
|
|||||||
requestRaw :
|
requestRaw :
|
||||||
HashRequest.Request
|
HashRequest.Request
|
||||||
-> Expect a
|
-> Expect a
|
||||||
-> DataSource Pages.StaticHttpRequest.Error a
|
-> DataSource (Catchable Pages.StaticHttpRequest.Error) a
|
||||||
requestRaw request__ expect =
|
requestRaw request__ expect =
|
||||||
let
|
let
|
||||||
request_ : HashRequest.Request
|
request_ : HashRequest.Request
|
||||||
@ -406,6 +407,7 @@ requestRaw request__ expect =
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> toResult
|
|> toResult
|
||||||
|
|> DataSource.mapError (\error -> Exception.Catchable error "TODO - error message here")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
module Exception exposing (Catchable(..), Throwable, fromString, fromStringWithValue, throw)
|
||||||
|
|
||||||
|
|
||||||
|
type alias Throwable =
|
||||||
|
Catchable ()
|
||||||
|
|
||||||
|
|
||||||
|
type Catchable error
|
||||||
|
= Catchable error String
|
||||||
|
|
||||||
|
|
||||||
|
fromString : String -> Catchable ()
|
||||||
|
fromString string =
|
||||||
|
Catchable () string
|
||||||
|
|
||||||
|
|
||||||
|
fromStringWithValue : String -> value -> Catchable value
|
||||||
|
fromStringWithValue string value =
|
||||||
|
Catchable value string
|
||||||
|
|
||||||
|
|
||||||
|
throw : Catchable error -> Catchable ()
|
||||||
|
throw exception =
|
||||||
|
case exception of
|
||||||
|
Catchable error string ->
|
||||||
|
Catchable () string
|
@ -8,8 +8,8 @@ module Internal.ApiRoute exposing
|
|||||||
, withRoutes
|
, withRoutes
|
||||||
)
|
)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Json.Decode
|
import Json.Decode
|
||||||
import Pattern exposing (Pattern)
|
import Pattern exposing (Pattern)
|
||||||
@ -46,12 +46,12 @@ tryMatchDone path (ApiRoute handler) =
|
|||||||
type ApiRoute response
|
type ApiRoute response
|
||||||
= ApiRoute
|
= ApiRoute
|
||||||
{ regex : Regex
|
{ regex : Regex
|
||||||
, matchesToResponse : Json.Decode.Value -> String -> DataSource BuildError (Maybe response)
|
, matchesToResponse : Json.Decode.Value -> String -> DataSource Throwable (Maybe response)
|
||||||
, buildTimeRoutes : DataSource BuildError (List String)
|
, buildTimeRoutes : DataSource Throwable (List String)
|
||||||
, handleRoute : String -> DataSource BuildError Bool
|
, handleRoute : String -> DataSource Throwable Bool
|
||||||
, pattern : Pattern
|
, pattern : Pattern
|
||||||
, kind : String
|
, kind : String
|
||||||
, globalHeadTags : Maybe (DataSource BuildError (List Head.Tag))
|
, globalHeadTags : Maybe (DataSource Throwable (List Head.Tag))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import Bytes.Encode
|
|||||||
import Codec
|
import Codec
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Dict
|
import Dict
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head exposing (Tag)
|
import Head exposing (Tag)
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
import HtmlPrinter
|
import HtmlPrinter
|
||||||
@ -50,7 +51,7 @@ currentCompatibilityKey =
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
type alias Model route =
|
type alias Model route =
|
||||||
{ staticResponses : DataSource BuildError Effect
|
{ staticResponses : DataSource Throwable Effect
|
||||||
, errors : List BuildError
|
, errors : List BuildError
|
||||||
, allRawResponses : RequestsAndPending
|
, allRawResponses : RequestsAndPending
|
||||||
, maybeRequestJson : RenderRequest route
|
, maybeRequestJson : RenderRequest route
|
||||||
@ -414,11 +415,11 @@ initLegacy :
|
|||||||
-> ( Model route, Effect )
|
-> ( Model route, Effect )
|
||||||
initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as renderRequest) { isDevServer } config =
|
initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as renderRequest) { isDevServer } config =
|
||||||
let
|
let
|
||||||
globalHeadTags : DataSource BuildError (List Tag)
|
globalHeadTags : DataSource Throwable (List Tag)
|
||||||
globalHeadTags =
|
globalHeadTags =
|
||||||
(config.globalHeadTags |> Maybe.withDefault (\_ -> DataSource.succeed [])) HtmlPrinter.htmlToString
|
(config.globalHeadTags |> Maybe.withDefault (\_ -> DataSource.succeed [])) HtmlPrinter.htmlToString
|
||||||
|
|
||||||
staticResponsesNew : DataSource BuildError Effect
|
staticResponsesNew : DataSource Throwable Effect
|
||||||
staticResponsesNew =
|
staticResponsesNew =
|
||||||
StaticResponses.renderApiRequest
|
StaticResponses.renderApiRequest
|
||||||
(case singleRequest of
|
(case singleRequest of
|
||||||
|
@ -3,20 +3,21 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), batchUpda
|
|||||||
import BuildError exposing (BuildError)
|
import BuildError exposing (BuildError)
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Dict
|
import Dict
|
||||||
|
import Exception exposing (Catchable(..), Throwable)
|
||||||
import List.Extra
|
import List.Extra
|
||||||
import Pages.StaticHttp.Request as HashRequest
|
import Pages.StaticHttp.Request as HashRequest
|
||||||
import Pages.StaticHttpRequest as StaticHttpRequest
|
import Pages.StaticHttpRequest as StaticHttpRequest
|
||||||
import RequestsAndPending exposing (RequestsAndPending)
|
import RequestsAndPending exposing (RequestsAndPending)
|
||||||
|
|
||||||
|
|
||||||
empty : a -> DataSource BuildError a
|
empty : a -> DataSource Throwable a
|
||||||
empty a =
|
empty a =
|
||||||
DataSource.succeed a
|
DataSource.succeed a
|
||||||
|
|
||||||
|
|
||||||
renderApiRequest :
|
renderApiRequest :
|
||||||
DataSource BuildError response
|
DataSource Throwable response
|
||||||
-> DataSource BuildError response
|
-> DataSource Throwable response
|
||||||
renderApiRequest request =
|
renderApiRequest request =
|
||||||
request
|
request
|
||||||
|
|
||||||
@ -49,21 +50,21 @@ batchUpdate newEntries model =
|
|||||||
|
|
||||||
|
|
||||||
type NextStep route value
|
type NextStep route value
|
||||||
= Continue (List HashRequest.Request) (StaticHttpRequest.RawRequest BuildError value)
|
= Continue (List HashRequest.Request) (StaticHttpRequest.RawRequest Throwable value)
|
||||||
| Finish value
|
| Finish value
|
||||||
| FinishedWithErrors (List BuildError)
|
| FinishedWithErrors (List BuildError)
|
||||||
|
|
||||||
|
|
||||||
nextStep :
|
nextStep :
|
||||||
{ model
|
{ model
|
||||||
| staticResponses : DataSource BuildError a
|
| staticResponses : DataSource Throwable a
|
||||||
, errors : List BuildError
|
, errors : List BuildError
|
||||||
, allRawResponses : RequestsAndPending
|
, allRawResponses : RequestsAndPending
|
||||||
}
|
}
|
||||||
-> NextStep route a
|
-> NextStep route a
|
||||||
nextStep ({ allRawResponses, errors } as model) =
|
nextStep ({ allRawResponses, errors } as model) =
|
||||||
let
|
let
|
||||||
staticRequestsStatus : StaticHttpRequest.Status BuildError a
|
staticRequestsStatus : StaticHttpRequest.Status Throwable a
|
||||||
staticRequestsStatus =
|
staticRequestsStatus =
|
||||||
allRawResponses
|
allRawResponses
|
||||||
|> StaticHttpRequest.cacheRequestResolution model.staticResponses
|
|> StaticHttpRequest.cacheRequestResolution model.staticResponses
|
||||||
@ -88,7 +89,7 @@ nextStep ({ allRawResponses, errors } as model) =
|
|||||||
StaticHttpRequest.HasPermanentError _ ->
|
StaticHttpRequest.HasPermanentError _ ->
|
||||||
( ( False, Nothing )
|
( ( False, Nothing )
|
||||||
, []
|
, []
|
||||||
, DataSource.fail (BuildError.internal "TODO this shouldn't happen")
|
, DataSource.fail (Exception.fromString "TODO this shouldn't happen")
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
if pendingRequests then
|
if pendingRequests then
|
||||||
@ -136,9 +137,9 @@ nextStep ({ allRawResponses, errors } as model) =
|
|||||||
Just (Ok completed) ->
|
Just (Ok completed) ->
|
||||||
Finish completed
|
Finish completed
|
||||||
|
|
||||||
Just (Err buildError) ->
|
Just (Err (Catchable () buildError)) ->
|
||||||
FinishedWithErrors
|
FinishedWithErrors
|
||||||
[ buildError
|
[ buildError |> BuildError.internal
|
||||||
]
|
]
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
|
@ -64,11 +64,11 @@ You pass your `Pages.Manifest.Config` record into the `Pages.application` functi
|
|||||||
-}
|
-}
|
||||||
|
|
||||||
import ApiRoute
|
import ApiRoute
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Color exposing (Color)
|
import Color exposing (Color)
|
||||||
import Color.Convert
|
import Color.Convert
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
import Json.Encode as Encode
|
import Json.Encode as Encode
|
||||||
import LanguageTag exposing (LanguageTag, emptySubtags)
|
import LanguageTag exposing (LanguageTag, emptySubtags)
|
||||||
@ -345,7 +345,7 @@ nonEmptyList list =
|
|||||||
|
|
||||||
{-| A generator for Api.elm to include a manifest.json.
|
{-| A generator for Api.elm to include a manifest.json.
|
||||||
-}
|
-}
|
||||||
generator : String -> DataSource BuildError Config -> ApiRoute.ApiRoute ApiRoute.Response
|
generator : String -> DataSource Throwable Config -> ApiRoute.ApiRoute ApiRoute.Response
|
||||||
generator canonicalSiteUrl config =
|
generator canonicalSiteUrl config =
|
||||||
ApiRoute.succeed
|
ApiRoute.succeed
|
||||||
(config
|
(config
|
||||||
|
@ -2,12 +2,12 @@ module Pages.ProgramConfig exposing (ProgramConfig)
|
|||||||
|
|
||||||
import ApiRoute
|
import ApiRoute
|
||||||
import Browser.Navigation
|
import Browser.Navigation
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import Bytes exposing (Bytes)
|
import Bytes exposing (Bytes)
|
||||||
import Bytes.Decode
|
import Bytes.Decode
|
||||||
import Bytes.Encode
|
import Bytes.Encode
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Form.FormData exposing (FormData)
|
import Form.FormData exposing (FormData)
|
||||||
import Head
|
import Head
|
||||||
import Html exposing (Html)
|
import Html exposing (Html)
|
||||||
@ -49,9 +49,9 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|||||||
-> ( userModel, effect )
|
-> ( userModel, effect )
|
||||||
, update : Pages.FormState.PageFormState -> Dict String (Pages.Transition.FetcherState actionData) -> Maybe Pages.Transition.Transition -> sharedData -> pageData -> Maybe Browser.Navigation.Key -> userMsg -> userModel -> ( userModel, effect )
|
, update : Pages.FormState.PageFormState -> Dict String (Pages.Transition.FetcherState actionData) -> Maybe Pages.Transition.Transition -> sharedData -> pageData -> Maybe Browser.Navigation.Key -> userMsg -> userModel -> ( userModel, effect )
|
||||||
, subscriptions : route -> Path -> userModel -> Sub userMsg
|
, subscriptions : route -> Path -> userModel -> Sub userMsg
|
||||||
, sharedData : DataSource BuildError sharedData
|
, sharedData : DataSource Throwable sharedData
|
||||||
, data : Decode.Value -> route -> DataSource BuildError (PageServerResponse pageData errorPage)
|
, data : Decode.Value -> route -> DataSource Throwable (PageServerResponse pageData errorPage)
|
||||||
, action : Decode.Value -> route -> DataSource BuildError (PageServerResponse actionData errorPage)
|
, action : Decode.Value -> route -> DataSource Throwable (PageServerResponse actionData errorPage)
|
||||||
, onActionData : actionData -> Maybe userMsg
|
, onActionData : actionData -> Maybe userMsg
|
||||||
, view :
|
, view :
|
||||||
Pages.FormState.PageFormState
|
Pages.FormState.PageFormState
|
||||||
@ -69,8 +69,8 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|||||||
{ view : userModel -> { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
|
{ view : userModel -> { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
|
||||||
, head : List Head.Tag
|
, head : List Head.Tag
|
||||||
}
|
}
|
||||||
, handleRoute : route -> DataSource BuildError (Maybe NotFoundReason)
|
, handleRoute : route -> DataSource Throwable (Maybe NotFoundReason)
|
||||||
, getStaticRoutes : DataSource BuildError (List route)
|
, getStaticRoutes : DataSource Throwable (List route)
|
||||||
, urlToRoute : Url -> route
|
, urlToRoute : Url -> route
|
||||||
, routeToPath : route -> List String
|
, routeToPath : route -> List String
|
||||||
, site : Maybe SiteConfig
|
, site : Maybe SiteConfig
|
||||||
@ -102,7 +102,7 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|||||||
, encodeResponse : ResponseSketch pageData actionData sharedData -> Bytes.Encode.Encoder
|
, encodeResponse : ResponseSketch pageData actionData sharedData -> Bytes.Encode.Encoder
|
||||||
, encodeAction : actionData -> Bytes.Encode.Encoder
|
, encodeAction : actionData -> Bytes.Encode.Encoder
|
||||||
, decodeResponse : Bytes.Decode.Decoder (ResponseSketch pageData actionData sharedData)
|
, decodeResponse : Bytes.Decode.Decoder (ResponseSketch pageData actionData sharedData)
|
||||||
, globalHeadTags : Maybe ((Maybe { indent : Int, newLines : Bool } -> Html Never -> String) -> DataSource BuildError (List Head.Tag))
|
, globalHeadTags : Maybe ((Maybe { indent : Int, newLines : Bool } -> Html Never -> String) -> DataSource Throwable (List Head.Tag))
|
||||||
, cmdToEffect : Cmd userMsg -> effect
|
, cmdToEffect : Cmd userMsg -> effect
|
||||||
, perform :
|
, perform :
|
||||||
{ fetchRouteData :
|
{ fetchRouteData :
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module Pages.SiteConfig exposing (SiteConfig)
|
module Pages.SiteConfig exposing (SiteConfig)
|
||||||
|
|
||||||
import BuildError exposing (BuildError)
|
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
|
import Exception exposing (Throwable)
|
||||||
import Head
|
import Head
|
||||||
|
|
||||||
|
|
||||||
type alias SiteConfig =
|
type alias SiteConfig =
|
||||||
{ canonicalUrl : String
|
{ canonicalUrl : String
|
||||||
, head : DataSource BuildError (List Head.Tag)
|
, head : DataSource Throwable (List Head.Tag)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user