elm-pages 2.1.10 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/{template/public/style.css → review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock} +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +6795 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +27617 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +110 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +187 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/package.json +1 -0
- package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +26 -0
- package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +62 -0
- package/generator/review/elm.json +13 -4
- package/{src → generator/review/src}/Pages/Review/NoContractViolations.elm +148 -148
- package/generator/review/tests/Pages/Review/NoContractViolationsTest.elm +331 -0
- package/generator/src/RouteBuilder.elm +420 -0
- package/generator/src/SharedTemplate.elm +4 -5
- package/generator/src/SiteConfig.elm +3 -9
- package/generator/src/build.js +308 -95
- package/generator/src/cli.js +103 -8
- package/generator/src/codegen.js +192 -35
- package/generator/src/compile-elm.js +183 -31
- package/generator/src/dev-server.js +353 -96
- package/generator/src/elm-application.json +3 -1
- package/generator/src/elm-codegen.js +34 -0
- package/generator/src/elm-file-constants.js +2 -0
- package/generator/src/error-formatter.js +20 -1
- package/generator/src/generate-template-module-connector.js +120 -924
- package/generator/src/hello.ts +5 -0
- package/generator/src/pre-render-html.js +58 -104
- package/generator/src/render-worker.js +27 -13
- package/generator/src/render.js +252 -197
- package/generator/src/request-cache-fs.js +18 -0
- package/generator/src/request-cache.js +128 -56
- package/generator/src/rewrite-client-elm-json.js +49 -0
- package/generator/src/route-codegen-helpers.js +62 -1
- package/generator/static-code/dev-style.css +22 -0
- package/generator/static-code/elm-pages.js +43 -39
- package/generator/static-code/hmr.js +98 -88
- package/generator/template/app/Api.elm +25 -0
- package/generator/template/app/ErrorPage.elm +38 -0
- package/generator/template/app/Route/Index.elm +87 -0
- package/generator/template/{src → app}/Shared.elm +34 -13
- package/generator/template/app/Site.elm +19 -0
- package/generator/template/{src → app}/View.elm +0 -0
- package/generator/template/elm-pages.config.mjs +5 -0
- package/generator/template/elm.json +14 -5
- package/generator/template/{public/index.js → index.ts} +7 -3
- package/generator/template/package.json +5 -5
- package/generator/template/public/favicon.ico +0 -0
- package/generator/template/public/images/icon-png.png +0 -0
- package/generator/template/src/.gitkeep +0 -0
- package/generator/template/style.css +4 -0
- package/package.json +30 -23
- package/src/ApiRoute.elm +176 -43
- package/src/BuildError.elm +10 -1
- package/src/CookieParser.elm +84 -0
- package/src/DataSource/Env.elm +38 -0
- package/src/DataSource/File.elm +27 -16
- package/src/DataSource/Glob.elm +126 -80
- package/src/DataSource/Http.elm +283 -304
- package/src/DataSource/Internal/Glob.elm +5 -21
- package/src/DataSource/Internal/Request.elm +25 -0
- package/src/DataSource/Port.elm +17 -14
- package/src/DataSource.elm +55 -318
- package/src/Form/Field.elm +717 -0
- package/src/Form/FieldStatus.elm +36 -0
- package/src/Form/FieldView.elm +417 -0
- package/src/Form/FormData.elm +22 -0
- package/src/Form/Validation.elm +391 -0
- package/src/Form/Value.elm +118 -0
- package/src/Form.elm +1683 -0
- package/src/FormData.elm +58 -0
- package/src/FormDecoder.elm +102 -0
- package/src/Head/Seo.elm +12 -4
- package/src/Head.elm +12 -2
- package/src/HtmlPrinter.elm +1 -1
- package/src/Internal/ApiRoute.elm +17 -4
- package/src/Internal/Request.elm +7 -0
- package/src/PageServerResponse.elm +68 -0
- package/src/Pages/ContentCache.elm +1 -229
- package/src/Pages/Fetcher.elm +58 -0
- package/src/Pages/FormState.elm +256 -0
- package/src/Pages/Generate.elm +800 -0
- package/src/Pages/Internal/Form.elm +17 -0
- package/src/Pages/Internal/NotFoundReason.elm +3 -55
- package/src/Pages/Internal/Platform/Cli.elm +777 -579
- package/src/Pages/Internal/Platform/Effect.elm +5 -5
- package/src/Pages/Internal/Platform/StaticResponses.elm +178 -394
- package/src/Pages/Internal/Platform/ToJsPayload.elm +24 -23
- package/src/Pages/Internal/Platform.elm +1244 -504
- package/src/Pages/Internal/ResponseSketch.elm +19 -0
- package/src/Pages/Internal/RoutePattern.elm +596 -45
- package/src/Pages/Manifest.elm +26 -0
- package/src/Pages/Msg.elm +79 -0
- package/src/Pages/ProgramConfig.elm +67 -14
- package/src/Pages/SiteConfig.elm +3 -6
- package/src/Pages/StaticHttp/Request.elm +4 -2
- package/src/Pages/StaticHttpRequest.elm +50 -215
- package/src/Pages/Transition.elm +70 -0
- package/src/Path.elm +1 -0
- package/src/Pattern.elm +98 -0
- package/src/RenderRequest.elm +2 -2
- package/src/RequestsAndPending.elm +111 -9
- package/src/Server/Request.elm +1253 -0
- package/src/Server/Response.elm +292 -0
- package/src/Server/Session.elm +316 -0
- package/src/Server/SetCookie.elm +169 -0
- package/src/TerminalText.elm +1 -1
- package/src/Test/Html/Internal/ElmHtml/Markdown.elm +0 -1
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +1 -1
- package/generator/src/Page.elm +0 -359
- package/generator/src/codegen-template-module.js +0 -183
- package/generator/src/elm-pages-js-minified.js +0 -1
- package/generator/template/src/Api.elm +0 -14
- package/generator/template/src/Page/Index.elm +0 -69
- package/generator/template/src/Site.elm +0 -41
- package/src/DataSource/ServerRequest.elm +0 -60
- package/src/Internal/OptimizedDecoder.elm +0 -18
- package/src/KeepOrDiscard.elm +0 -6
- package/src/OptimizedDecoder/Pipeline.elm +0 -335
- package/src/OptimizedDecoder.elm +0 -818
- package/src/Pages/Internal/ApplicationType.elm +0 -6
- package/src/Pages/Secrets.elm +0 -83
- package/src/Secrets.elm +0 -111
- package/src/SecretsDict.elm +0 -45
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
module Server.SetCookie exposing
|
|
2
|
+
( SetCookie, SameSite(..)
|
|
3
|
+
, withImmediateExpiration, httpOnly, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
|
|
4
|
+
, toString
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
{-| <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
|
|
8
|
+
|
|
9
|
+
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies>
|
|
10
|
+
|
|
11
|
+
@docs SetCookie, SameSite
|
|
12
|
+
@docs withImmediateExpiration, httpOnly, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
|
|
13
|
+
|
|
14
|
+
@docs toString
|
|
15
|
+
|
|
16
|
+
-}
|
|
17
|
+
|
|
18
|
+
import Time
|
|
19
|
+
import Url
|
|
20
|
+
import Utc
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
{-| -}
|
|
24
|
+
type alias SetCookie =
|
|
25
|
+
{ name : String
|
|
26
|
+
, value : String
|
|
27
|
+
, expiration : Maybe Time.Posix
|
|
28
|
+
, httpOnly : Bool
|
|
29
|
+
, maxAge : Maybe Int
|
|
30
|
+
, path : Maybe String
|
|
31
|
+
, domain : Maybe String
|
|
32
|
+
, secure : Bool
|
|
33
|
+
, sameSite : Maybe SameSite
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
{-| -}
|
|
38
|
+
type SameSite
|
|
39
|
+
= Strict
|
|
40
|
+
| Lax
|
|
41
|
+
| None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
{-| -}
|
|
45
|
+
toString : SetCookie -> String
|
|
46
|
+
toString builder =
|
|
47
|
+
let
|
|
48
|
+
option : String -> Maybe String -> String
|
|
49
|
+
option name maybeValue =
|
|
50
|
+
case maybeValue of
|
|
51
|
+
Just value ->
|
|
52
|
+
"; " ++ name ++ "=" ++ value
|
|
53
|
+
|
|
54
|
+
Nothing ->
|
|
55
|
+
""
|
|
56
|
+
|
|
57
|
+
boolOption : String -> Bool -> String
|
|
58
|
+
boolOption name bool =
|
|
59
|
+
if bool then
|
|
60
|
+
"; " ++ name
|
|
61
|
+
|
|
62
|
+
else
|
|
63
|
+
""
|
|
64
|
+
in
|
|
65
|
+
builder.name
|
|
66
|
+
++ "="
|
|
67
|
+
++ Url.percentEncode builder.value
|
|
68
|
+
++ option "Expires" (builder.expiration |> Maybe.map Utc.fromTime)
|
|
69
|
+
++ option "Max-Age" (builder.maxAge |> Maybe.map String.fromInt)
|
|
70
|
+
++ option "Path" builder.path
|
|
71
|
+
++ option "Domain" builder.domain
|
|
72
|
+
++ option "SameSite" (builder.sameSite |> Maybe.map sameSiteToString)
|
|
73
|
+
++ boolOption "HttpOnly" builder.httpOnly
|
|
74
|
+
++ boolOption "Secure" builder.secure
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
sameSiteToString : SameSite -> String
|
|
78
|
+
sameSiteToString sameSite =
|
|
79
|
+
case sameSite of
|
|
80
|
+
Strict ->
|
|
81
|
+
"Strict"
|
|
82
|
+
|
|
83
|
+
Lax ->
|
|
84
|
+
"Lax"
|
|
85
|
+
|
|
86
|
+
None ->
|
|
87
|
+
"None"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
{-| -}
|
|
91
|
+
setCookie : String -> String -> SetCookie
|
|
92
|
+
setCookie name value =
|
|
93
|
+
{ name = name
|
|
94
|
+
, value = value
|
|
95
|
+
, expiration = Nothing
|
|
96
|
+
, httpOnly = False
|
|
97
|
+
, maxAge = Nothing
|
|
98
|
+
, path = Nothing
|
|
99
|
+
, domain = Nothing
|
|
100
|
+
, secure = True
|
|
101
|
+
, sameSite = Nothing
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
{-| -}
|
|
106
|
+
withExpiration : Time.Posix -> SetCookie -> SetCookie
|
|
107
|
+
withExpiration time builder =
|
|
108
|
+
{ builder
|
|
109
|
+
| expiration = Just time
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
{-| -}
|
|
114
|
+
withImmediateExpiration : SetCookie -> SetCookie
|
|
115
|
+
withImmediateExpiration builder =
|
|
116
|
+
{ builder
|
|
117
|
+
| expiration = Just (Time.millisToPosix 0)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
{-| -}
|
|
122
|
+
httpOnly : SetCookie -> SetCookie
|
|
123
|
+
httpOnly builder =
|
|
124
|
+
{ builder
|
|
125
|
+
| httpOnly = True
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
{-| -}
|
|
130
|
+
withMaxAge : Int -> SetCookie -> SetCookie
|
|
131
|
+
withMaxAge maxAge builder =
|
|
132
|
+
{ builder
|
|
133
|
+
| maxAge = Just maxAge
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
{-| -}
|
|
138
|
+
withPath : String -> SetCookie -> SetCookie
|
|
139
|
+
withPath path builder =
|
|
140
|
+
{ builder
|
|
141
|
+
| path = Just path
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
{-| -}
|
|
146
|
+
withDomain : String -> SetCookie -> SetCookie
|
|
147
|
+
withDomain domain builder =
|
|
148
|
+
{ builder
|
|
149
|
+
| domain = Just domain
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
{-| Secure (only sent over https, or localhost on http) is the default. This overrides that and
|
|
154
|
+
removes the `Secure` attribute from the cookie.
|
|
155
|
+
-}
|
|
156
|
+
nonSecure : SetCookie -> SetCookie
|
|
157
|
+
nonSecure builder =
|
|
158
|
+
{ builder
|
|
159
|
+
| secure = False
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
{-| The default SameSite policy is Lax if one is not explicitly set. See the SameSite section in <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes>.
|
|
164
|
+
-}
|
|
165
|
+
withSameSite : SameSite -> SetCookie -> SetCookie
|
|
166
|
+
withSameSite sameSite builder =
|
|
167
|
+
{ builder
|
|
168
|
+
| sameSite = Just sameSite
|
|
169
|
+
}
|
package/src/TerminalText.elm
CHANGED
package/generator/src/Page.elm
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
module Page exposing
|
|
2
|
-
( Builder(..)
|
|
3
|
-
, StaticPayload
|
|
4
|
-
, prerender, single
|
|
5
|
-
, Page, buildNoState
|
|
6
|
-
, PageWithState, buildWithLocalState, buildWithSharedState
|
|
7
|
-
--, serverless, prerenderWithFallback
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
{-|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## Building a Page Module
|
|
14
|
-
|
|
15
|
-
@docs Builder
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## Static Data
|
|
19
|
-
|
|
20
|
-
Every template will have access to a `StaticPayload`.
|
|
21
|
-
|
|
22
|
-
@docs StaticPayload
|
|
23
|
-
|
|
24
|
-
Since this data is _static_, you have access to it before the user has loaded the page, including at build time.
|
|
25
|
-
An example of dynamic data would be keyboard input from the user, query params, or any other data that comes from the app running in the browser.
|
|
26
|
-
|
|
27
|
-
But before the user even requests the page, we have the following data:
|
|
28
|
-
|
|
29
|
-
- `path` - these paths are static. In other words, we know every single path when we build an elm-pages site.
|
|
30
|
-
- `metadata` - we have a decoded Elm value for the page's metadata.
|
|
31
|
-
- `sharedStatic` - we can access any shared data between pages. For example, you may have fetched the name of a blog ("Jane's Blog") from the API for a Content Management System (CMS).
|
|
32
|
-
- `static` - this is the static data for this specific page. If you use `noData`, then this will be `()`, meaning there is no page-specific static data.
|
|
33
|
-
|
|
34
|
-
@docs prerender, single
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## Stateless Page Modules
|
|
38
|
-
|
|
39
|
-
@docs Page, buildNoState
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Stateful Page Modules
|
|
43
|
-
|
|
44
|
-
@docs PageWithState, buildWithLocalState, buildWithSharedState
|
|
45
|
-
|
|
46
|
-
-}
|
|
47
|
-
|
|
48
|
-
--import DataSource.ServerRequest as ServerRequest exposing (ServerRequest)
|
|
49
|
-
|
|
50
|
-
import Browser.Navigation
|
|
51
|
-
import DataSource exposing (DataSource)
|
|
52
|
-
import Head
|
|
53
|
-
import Pages.Internal.NotFoundReason exposing (NotFoundReason)
|
|
54
|
-
import Pages.Internal.RoutePattern exposing (RoutePattern)
|
|
55
|
-
import Pages.PageUrl exposing (PageUrl)
|
|
56
|
-
import Path exposing (Path)
|
|
57
|
-
import Shared
|
|
58
|
-
import View exposing (View)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{-| -}
|
|
62
|
-
type alias PageWithState routeParams templateData templateModel templateMsg =
|
|
63
|
-
{ data : routeParams -> DataSource templateData
|
|
64
|
-
, staticRoutes : DataSource (List routeParams)
|
|
65
|
-
, view :
|
|
66
|
-
Maybe PageUrl
|
|
67
|
-
-> Shared.Model
|
|
68
|
-
-> templateModel
|
|
69
|
-
-> StaticPayload templateData routeParams
|
|
70
|
-
-> View templateMsg
|
|
71
|
-
, head :
|
|
72
|
-
StaticPayload templateData routeParams
|
|
73
|
-
-> List Head.Tag
|
|
74
|
-
, init : Maybe PageUrl -> Shared.Model -> StaticPayload templateData routeParams -> ( templateModel, Cmd templateMsg )
|
|
75
|
-
, update : PageUrl -> StaticPayload templateData routeParams -> Maybe Browser.Navigation.Key -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.Msg )
|
|
76
|
-
, subscriptions : Maybe PageUrl -> routeParams -> Path -> templateModel -> Shared.Model -> Sub templateMsg
|
|
77
|
-
, handleRoute : { moduleName : List String, routePattern : RoutePattern } -> (routeParams -> List ( String, String )) -> routeParams -> DataSource (Maybe NotFoundReason)
|
|
78
|
-
, kind : String
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{-| -}
|
|
83
|
-
type alias Page routeParams data =
|
|
84
|
-
PageWithState routeParams data () Never
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{-| -}
|
|
88
|
-
type alias StaticPayload data routeParams =
|
|
89
|
-
{ data : data
|
|
90
|
-
, sharedData : Shared.Data
|
|
91
|
-
, routeParams : routeParams
|
|
92
|
-
, path : Path
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{-| -}
|
|
97
|
-
type Builder routeParams templateData
|
|
98
|
-
= WithData
|
|
99
|
-
{ data : routeParams -> DataSource templateData
|
|
100
|
-
, staticRoutes : DataSource (List routeParams)
|
|
101
|
-
, head :
|
|
102
|
-
StaticPayload templateData routeParams
|
|
103
|
-
-> List Head.Tag
|
|
104
|
-
, serverless : Bool
|
|
105
|
-
, handleRoute :
|
|
106
|
-
{ moduleName : List String, routePattern : RoutePattern }
|
|
107
|
-
-> (routeParams -> List ( String, String ))
|
|
108
|
-
-> routeParams
|
|
109
|
-
-> DataSource (Maybe NotFoundReason)
|
|
110
|
-
, kind : String
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
{-| -}
|
|
115
|
-
buildNoState :
|
|
116
|
-
{ view :
|
|
117
|
-
Maybe PageUrl
|
|
118
|
-
-> Shared.Model
|
|
119
|
-
-> StaticPayload templateData routeParams
|
|
120
|
-
-> View Never
|
|
121
|
-
}
|
|
122
|
-
-> Builder routeParams templateData
|
|
123
|
-
-> PageWithState routeParams templateData () Never
|
|
124
|
-
buildNoState { view } builderState =
|
|
125
|
-
case builderState of
|
|
126
|
-
WithData record ->
|
|
127
|
-
{ view = \maybePageUrl sharedModel _ -> view maybePageUrl sharedModel
|
|
128
|
-
, head = record.head
|
|
129
|
-
, data = record.data
|
|
130
|
-
, staticRoutes = record.staticRoutes
|
|
131
|
-
, init = \_ _ _ -> ( (), Cmd.none )
|
|
132
|
-
, update = \_ _ _ _ _ _ -> ( (), Cmd.none, Nothing )
|
|
133
|
-
, subscriptions = \_ _ _ _ _ -> Sub.none
|
|
134
|
-
, handleRoute = record.handleRoute
|
|
135
|
-
, kind = record.kind
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
{-| -}
|
|
140
|
-
buildWithLocalState :
|
|
141
|
-
{ view :
|
|
142
|
-
Maybe PageUrl
|
|
143
|
-
-> Shared.Model
|
|
144
|
-
-> templateModel
|
|
145
|
-
-> StaticPayload templateData routeParams
|
|
146
|
-
-> View templateMsg
|
|
147
|
-
, init : Maybe PageUrl -> Shared.Model -> StaticPayload templateData routeParams -> ( templateModel, Cmd templateMsg )
|
|
148
|
-
, update : PageUrl -> Maybe Browser.Navigation.Key -> Shared.Model -> StaticPayload templateData routeParams -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg )
|
|
149
|
-
, subscriptions : Maybe PageUrl -> routeParams -> Path -> templateModel -> Sub templateMsg
|
|
150
|
-
}
|
|
151
|
-
-> Builder routeParams templateData
|
|
152
|
-
-> PageWithState routeParams templateData templateModel templateMsg
|
|
153
|
-
buildWithLocalState config builderState =
|
|
154
|
-
case builderState of
|
|
155
|
-
WithData record ->
|
|
156
|
-
{ view =
|
|
157
|
-
\model sharedModel staticPayload ->
|
|
158
|
-
config.view model sharedModel staticPayload
|
|
159
|
-
, head = record.head
|
|
160
|
-
, data = record.data
|
|
161
|
-
, staticRoutes = record.staticRoutes
|
|
162
|
-
, init = config.init
|
|
163
|
-
, update =
|
|
164
|
-
\pageUrl staticPayload navigationKey msg templateModel sharedModel ->
|
|
165
|
-
let
|
|
166
|
-
( updatedModel, cmd ) =
|
|
167
|
-
config.update
|
|
168
|
-
pageUrl
|
|
169
|
-
navigationKey
|
|
170
|
-
sharedModel
|
|
171
|
-
staticPayload
|
|
172
|
-
msg
|
|
173
|
-
templateModel
|
|
174
|
-
in
|
|
175
|
-
( updatedModel, cmd, Nothing )
|
|
176
|
-
, subscriptions =
|
|
177
|
-
\maybePageUrl routeParams path templateModel sharedModel ->
|
|
178
|
-
config.subscriptions maybePageUrl routeParams path templateModel
|
|
179
|
-
, handleRoute = record.handleRoute
|
|
180
|
-
, kind = record.kind
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
{-| -}
|
|
185
|
-
buildWithSharedState :
|
|
186
|
-
{ view :
|
|
187
|
-
Maybe PageUrl
|
|
188
|
-
-> Shared.Model
|
|
189
|
-
-> templateModel
|
|
190
|
-
-> StaticPayload templateData routeParams
|
|
191
|
-
-> View templateMsg
|
|
192
|
-
, init : Maybe PageUrl -> Shared.Model -> StaticPayload templateData routeParams -> ( templateModel, Cmd templateMsg )
|
|
193
|
-
, update : PageUrl -> Maybe Browser.Navigation.Key -> Shared.Model -> StaticPayload templateData routeParams -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg, Maybe Shared.Msg )
|
|
194
|
-
, subscriptions : Maybe PageUrl -> routeParams -> Path -> templateModel -> Shared.Model -> Sub templateMsg
|
|
195
|
-
}
|
|
196
|
-
-> Builder routeParams templateData
|
|
197
|
-
-> PageWithState routeParams templateData templateModel templateMsg
|
|
198
|
-
buildWithSharedState config builderState =
|
|
199
|
-
case builderState of
|
|
200
|
-
WithData record ->
|
|
201
|
-
{ view = config.view
|
|
202
|
-
, head = record.head
|
|
203
|
-
, data = record.data
|
|
204
|
-
, staticRoutes = record.staticRoutes
|
|
205
|
-
, init = config.init
|
|
206
|
-
, update =
|
|
207
|
-
\pageUrl staticPayload navigationKey msg templateModel sharedModel ->
|
|
208
|
-
config.update pageUrl
|
|
209
|
-
navigationKey
|
|
210
|
-
sharedModel
|
|
211
|
-
staticPayload
|
|
212
|
-
msg
|
|
213
|
-
templateModel
|
|
214
|
-
, subscriptions = config.subscriptions
|
|
215
|
-
, handleRoute = record.handleRoute
|
|
216
|
-
, kind = record.kind
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{-| -}
|
|
221
|
-
single :
|
|
222
|
-
{ data : DataSource data
|
|
223
|
-
, head : StaticPayload data {} -> List Head.Tag
|
|
224
|
-
}
|
|
225
|
-
-> Builder {} data
|
|
226
|
-
single { data, head } =
|
|
227
|
-
WithData
|
|
228
|
-
{ data = \_ -> data
|
|
229
|
-
, staticRoutes = DataSource.succeed [ {} ]
|
|
230
|
-
, head = head
|
|
231
|
-
, serverless = False
|
|
232
|
-
, handleRoute = \_ _ _ -> DataSource.succeed Nothing
|
|
233
|
-
, kind = "static"
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{-| -}
|
|
238
|
-
prerender :
|
|
239
|
-
{ data : routeParams -> DataSource data
|
|
240
|
-
, routes : DataSource (List routeParams)
|
|
241
|
-
, head : StaticPayload data routeParams -> List Head.Tag
|
|
242
|
-
}
|
|
243
|
-
-> Builder routeParams data
|
|
244
|
-
prerender { data, head, routes } =
|
|
245
|
-
WithData
|
|
246
|
-
{ data = data
|
|
247
|
-
, staticRoutes = routes
|
|
248
|
-
, head = head
|
|
249
|
-
, serverless = False
|
|
250
|
-
, handleRoute =
|
|
251
|
-
\moduleContext toRecord routeParams ->
|
|
252
|
-
routes
|
|
253
|
-
|> DataSource.map
|
|
254
|
-
(\allRoutes ->
|
|
255
|
-
if allRoutes |> List.member routeParams then
|
|
256
|
-
Nothing
|
|
257
|
-
|
|
258
|
-
else
|
|
259
|
-
-- TODO pass in toString function, and use a custom one to avoid Debug.toString
|
|
260
|
-
Just <|
|
|
261
|
-
Pages.Internal.NotFoundReason.NotPrerendered
|
|
262
|
-
{ moduleName = moduleContext.moduleName
|
|
263
|
-
, routePattern = moduleContext.routePattern
|
|
264
|
-
, matchedRouteParams = toRecord routeParams
|
|
265
|
-
}
|
|
266
|
-
(allRoutes
|
|
267
|
-
|> List.map toRecord
|
|
268
|
-
)
|
|
269
|
-
)
|
|
270
|
-
, kind = "prerender"
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
--{-| -}
|
|
276
|
-
--prerenderWithFallback :
|
|
277
|
-
-- { data : routeParams -> DataSource data
|
|
278
|
-
-- , routes : DataSource (List routeParams)
|
|
279
|
-
-- , handleFallback : routeParams -> DataSource Bool
|
|
280
|
-
-- , head : StaticPayload data routeParams -> List Head.Tag
|
|
281
|
-
-- }
|
|
282
|
-
-- -> Builder routeParams data
|
|
283
|
-
--prerenderWithFallback { data, head, routes, handleFallback } =
|
|
284
|
-
-- WithData
|
|
285
|
-
-- { data = data
|
|
286
|
-
-- , staticRoutes = routes
|
|
287
|
-
-- , head = head
|
|
288
|
-
-- , serverless = False
|
|
289
|
-
-- , handleRoute =
|
|
290
|
-
-- \moduleContext toRecord routeParams ->
|
|
291
|
-
-- handleFallback routeParams
|
|
292
|
-
-- |> DataSource.andThen
|
|
293
|
-
-- (\handleFallbackResult ->
|
|
294
|
-
-- if handleFallbackResult then
|
|
295
|
-
-- DataSource.succeed Nothing
|
|
296
|
-
--
|
|
297
|
-
-- else
|
|
298
|
-
-- -- we want to lazily evaluate this in our on-demand builders
|
|
299
|
-
-- -- so we try handle fallback first and short-circuit in those cases
|
|
300
|
-
-- -- TODO - we could make an optimization to handle this differently
|
|
301
|
-
-- -- between on-demand builders and the dev server
|
|
302
|
-
-- -- we only need to match the pre-rendered routes in the dev server,
|
|
303
|
-
-- -- not in on-demand builders
|
|
304
|
-
-- routes
|
|
305
|
-
-- |> DataSource.map
|
|
306
|
-
-- (\allRoutes ->
|
|
307
|
-
-- if allRoutes |> List.member routeParams then
|
|
308
|
-
-- Nothing
|
|
309
|
-
--
|
|
310
|
-
-- else
|
|
311
|
-
-- Just <|
|
|
312
|
-
-- NotFoundReason.NotPrerenderedOrHandledByFallback
|
|
313
|
-
-- { moduleName = moduleContext.moduleName
|
|
314
|
-
-- , routePattern = moduleContext.routePattern
|
|
315
|
-
-- , matchedRouteParams = toRecord routeParams
|
|
316
|
-
-- }
|
|
317
|
-
-- (allRoutes
|
|
318
|
-
-- |> List.map toRecord
|
|
319
|
-
-- )
|
|
320
|
-
-- )
|
|
321
|
-
-- )
|
|
322
|
-
-- , kind = "prerender-with-fallback"
|
|
323
|
-
-- }
|
|
324
|
-
--
|
|
325
|
-
--
|
|
326
|
-
--{-| -}
|
|
327
|
-
--serverless :
|
|
328
|
-
-- { data : (ServerRequest decodedRequest -> DataSource decodedRequest) -> routeParams -> DataSource data
|
|
329
|
-
-- , routeFound : routeParams -> DataSource Bool
|
|
330
|
-
-- , head : StaticPayload data routeParams -> List Head.Tag
|
|
331
|
-
-- }
|
|
332
|
-
-- -> Builder routeParams data
|
|
333
|
-
--serverless { data, head, routeFound } =
|
|
334
|
-
-- WithData
|
|
335
|
-
-- { data = data ServerRequest.toStaticHttp
|
|
336
|
-
-- , staticRoutes = DataSource.succeed []
|
|
337
|
-
-- , head = head
|
|
338
|
-
-- , serverless = True
|
|
339
|
-
-- , handleRoute =
|
|
340
|
-
-- \moduleContext toRecord routeParams ->
|
|
341
|
-
-- routeFound routeParams
|
|
342
|
-
-- |> DataSource.map
|
|
343
|
-
-- (\found ->
|
|
344
|
-
-- if found then
|
|
345
|
-
-- Nothing
|
|
346
|
-
--
|
|
347
|
-
-- else
|
|
348
|
-
-- Just
|
|
349
|
-
-- (NotFoundReason.UnhandledServerRoute
|
|
350
|
-
-- { moduleName = moduleContext.moduleName
|
|
351
|
-
-- , routePattern = moduleContext.routePattern
|
|
352
|
-
-- , matchedRouteParams = toRecord routeParams
|
|
353
|
-
-- }
|
|
354
|
-
-- )
|
|
355
|
-
-- )
|
|
356
|
-
-- , kind = "serverless"
|
|
357
|
-
-- }
|
|
358
|
-
--
|
|
359
|
-
--
|