elm-pages 3.0.0-beta.4 → 3.0.0-beta.40
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/README.md +10 -1
- package/adapter/netlify.js +207 -0
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2678 -2725
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +17004 -13817
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/dead-code-review/elm.json +9 -7
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
- 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/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +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 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25025 -21739
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/review/elm.json +10 -10
- package/generator/src/RouteBuilder.elm +115 -109
- package/generator/src/SharedTemplate.elm +3 -2
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +209 -92
- package/generator/src/cli.js +292 -88
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +43 -26
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +176 -138
- package/generator/src/dir-helpers.js +9 -26
- package/generator/src/elm-codegen.js +5 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +12 -11
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +23 -23
- package/generator/src/init.js +9 -8
- package/generator/src/pre-render-html.js +39 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +25 -28
- package/generator/src/render.js +321 -142
- package/generator/src/request-cache.js +265 -162
- package/generator/src/resolve-elm-module.js +64 -0
- package/generator/src/rewrite-client-elm-json.js +6 -5
- package/generator/src/rewrite-elm-json-help.js +56 -0
- package/generator/src/rewrite-elm-json.js +17 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +12 -7
- package/generator/src/vite-utils.js +77 -0
- package/generator/static-code/elm-pages.js +10 -0
- package/generator/static-code/hmr.js +79 -13
- package/generator/template/app/Api.elm +6 -5
- package/generator/template/app/Effect.elm +123 -0
- package/generator/template/app/ErrorPage.elm +37 -6
- package/generator/template/app/Route/Index.elm +17 -10
- package/generator/template/app/Shared.elm +24 -47
- package/generator/template/app/Site.elm +19 -6
- package/generator/template/app/View.elm +1 -8
- package/generator/template/elm-tooling.json +0 -3
- package/generator/template/elm.json +32 -24
- package/generator/template/package.json +10 -4
- package/package.json +30 -27
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +325 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +171 -56
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +679 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +69 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +537 -0
- package/src/FatalError.elm +90 -0
- package/src/Head.elm +237 -7
- package/src/HtmlPrinter.elm +7 -3
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Msg.elm +93 -0
- package/src/Pages/Internal/Platform/Cli.elm +612 -763
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +379 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +65 -276
- package/src/Pages/Internal/Platform/ToJsPayload.elm +6 -9
- package/src/Pages/Internal/Platform.elm +327 -194
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +29 -4
- package/src/Pages/PageUrl.elm +23 -9
- package/src/Pages/ProgramConfig.elm +26 -15
- package/src/Pages/Script.elm +109 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -99
- package/src/Pages/Transition.elm +12 -3
- package/src/PagesMsg.elm +82 -0
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +21 -172
- package/src/RequestsAndPending.elm +37 -20
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +546 -0
- package/src/Scaffold/Route.elm +1402 -0
- package/src/Server/Request.elm +73 -72
- package/src/Server/Session.elm +62 -42
- package/src/Server/SetCookie.elm +12 -4
- package/src/Stub.elm +53 -0
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/DataSource/Env.elm +0 -38
- package/src/DataSource/Http.elm +0 -446
- package/src/DataSource/Internal/Request.elm +0 -20
- package/src/DataSource/Port.elm +0 -90
- package/src/DataSource.elm +0 -538
- package/src/Form/Field.elm +0 -717
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -417
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1683
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -256
- package/src/Pages/Generate.elm +0 -800
- package/src/Pages/Internal/Form.elm +0 -17
- package/src/Pages/Msg.elm +0 -79
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Pages.Internal.Script exposing (Script(..))
|
|
2
|
+
|
|
3
|
+
import BackendTask exposing (BackendTask)
|
|
4
|
+
import Cli.Program as Program
|
|
5
|
+
import FatalError exposing (FatalError)
|
|
6
|
+
import Html exposing (Html)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
{-| -}
|
|
10
|
+
type Script
|
|
11
|
+
= Script
|
|
12
|
+
((Maybe { indent : Int, newLines : Bool }
|
|
13
|
+
-> Html Never
|
|
14
|
+
-> String
|
|
15
|
+
)
|
|
16
|
+
-> Program.Config (BackendTask FatalError ())
|
|
17
|
+
)
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module Pages.Internal.StaticHttpBody exposing (Body(..), codec, encode)
|
|
2
2
|
|
|
3
|
+
import Base64
|
|
4
|
+
import Bytes exposing (Bytes)
|
|
3
5
|
import Codec exposing (Codec)
|
|
6
|
+
import Json.Decode
|
|
4
7
|
import Json.Encode as Encode
|
|
5
8
|
|
|
6
9
|
|
|
@@ -8,6 +11,7 @@ type Body
|
|
|
8
11
|
= EmptyBody
|
|
9
12
|
| StringBody String String
|
|
10
13
|
| JsonBody Encode.Value
|
|
14
|
+
| BytesBody String Bytes
|
|
11
15
|
|
|
12
16
|
|
|
13
17
|
encode : Body -> Encode.Value
|
|
@@ -26,6 +30,15 @@ encode body =
|
|
|
26
30
|
[ ( "content", content )
|
|
27
31
|
]
|
|
28
32
|
|
|
33
|
+
BytesBody _ content ->
|
|
34
|
+
encodeWithType "bytes"
|
|
35
|
+
[ ( "content"
|
|
36
|
+
, Base64.fromBytes content
|
|
37
|
+
|> Maybe.withDefault ""
|
|
38
|
+
|> Encode.string
|
|
39
|
+
)
|
|
40
|
+
]
|
|
41
|
+
|
|
29
42
|
|
|
30
43
|
encodeWithType : String -> List ( String, Encode.Value ) -> Encode.Value
|
|
31
44
|
encodeWithType typeName otherFields =
|
|
@@ -37,7 +50,7 @@ encodeWithType typeName otherFields =
|
|
|
37
50
|
codec : Codec Body
|
|
38
51
|
codec =
|
|
39
52
|
Codec.custom
|
|
40
|
-
(\vEmpty vString vJson value ->
|
|
53
|
+
(\vEmpty vString vJson vBytes value ->
|
|
41
54
|
case value of
|
|
42
55
|
EmptyBody ->
|
|
43
56
|
vEmpty
|
|
@@ -47,8 +60,29 @@ codec =
|
|
|
47
60
|
|
|
48
61
|
JsonBody body ->
|
|
49
62
|
vJson body
|
|
63
|
+
|
|
64
|
+
BytesBody contentType body ->
|
|
65
|
+
vBytes contentType body
|
|
50
66
|
)
|
|
51
67
|
|> Codec.variant0 "EmptyBody" EmptyBody
|
|
52
68
|
|> Codec.variant2 "StringBody" StringBody Codec.string Codec.string
|
|
53
69
|
|> Codec.variant1 "JsonBody" JsonBody Codec.value
|
|
70
|
+
|> Codec.variant2 "BytesBody" BytesBody Codec.string bytesCodec
|
|
54
71
|
|> Codec.buildCustom
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
bytesCodec : Codec Bytes
|
|
75
|
+
bytesCodec =
|
|
76
|
+
Codec.build (Base64.fromBytes >> Maybe.withDefault "" >> Encode.string)
|
|
77
|
+
(Json.Decode.string
|
|
78
|
+
|> Json.Decode.map Base64.toBytes
|
|
79
|
+
|> Json.Decode.andThen
|
|
80
|
+
(\decodedBytes ->
|
|
81
|
+
case decodedBytes of
|
|
82
|
+
Just bytes ->
|
|
83
|
+
Json.Decode.succeed bytes
|
|
84
|
+
|
|
85
|
+
Nothing ->
|
|
86
|
+
Json.Decode.fail "Couldn't parse bytes."
|
|
87
|
+
)
|
|
88
|
+
)
|
package/src/Pages/Manifest.elm
CHANGED
|
@@ -2,6 +2,7 @@ module Pages.Manifest exposing
|
|
|
2
2
|
( Config, Icon
|
|
3
3
|
, init
|
|
4
4
|
, withBackgroundColor, withCategories, withDisplayMode, withIarcRatingId, withLang, withOrientation, withShortName, withThemeColor
|
|
5
|
+
, withField
|
|
5
6
|
, DisplayMode(..), Orientation(..), IconPurpose(..)
|
|
6
7
|
, generator
|
|
7
8
|
, toJson
|
|
@@ -41,6 +42,11 @@ You pass your `Pages.Manifest.Config` record into the `Pages.application` functi
|
|
|
41
42
|
@docs withBackgroundColor, withCategories, withDisplayMode, withIarcRatingId, withLang, withOrientation, withShortName, withThemeColor
|
|
42
43
|
|
|
43
44
|
|
|
45
|
+
## Arbitrary Fields Escape Hatch
|
|
46
|
+
|
|
47
|
+
@docs withField
|
|
48
|
+
|
|
49
|
+
|
|
44
50
|
## Config options
|
|
45
51
|
|
|
46
52
|
@docs DisplayMode, Orientation, IconPurpose
|
|
@@ -58,9 +64,11 @@ You pass your `Pages.Manifest.Config` record into the `Pages.application` functi
|
|
|
58
64
|
-}
|
|
59
65
|
|
|
60
66
|
import ApiRoute
|
|
67
|
+
import BackendTask exposing (BackendTask)
|
|
61
68
|
import Color exposing (Color)
|
|
62
69
|
import Color.Convert
|
|
63
|
-
import
|
|
70
|
+
import Dict exposing (Dict)
|
|
71
|
+
import FatalError exposing (FatalError)
|
|
64
72
|
import Head
|
|
65
73
|
import Json.Encode as Encode
|
|
66
74
|
import LanguageTag exposing (LanguageTag, emptySubtags)
|
|
@@ -123,6 +131,7 @@ init options =
|
|
|
123
131
|
, shortName = Nothing
|
|
124
132
|
, icons = options.icons
|
|
125
133
|
, lang = usEnglish
|
|
134
|
+
, otherFields = Dict.empty
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
|
|
@@ -191,6 +200,17 @@ withLang languageTag config =
|
|
|
191
200
|
{ config | lang = languageTag }
|
|
192
201
|
|
|
193
202
|
|
|
203
|
+
{-| Escape hatch for specifying fields that aren't exposed through this module otherwise. The possible supported properties
|
|
204
|
+
in a manifest file can change over time, so see [MDN manifest.json docs](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json)
|
|
205
|
+
for a full listing of the current supported properties.
|
|
206
|
+
-}
|
|
207
|
+
withField : String -> Encode.Value -> Config -> Config
|
|
208
|
+
withField name value config =
|
|
209
|
+
{ config
|
|
210
|
+
| otherFields = config.otherFields |> Dict.insert name value
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
194
214
|
orientationToString : Orientation -> String
|
|
195
215
|
orientationToString orientation =
|
|
196
216
|
case orientation of
|
|
@@ -239,6 +259,7 @@ type alias Config =
|
|
|
239
259
|
, shortName : Maybe String
|
|
240
260
|
, icons : List Icon
|
|
241
261
|
, lang : LanguageTag
|
|
262
|
+
, otherFields : Dict String Encode.Value
|
|
242
263
|
}
|
|
243
264
|
|
|
244
265
|
|
|
@@ -324,16 +345,16 @@ nonEmptyList list =
|
|
|
324
345
|
|
|
325
346
|
{-| A generator for Api.elm to include a manifest.json.
|
|
326
347
|
-}
|
|
327
|
-
generator : String ->
|
|
348
|
+
generator : String -> BackendTask FatalError Config -> ApiRoute.ApiRoute ApiRoute.Response
|
|
328
349
|
generator canonicalSiteUrl config =
|
|
329
350
|
ApiRoute.succeed
|
|
330
351
|
(config
|
|
331
|
-
|>
|
|
352
|
+
|> BackendTask.map (toJson canonicalSiteUrl >> Encode.encode 0)
|
|
332
353
|
)
|
|
333
354
|
|> ApiRoute.literal "manifest.json"
|
|
334
355
|
|> ApiRoute.single
|
|
335
356
|
|> ApiRoute.withGlobalHeadTags
|
|
336
|
-
(
|
|
357
|
+
(BackendTask.succeed
|
|
337
358
|
[ Head.manifestLink "/manifest.json"
|
|
338
359
|
]
|
|
339
360
|
)
|
|
@@ -420,6 +441,10 @@ toJson canonicalSiteUrl config =
|
|
|
420
441
|
, Encode.string "/" |> Just
|
|
421
442
|
)
|
|
422
443
|
]
|
|
444
|
+
++ (config.otherFields
|
|
445
|
+
|> Dict.toList
|
|
446
|
+
|> List.map (Tuple.mapSecond Just)
|
|
447
|
+
)
|
|
423
448
|
|> encodeMaybeObject
|
|
424
449
|
|
|
425
450
|
|
package/src/Pages/PageUrl.elm
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
module Pages.PageUrl exposing
|
|
1
|
+
module Pages.PageUrl exposing
|
|
2
|
+
( PageUrl, toUrl
|
|
3
|
+
, parseQueryParams
|
|
4
|
+
)
|
|
2
5
|
|
|
3
|
-
{-| Same as a Url in `elm/url`, but slightly more structured. The path portion of the URL is parsed into a
|
|
4
|
-
the query params
|
|
5
|
-
|
|
6
|
-
Because `elm-pages` takes care of the main routing for pages in your app, the standard Elm URL parser API isn't suited
|
|
7
|
-
to parsing query params individually, which is why the structure of these types is different.
|
|
6
|
+
{-| Same as a Url in `elm/url`, but slightly more structured. The path portion of the URL is parsed into a `List String` representing each segment, and
|
|
7
|
+
the query params are parsed into a `Dict String (List String)`.
|
|
8
8
|
|
|
9
9
|
@docs PageUrl, toUrl
|
|
10
10
|
|
|
11
|
+
@docs parseQueryParams
|
|
12
|
+
|
|
11
13
|
-}
|
|
12
14
|
|
|
15
|
+
import Dict exposing (Dict)
|
|
13
16
|
import Path exposing (Path)
|
|
14
|
-
import QueryParams
|
|
17
|
+
import QueryParams
|
|
15
18
|
import Url
|
|
16
19
|
|
|
17
20
|
|
|
@@ -21,7 +24,7 @@ type alias PageUrl =
|
|
|
21
24
|
, host : String
|
|
22
25
|
, port_ : Maybe Int
|
|
23
26
|
, path : Path
|
|
24
|
-
, query :
|
|
27
|
+
, query : Dict String (List String)
|
|
25
28
|
, fragment : Maybe String
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -33,6 +36,17 @@ toUrl url =
|
|
|
33
36
|
, host = url.host
|
|
34
37
|
, port_ = url.port_
|
|
35
38
|
, path = url.path |> Path.toRelative
|
|
36
|
-
, query =
|
|
39
|
+
, query =
|
|
40
|
+
if url.query |> Dict.isEmpty then
|
|
41
|
+
Nothing
|
|
42
|
+
|
|
43
|
+
else
|
|
44
|
+
url.query |> QueryParams.toString |> Just
|
|
37
45
|
, fragment = url.fragment
|
|
38
46
|
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
{-| -}
|
|
50
|
+
parseQueryParams : String -> Dict String (List String)
|
|
51
|
+
parseQueryParams =
|
|
52
|
+
QueryParams.fromString
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
module Pages.ProgramConfig exposing (ProgramConfig)
|
|
1
|
+
module Pages.ProgramConfig exposing (FormData, ProgramConfig)
|
|
2
2
|
|
|
3
3
|
import ApiRoute
|
|
4
|
+
import BackendTask exposing (BackendTask)
|
|
4
5
|
import Browser.Navigation
|
|
5
6
|
import Bytes exposing (Bytes)
|
|
6
7
|
import Bytes.Decode
|
|
7
8
|
import Bytes.Encode
|
|
8
|
-
import DataSource exposing (DataSource)
|
|
9
9
|
import Dict exposing (Dict)
|
|
10
|
-
import
|
|
10
|
+
import FatalError exposing (FatalError)
|
|
11
|
+
import Form
|
|
11
12
|
import Head
|
|
12
13
|
import Html exposing (Html)
|
|
13
14
|
import Http
|
|
@@ -16,15 +17,14 @@ import Json.Encode
|
|
|
16
17
|
import PageServerResponse exposing (PageServerResponse)
|
|
17
18
|
import Pages.Fetcher
|
|
18
19
|
import Pages.Flags
|
|
19
|
-
import Pages.FormState
|
|
20
20
|
import Pages.Internal.NotFoundReason exposing (NotFoundReason)
|
|
21
21
|
import Pages.Internal.Platform.ToJsPayload
|
|
22
22
|
import Pages.Internal.ResponseSketch exposing (ResponseSketch)
|
|
23
23
|
import Pages.Internal.RoutePattern exposing (RoutePattern)
|
|
24
|
-
import Pages.Msg
|
|
25
24
|
import Pages.PageUrl exposing (PageUrl)
|
|
26
25
|
import Pages.SiteConfig exposing (SiteConfig)
|
|
27
26
|
import Pages.Transition
|
|
27
|
+
import PagesMsg exposing (PagesMsg)
|
|
28
28
|
import Path exposing (Path)
|
|
29
29
|
import Url exposing (Url)
|
|
30
30
|
|
|
@@ -46,14 +46,14 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
46
46
|
, pageUrl : Maybe PageUrl
|
|
47
47
|
}
|
|
48
48
|
-> ( userModel, effect )
|
|
49
|
-
, update :
|
|
49
|
+
, update : Form.Model -> Dict String (Pages.Transition.FetcherState actionData) -> Maybe Pages.Transition.Transition -> sharedData -> pageData -> Maybe Browser.Navigation.Key -> userMsg -> userModel -> ( userModel, effect )
|
|
50
50
|
, subscriptions : route -> Path -> userModel -> Sub userMsg
|
|
51
|
-
, sharedData :
|
|
52
|
-
, data : route ->
|
|
53
|
-
, action : route ->
|
|
51
|
+
, sharedData : BackendTask FatalError sharedData
|
|
52
|
+
, data : Decode.Value -> route -> BackendTask FatalError (PageServerResponse pageData errorPage)
|
|
53
|
+
, action : Decode.Value -> route -> BackendTask FatalError (PageServerResponse actionData errorPage)
|
|
54
54
|
, onActionData : actionData -> Maybe userMsg
|
|
55
55
|
, view :
|
|
56
|
-
|
|
56
|
+
Form.Model
|
|
57
57
|
-> Dict String (Pages.Transition.FetcherState actionData)
|
|
58
58
|
-> Maybe Pages.Transition.Transition
|
|
59
59
|
->
|
|
@@ -65,11 +65,11 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
65
65
|
-> pageData
|
|
66
66
|
-> Maybe actionData
|
|
67
67
|
->
|
|
68
|
-
{ view : userModel -> { title : String, body : List (Html (
|
|
68
|
+
{ view : userModel -> { title : String, body : List (Html (PagesMsg userMsg)) }
|
|
69
69
|
, head : List Head.Tag
|
|
70
70
|
}
|
|
71
|
-
, handleRoute : route ->
|
|
72
|
-
, getStaticRoutes :
|
|
71
|
+
, handleRoute : route -> BackendTask FatalError (Maybe NotFoundReason)
|
|
72
|
+
, getStaticRoutes : BackendTask FatalError (List route)
|
|
73
73
|
, urlToRoute : Url -> route
|
|
74
74
|
, routeToPath : route -> List String
|
|
75
75
|
, site : Maybe SiteConfig
|
|
@@ -88,7 +88,10 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
88
88
|
}
|
|
89
89
|
-> userMsg
|
|
90
90
|
, apiRoutes :
|
|
91
|
-
(
|
|
91
|
+
(Maybe { indent : Int, newLines : Bool }
|
|
92
|
+
-> Html Never
|
|
93
|
+
-> String
|
|
94
|
+
)
|
|
92
95
|
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
|
93
96
|
, pathPatterns : List RoutePattern
|
|
94
97
|
, basePath : List String
|
|
@@ -98,7 +101,7 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
98
101
|
, encodeResponse : ResponseSketch pageData actionData sharedData -> Bytes.Encode.Encoder
|
|
99
102
|
, encodeAction : actionData -> Bytes.Encode.Encoder
|
|
100
103
|
, decodeResponse : Bytes.Decode.Decoder (ResponseSketch pageData actionData sharedData)
|
|
101
|
-
, globalHeadTags : Maybe ((Html Never -> String) ->
|
|
104
|
+
, globalHeadTags : Maybe ((Maybe { indent : Int, newLines : Bool } -> Html Never -> String) -> BackendTask FatalError (List Head.Tag))
|
|
102
105
|
, cmdToEffect : Cmd userMsg -> effect
|
|
103
106
|
, perform :
|
|
104
107
|
{ fetchRouteData :
|
|
@@ -124,3 +127,11 @@ type alias ProgramConfig userMsg userModel route pageData actionData sharedData
|
|
|
124
127
|
, errorPageToData : errorPage -> pageData
|
|
125
128
|
, notFoundRoute : route
|
|
126
129
|
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
type alias FormData =
|
|
133
|
+
{ fields : List ( String, String )
|
|
134
|
+
, method : Form.Method
|
|
135
|
+
, action : String
|
|
136
|
+
, id : Maybe String
|
|
137
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
module Pages.Script exposing
|
|
2
|
+
( Script
|
|
3
|
+
, withCliOptions, withoutCliOptions
|
|
4
|
+
, writeFile
|
|
5
|
+
, log
|
|
6
|
+
, Error(..)
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
{-|
|
|
10
|
+
|
|
11
|
+
@docs Script
|
|
12
|
+
|
|
13
|
+
@docs withCliOptions, withoutCliOptions
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## File System Utilities
|
|
17
|
+
|
|
18
|
+
@docs writeFile
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Utilities
|
|
22
|
+
|
|
23
|
+
@docs log
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Errors
|
|
27
|
+
|
|
28
|
+
@docs Error
|
|
29
|
+
|
|
30
|
+
-}
|
|
31
|
+
|
|
32
|
+
import BackendTask exposing (BackendTask)
|
|
33
|
+
import BackendTask.Http
|
|
34
|
+
import BackendTask.Internal.Request
|
|
35
|
+
import Cli.OptionsParser as OptionsParser
|
|
36
|
+
import Cli.Program as Program
|
|
37
|
+
import FatalError exposing (FatalError)
|
|
38
|
+
import Json.Decode as Decode
|
|
39
|
+
import Json.Encode as Encode
|
|
40
|
+
import Pages.Internal.Script
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
{-| -}
|
|
44
|
+
type alias Script =
|
|
45
|
+
Pages.Internal.Script.Script
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
{-| -}
|
|
49
|
+
type Error
|
|
50
|
+
= --TODO make more descriptive
|
|
51
|
+
FileWriteError
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
{-| -}
|
|
55
|
+
writeFile : { path : String, body : String } -> BackendTask { fatal : FatalError, recoverable : Error } ()
|
|
56
|
+
writeFile { path, body } =
|
|
57
|
+
BackendTask.Internal.Request.request
|
|
58
|
+
{ name = "write-file"
|
|
59
|
+
, body =
|
|
60
|
+
BackendTask.Http.jsonBody
|
|
61
|
+
(Encode.object
|
|
62
|
+
[ ( "path", Encode.string path )
|
|
63
|
+
, ( "body", Encode.string body )
|
|
64
|
+
]
|
|
65
|
+
)
|
|
66
|
+
, expect =
|
|
67
|
+
-- TODO decode possible error details here
|
|
68
|
+
BackendTask.Http.expectJson (Decode.succeed ())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
{-| -}
|
|
73
|
+
log : String -> BackendTask error ()
|
|
74
|
+
log message =
|
|
75
|
+
BackendTask.Internal.Request.request
|
|
76
|
+
{ name = "log"
|
|
77
|
+
, body =
|
|
78
|
+
BackendTask.Http.jsonBody
|
|
79
|
+
(Encode.object
|
|
80
|
+
[ ( "message", Encode.string message )
|
|
81
|
+
]
|
|
82
|
+
)
|
|
83
|
+
, expect = BackendTask.Http.expectJson (Decode.succeed ())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
{-| -}
|
|
88
|
+
withoutCliOptions : BackendTask FatalError () -> Script
|
|
89
|
+
withoutCliOptions execute =
|
|
90
|
+
Pages.Internal.Script.Script
|
|
91
|
+
(\_ ->
|
|
92
|
+
Program.config
|
|
93
|
+
|> Program.add
|
|
94
|
+
(OptionsParser.build ())
|
|
95
|
+
|> Program.mapConfig
|
|
96
|
+
(\() ->
|
|
97
|
+
execute
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
{-| -}
|
|
103
|
+
withCliOptions : Program.Config cliOptions -> (cliOptions -> BackendTask FatalError ()) -> Script
|
|
104
|
+
withCliOptions config execute =
|
|
105
|
+
Pages.Internal.Script.Script
|
|
106
|
+
(\_ ->
|
|
107
|
+
config
|
|
108
|
+
|> Program.mapConfig execute
|
|
109
|
+
)
|
package/src/Pages/SiteConfig.elm
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
module Pages.SiteConfig exposing (SiteConfig)
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import BackendTask exposing (BackendTask)
|
|
4
|
+
import FatalError exposing (FatalError)
|
|
4
5
|
import Head
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
type alias SiteConfig =
|
|
8
9
|
{ canonicalUrl : String
|
|
9
|
-
, head :
|
|
10
|
+
, head : BackendTask FatalError (List Head.Tag)
|
|
10
11
|
}
|
|
@@ -11,7 +11,7 @@ type alias Request =
|
|
|
11
11
|
, method : String
|
|
12
12
|
, headers : List ( String, String )
|
|
13
13
|
, body : Body
|
|
14
|
-
,
|
|
14
|
+
, cacheOptions : Maybe Encode.Value
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
|
|
@@ -40,5 +40,5 @@ codec =
|
|
|
40
40
|
|> Codec.field "method" .method Codec.string
|
|
41
41
|
|> Codec.field "headers" .headers (Codec.list (Codec.tuple Codec.string Codec.string))
|
|
42
42
|
|> Codec.field "body" .body StaticHttpBody.codec
|
|
43
|
-
|> Codec.
|
|
43
|
+
|> Codec.nullableField "cacheOptions" .cacheOptions Codec.value
|
|
44
44
|
|> Codec.buildObject
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
module Pages.StaticHttpRequest exposing (Error(..), MockResolver, RawRequest(..), Status(..), cacheRequestResolution, mockResolve,
|
|
1
|
+
module Pages.StaticHttpRequest exposing (Error(..), MockResolver, RawRequest(..), Status(..), cacheRequestResolution, mockResolve, toBuildError)
|
|
2
2
|
|
|
3
3
|
import BuildError exposing (BuildError)
|
|
4
|
-
import
|
|
5
|
-
import List.Extra
|
|
4
|
+
import Json.Encode
|
|
6
5
|
import Pages.StaticHttp.Request
|
|
7
6
|
import RequestsAndPending exposing (RequestsAndPending)
|
|
8
7
|
import TerminalText as Terminal
|
|
@@ -13,30 +12,19 @@ type alias MockResolver =
|
|
|
13
12
|
-> Maybe RequestsAndPending.Response
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
type RawRequest value
|
|
17
|
-
= Request (List Pages.StaticHttp.Request.Request) (Maybe MockResolver -> RequestsAndPending -> RawRequest value)
|
|
18
|
-
|
|
|
19
|
-
| ApiRoute value
|
|
15
|
+
type RawRequest error value
|
|
16
|
+
= Request (List Pages.StaticHttp.Request.Request) (Maybe MockResolver -> RequestsAndPending -> RawRequest error value)
|
|
17
|
+
| ApiRoute (Result error value)
|
|
20
18
|
|
|
21
19
|
|
|
22
20
|
type Error
|
|
23
|
-
=
|
|
24
|
-
| DecoderError String
|
|
21
|
+
= DecoderError String
|
|
25
22
|
| UserCalledStaticHttpFail String
|
|
26
23
|
|
|
27
24
|
|
|
28
25
|
toBuildError : String -> Error -> BuildError
|
|
29
26
|
toBuildError path error =
|
|
30
27
|
case error of
|
|
31
|
-
MissingHttpResponse missingKey _ ->
|
|
32
|
-
{ title = "Missing Http Response"
|
|
33
|
-
, message =
|
|
34
|
-
[ Terminal.text missingKey
|
|
35
|
-
]
|
|
36
|
-
, path = path
|
|
37
|
-
, fatal = True
|
|
38
|
-
}
|
|
39
|
-
|
|
40
28
|
DecoderError decodeErrorMessage ->
|
|
41
29
|
{ title = "Static Http Decoding Error"
|
|
42
30
|
, message =
|
|
@@ -49,107 +37,43 @@ toBuildError path error =
|
|
|
49
37
|
UserCalledStaticHttpFail decodeErrorMessage ->
|
|
50
38
|
{ title = "Called Static Http Fail"
|
|
51
39
|
, message =
|
|
52
|
-
[ Terminal.text <| "I ran into a call to `
|
|
40
|
+
[ Terminal.text <| "I ran into a call to `BackendTask.fail` with message: " ++ decodeErrorMessage
|
|
53
41
|
]
|
|
54
42
|
, path = path
|
|
55
43
|
, fatal = True
|
|
56
44
|
}
|
|
57
45
|
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
resolve request rawResponses =
|
|
61
|
-
case request of
|
|
62
|
-
RequestError error ->
|
|
63
|
-
Err error
|
|
64
|
-
|
|
65
|
-
Request _ lookupFn ->
|
|
66
|
-
case lookupFn Nothing rawResponses of
|
|
67
|
-
nextRequest ->
|
|
68
|
-
resolve nextRequest rawResponses
|
|
69
|
-
|
|
70
|
-
ApiRoute value ->
|
|
71
|
-
Ok value
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
mockResolve : RawRequest value -> MockResolver -> Result Error value
|
|
47
|
+
mockResolve : RawRequest error value -> MockResolver -> Result error value
|
|
75
48
|
mockResolve request mockResolver =
|
|
76
49
|
case request of
|
|
77
|
-
RequestError error ->
|
|
78
|
-
Err error
|
|
79
|
-
|
|
80
50
|
Request _ lookupFn ->
|
|
81
|
-
case lookupFn (Just mockResolver)
|
|
51
|
+
case lookupFn (Just mockResolver) (Json.Encode.object []) of
|
|
82
52
|
nextRequest ->
|
|
83
53
|
mockResolve nextRequest mockResolver
|
|
84
54
|
|
|
85
55
|
ApiRoute value ->
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
resolveUrls : RawRequest value -> RequestsAndPending -> List Pages.StaticHttp.Request.Request
|
|
90
|
-
resolveUrls request rawResponses =
|
|
91
|
-
resolveUrlsHelp rawResponses [] request
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
resolveUrlsHelp : RequestsAndPending -> List Pages.StaticHttp.Request.Request -> RawRequest value -> List Pages.StaticHttp.Request.Request
|
|
95
|
-
resolveUrlsHelp rawResponses soFar request =
|
|
96
|
-
case request of
|
|
97
|
-
RequestError error ->
|
|
98
|
-
case error of
|
|
99
|
-
MissingHttpResponse _ next ->
|
|
100
|
-
(soFar ++ next)
|
|
101
|
-
|> List.Extra.uniqueBy Pages.StaticHttp.Request.hash
|
|
102
|
-
|
|
103
|
-
_ ->
|
|
104
|
-
soFar
|
|
105
|
-
|
|
106
|
-
Request urlList lookupFn ->
|
|
107
|
-
resolveUrlsHelp
|
|
108
|
-
rawResponses
|
|
109
|
-
(soFar ++ urlList)
|
|
110
|
-
(lookupFn Nothing rawResponses)
|
|
111
|
-
|
|
112
|
-
ApiRoute _ ->
|
|
113
|
-
soFar
|
|
56
|
+
value
|
|
114
57
|
|
|
115
58
|
|
|
116
59
|
cacheRequestResolution :
|
|
117
|
-
RawRequest value
|
|
60
|
+
RawRequest error value
|
|
118
61
|
-> RequestsAndPending
|
|
119
|
-
-> Status value
|
|
62
|
+
-> Status error value
|
|
120
63
|
cacheRequestResolution request rawResponses =
|
|
121
|
-
cacheRequestResolutionHelp [] rawResponses request
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
type Status value
|
|
125
|
-
= Incomplete (List Pages.StaticHttp.Request.Request)
|
|
126
|
-
| HasPermanentError Error
|
|
127
|
-
| Complete
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
cacheRequestResolutionHelp :
|
|
131
|
-
List Pages.StaticHttp.Request.Request
|
|
132
|
-
-> RequestsAndPending
|
|
133
|
-
-> RawRequest value
|
|
134
|
-
-> Status value
|
|
135
|
-
cacheRequestResolutionHelp foundUrls rawResponses request =
|
|
136
64
|
case request of
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
-- TODO do I need to pass through continuation URLs here? -- Incomplete (urlList ++ foundUrls)
|
|
141
|
-
Incomplete foundUrls
|
|
65
|
+
Request urlList lookupFn ->
|
|
66
|
+
if List.isEmpty urlList then
|
|
67
|
+
cacheRequestResolution (lookupFn Nothing rawResponses) rawResponses
|
|
142
68
|
|
|
143
|
-
|
|
144
|
-
|
|
69
|
+
else
|
|
70
|
+
Incomplete urlList (Request [] lookupFn)
|
|
145
71
|
|
|
146
|
-
|
|
147
|
-
|
|
72
|
+
ApiRoute value ->
|
|
73
|
+
Complete value
|
|
148
74
|
|
|
149
|
-
Request urlList lookupFn ->
|
|
150
|
-
cacheRequestResolutionHelp urlList
|
|
151
|
-
rawResponses
|
|
152
|
-
(lookupFn Nothing rawResponses)
|
|
153
75
|
|
|
154
|
-
|
|
155
|
-
|
|
76
|
+
type Status error value
|
|
77
|
+
= Incomplete (List Pages.StaticHttp.Request.Request) (RawRequest error value)
|
|
78
|
+
| HasPermanentError Error
|
|
79
|
+
| Complete (Result error value)
|
package/src/Pages/Transition.elm
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module Pages.Transition exposing
|
|
2
|
-
( Transition(..), LoadingState(..), map
|
|
2
|
+
( Transition(..), LoadingState(..), map, FormData
|
|
3
3
|
, FetcherState, FetcherSubmitStatus(..)
|
|
4
4
|
)
|
|
5
5
|
|
|
6
6
|
{-|
|
|
7
7
|
|
|
8
|
-
@docs Transition, LoadingState, map
|
|
8
|
+
@docs Transition, LoadingState, map, FormData
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
## Fetchers
|
|
@@ -14,11 +14,20 @@ module Pages.Transition exposing
|
|
|
14
14
|
|
|
15
15
|
-}
|
|
16
16
|
|
|
17
|
-
import Form
|
|
17
|
+
import Form
|
|
18
18
|
import Path exposing (Path)
|
|
19
19
|
import Time
|
|
20
20
|
|
|
21
21
|
|
|
22
|
+
{-| -}
|
|
23
|
+
type alias FormData =
|
|
24
|
+
{ fields : List ( String, String )
|
|
25
|
+
, method : Form.Method
|
|
26
|
+
, action : String
|
|
27
|
+
, id : Maybe String
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
22
31
|
{-| -}
|
|
23
32
|
type Transition
|
|
24
33
|
= Submitting FormData
|