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