elm-pages 3.0.0-beta.3 → 3.0.0-beta.30
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/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2864 -2589
- 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 +1327 -122
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15295 -13271
- 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 +8 -6
- 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/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 +1327 -122
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14621 -12637
- 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 +8 -8
- package/generator/src/RouteBuilder.elm +113 -107
- 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 +123 -87
- package/generator/src/cli.js +256 -77
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +25 -25
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +150 -133
- 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 -22
- 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 +322 -142
- package/generator/src/request-cache.js +252 -163
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +7 -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/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 +34 -25
- package/generator/template/package.json +10 -4
- package/package.json +23 -22
- 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 +128 -43
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +673 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +28 -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 +89 -0
- package/src/Form/Field.elm +21 -9
- package/src/Form/FieldView.elm +94 -14
- package/src/Form.elm +275 -400
- 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/FormState.elm +6 -5
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Form.elm +21 -1
- package/src/Pages/{Msg.elm → Internal/Msg.elm} +26 -16
- package/src/Pages/Internal/Platform/Cli.elm +507 -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 +373 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Internal/Platform.elm +215 -102
- 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 +14 -10
- 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 -98
- package/src/PagesMsg.elm +92 -0
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +21 -172
- package/src/RequestsAndPending.elm +8 -19
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +484 -0
- package/src/Scaffold/Route.elm +1376 -0
- package/src/Server/Request.elm +43 -37
- package/src/Server/Session.elm +34 -34
- package/src/Server/SetCookie.elm +1 -1
- 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/Pages/Generate.elm +0 -800
package/src/PagesMsg.elm
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module PagesMsg exposing
|
|
2
|
+
( PagesMsg
|
|
3
|
+
, fromMsg
|
|
4
|
+
, map, noOp
|
|
5
|
+
, onSubmit
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
{-| In `elm-pages`, Route modules have their own `Msg` type which can be used like a normal TEA (The Elm Architecture) app.
|
|
9
|
+
But the `Msg` defined in a `Route` module is wrapped in the `PagesMsg` type.
|
|
10
|
+
|
|
11
|
+
@docs PagesMsg
|
|
12
|
+
|
|
13
|
+
You can wrap your Route Module's `Msg` using `fromMsg`.
|
|
14
|
+
|
|
15
|
+
@docs fromMsg
|
|
16
|
+
|
|
17
|
+
@docs map, noOp
|
|
18
|
+
|
|
19
|
+
@docs onSubmit
|
|
20
|
+
|
|
21
|
+
-}
|
|
22
|
+
|
|
23
|
+
import Html exposing (Attribute)
|
|
24
|
+
import Pages.Internal.Msg
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
{-| -}
|
|
28
|
+
type alias PagesMsg userMsg =
|
|
29
|
+
Pages.Internal.Msg.Msg userMsg
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
{-|
|
|
33
|
+
|
|
34
|
+
import PagesMsg exposing (PagesMsg)
|
|
35
|
+
|
|
36
|
+
type Msg
|
|
37
|
+
= ToggleMenu
|
|
38
|
+
|
|
39
|
+
view :
|
|
40
|
+
Maybe PageUrl
|
|
41
|
+
-> Shared.Model
|
|
42
|
+
-> Model
|
|
43
|
+
-> App Data ActionData RouteParams
|
|
44
|
+
-> View (PagesMsg Msg)
|
|
45
|
+
view maybeUrl sharedModel model app =
|
|
46
|
+
{ title = "My Page"
|
|
47
|
+
, view =
|
|
48
|
+
[ button
|
|
49
|
+
-- we need to wrap our Route module's `Msg` here so we have a `PagesMsg Msg`
|
|
50
|
+
[ onClick (PagesMsg.fromMsg ToggleMenu) ]
|
|
51
|
+
[]
|
|
52
|
+
|
|
53
|
+
-- `Form.renderHtml` gives us `Html (PagesMsg msg)`, so we don't need to wrap its Msg type
|
|
54
|
+
, logoutForm
|
|
55
|
+
|> Form.withOnSubmit (\_ -> NewItemSubmitted)
|
|
56
|
+
|> Form.renderHtml "logout" [] (\_ -> Nothing) app Nothing
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
-}
|
|
61
|
+
fromMsg : userMsg -> PagesMsg userMsg
|
|
62
|
+
fromMsg userMsg =
|
|
63
|
+
Pages.Internal.Msg.UserMsg userMsg
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
{-| A Msg that is handled by the elm-pages framework and does nothing. Helpful for when you don't want to register a callback.
|
|
67
|
+
|
|
68
|
+
import Browser.Dom as Dom
|
|
69
|
+
import PagesMsg exposing (PagesMsg)
|
|
70
|
+
import Task
|
|
71
|
+
|
|
72
|
+
resetViewport : Cmd (PagesMsg msg)
|
|
73
|
+
resetViewport =
|
|
74
|
+
Dom.setViewport 0 0
|
|
75
|
+
|> Task.perform (\() -> PagesMsg.noOp)
|
|
76
|
+
|
|
77
|
+
-}
|
|
78
|
+
noOp : PagesMsg userMsg
|
|
79
|
+
noOp =
|
|
80
|
+
Pages.Internal.Msg.NoOp
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
{-| -}
|
|
84
|
+
map : (a -> b) -> PagesMsg a -> PagesMsg b
|
|
85
|
+
map mapFn msg =
|
|
86
|
+
Pages.Internal.Msg.map mapFn msg
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
{-| -}
|
|
90
|
+
onSubmit : Attribute (PagesMsg userMsg)
|
|
91
|
+
onSubmit =
|
|
92
|
+
Pages.Internal.Msg.onSubmit
|
package/src/Path.elm
CHANGED
|
@@ -40,20 +40,25 @@ import Pages.Internal.String exposing (chopEnd, chopStart)
|
|
|
40
40
|
|
|
41
41
|
{-| The path portion of the URL, normalized to ensure that path segments are joined with `/`s in the right places (no doubled up or missing slashes).
|
|
42
42
|
-}
|
|
43
|
-
type Path
|
|
44
|
-
|
|
43
|
+
type alias Path =
|
|
44
|
+
List String
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
{-|
|
|
48
|
-
multi-part path part, like `blog/post-1`.
|
|
47
|
+
{-| Turn a Path to a relative URL.
|
|
49
48
|
-}
|
|
50
|
-
join :
|
|
49
|
+
join : Path -> Path
|
|
51
50
|
join parts =
|
|
52
51
|
parts
|
|
53
52
|
|> List.filter (\segment -> segment /= "/")
|
|
54
53
|
|> List.map normalize
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
{-| Turn a Path to a relative URL.
|
|
57
|
+
-}
|
|
58
|
+
toRelative : Path -> String
|
|
59
|
+
toRelative parts =
|
|
60
|
+
join parts
|
|
55
61
|
|> String.join "/"
|
|
56
|
-
|> Path
|
|
57
62
|
|
|
58
63
|
|
|
59
64
|
{-| Create a Path from a path String.
|
|
@@ -66,28 +71,20 @@ join parts =
|
|
|
66
71
|
fromString : String -> Path
|
|
67
72
|
fromString path =
|
|
68
73
|
path
|
|
69
|
-
|>
|
|
70
|
-
|> Path
|
|
74
|
+
|> toSegments
|
|
71
75
|
|
|
72
76
|
|
|
73
77
|
{-| -}
|
|
74
|
-
toSegments :
|
|
75
|
-
toSegments
|
|
78
|
+
toSegments : String -> List String
|
|
79
|
+
toSegments path =
|
|
76
80
|
path |> String.split "/" |> List.filter ((/=) "")
|
|
77
81
|
|
|
78
82
|
|
|
79
83
|
{-| Turn a Path to an absolute URL (with no trailing slash).
|
|
80
84
|
-}
|
|
81
85
|
toAbsolute : Path -> String
|
|
82
|
-
toAbsolute
|
|
83
|
-
"/" ++ path
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{-| Turn a Path to a relative URL.
|
|
87
|
-
-}
|
|
88
|
-
toRelative : Path -> String
|
|
89
|
-
toRelative (Path path) =
|
|
90
|
-
path
|
|
86
|
+
toAbsolute path =
|
|
87
|
+
"/" ++ toRelative path
|
|
91
88
|
|
|
92
89
|
|
|
93
90
|
normalize : String -> String
|
package/src/QueryParams.elm
CHANGED
|
@@ -1,189 +1,38 @@
|
|
|
1
1
|
module QueryParams exposing
|
|
2
2
|
( QueryParams
|
|
3
|
-
,
|
|
4
|
-
,
|
|
5
|
-
, map2, oneOf
|
|
6
|
-
, toDict, toString
|
|
3
|
+
, fromString
|
|
4
|
+
, toString
|
|
7
5
|
)
|
|
8
6
|
|
|
9
|
-
{-| Represents the query portion of a URL. You can use `toDict` or `toString` to turn it into basic types, or you can
|
|
10
|
-
parse it into a custom type using the other functions in this module.
|
|
11
|
-
|
|
12
|
-
@docs QueryParams
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Parsing
|
|
16
|
-
|
|
17
|
-
@docs Parser
|
|
18
|
-
|
|
19
|
-
@docs andThen, fail, fromResult, fromString, optionalString, parse, string, strings, succeed
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Combining
|
|
23
|
-
|
|
24
|
-
@docs map2, oneOf
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## Accessing as Built-In Types
|
|
28
|
-
|
|
29
|
-
@docs toDict, toString
|
|
30
|
-
|
|
31
|
-
-}
|
|
32
|
-
|
|
33
7
|
import Dict exposing (Dict)
|
|
34
8
|
import Url
|
|
35
9
|
|
|
36
10
|
|
|
37
11
|
{-| -}
|
|
38
|
-
type QueryParams
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{-| -}
|
|
43
|
-
type Parser a
|
|
44
|
-
= Parser (Dict String (List String) -> Result String a)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{-| -}
|
|
48
|
-
succeed : a -> Parser a
|
|
49
|
-
succeed value =
|
|
50
|
-
Parser (\_ -> Ok value)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{-| -}
|
|
54
|
-
fail : String -> Parser a
|
|
55
|
-
fail errorMessage =
|
|
56
|
-
Parser (\_ -> Err errorMessage)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
{-| -}
|
|
60
|
-
fromResult : Result String a -> Parser a
|
|
61
|
-
fromResult result =
|
|
62
|
-
Parser (\_ -> result)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{-| -}
|
|
66
|
-
andThen : (a -> Parser b) -> Parser a -> Parser b
|
|
67
|
-
andThen andThenFn (Parser parser) =
|
|
68
|
-
Parser
|
|
69
|
-
(\dict ->
|
|
70
|
-
case Result.map andThenFn (parser dict) of
|
|
71
|
-
Ok (Parser result) ->
|
|
72
|
-
result dict
|
|
73
|
-
|
|
74
|
-
Err error ->
|
|
75
|
-
Err error
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
{-| -}
|
|
80
|
-
oneOf : List (Parser a) -> Parser a
|
|
81
|
-
oneOf parsers =
|
|
82
|
-
Parser
|
|
83
|
-
(tryParser parsers)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{-| -}
|
|
87
|
-
tryParser : List (Parser a) -> Dict String (List String) -> Result String a
|
|
88
|
-
tryParser parsers dict =
|
|
89
|
-
case parsers of
|
|
90
|
-
[] ->
|
|
91
|
-
Err ""
|
|
92
|
-
|
|
93
|
-
(Parser nextParser) :: otherParsers ->
|
|
94
|
-
case nextParser dict of
|
|
95
|
-
Ok okValue ->
|
|
96
|
-
Ok okValue
|
|
97
|
-
|
|
98
|
-
Err _ ->
|
|
99
|
-
tryParser otherParsers dict
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
{-| -}
|
|
103
|
-
map2 : (a -> b -> combined) -> Parser a -> Parser b -> Parser combined
|
|
104
|
-
map2 func (Parser a) (Parser b) =
|
|
105
|
-
Parser <|
|
|
106
|
-
\dict ->
|
|
107
|
-
Result.map2 func (a dict) (b dict)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{-| -}
|
|
111
|
-
optionalString : String -> Parser (Maybe String)
|
|
112
|
-
optionalString key =
|
|
113
|
-
custom key
|
|
114
|
-
(\stringList ->
|
|
115
|
-
case stringList of
|
|
116
|
-
str :: _ ->
|
|
117
|
-
Ok (Just str)
|
|
118
|
-
|
|
119
|
-
_ ->
|
|
120
|
-
Ok Nothing
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
{-| -}
|
|
125
|
-
string : String -> Parser String
|
|
126
|
-
string key =
|
|
127
|
-
custom key
|
|
128
|
-
(\stringList ->
|
|
129
|
-
case stringList of
|
|
130
|
-
[ str ] ->
|
|
131
|
-
Ok str
|
|
132
|
-
|
|
133
|
-
_ ->
|
|
134
|
-
Err ("Missing key " ++ key)
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{-| -}
|
|
139
|
-
custom : String -> (List String -> Result String a) -> Parser a
|
|
140
|
-
custom key customFn =
|
|
141
|
-
Parser <|
|
|
142
|
-
\dict ->
|
|
143
|
-
customFn (Maybe.withDefault [] (Dict.get key dict))
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{-| -}
|
|
147
|
-
strings : String -> Parser (List String)
|
|
148
|
-
strings key =
|
|
149
|
-
custom key
|
|
150
|
-
(\stringList -> Ok stringList)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{-| -}
|
|
154
|
-
fromString : String -> QueryParams
|
|
155
|
-
fromString =
|
|
156
|
-
QueryParams
|
|
12
|
+
type alias QueryParams =
|
|
13
|
+
Dict String (List String)
|
|
157
14
|
|
|
158
15
|
|
|
159
16
|
{-| -}
|
|
160
17
|
toString : QueryParams -> String
|
|
161
|
-
toString
|
|
18
|
+
toString queryParams =
|
|
162
19
|
queryParams
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
prepareQuery : Maybe String -> Dict String (List String)
|
|
180
|
-
prepareQuery maybeQuery =
|
|
181
|
-
case maybeQuery of
|
|
182
|
-
Nothing ->
|
|
183
|
-
Dict.empty
|
|
184
|
-
|
|
185
|
-
Just qry ->
|
|
186
|
-
List.foldr addParam Dict.empty (String.split "&" qry)
|
|
20
|
+
|> Dict.toList
|
|
21
|
+
|> List.concatMap
|
|
22
|
+
(\( key, values ) ->
|
|
23
|
+
values
|
|
24
|
+
|> List.map
|
|
25
|
+
(\value ->
|
|
26
|
+
key ++ "=" ++ value
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
|> String.join "&"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
{-| -}
|
|
33
|
+
fromString : String -> Dict String (List String)
|
|
34
|
+
fromString query =
|
|
35
|
+
List.foldr addParam Dict.empty (String.split "&" query)
|
|
187
36
|
|
|
188
37
|
|
|
189
38
|
addParam : String -> Dict String (List String) -> Dict String (List String)
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
module RequestsAndPending exposing (RequestsAndPending, Response(..), ResponseBody(..),
|
|
1
|
+
module RequestsAndPending exposing (RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get)
|
|
2
2
|
|
|
3
3
|
import Base64
|
|
4
4
|
import Bytes exposing (Bytes)
|
|
5
|
-
import Codec
|
|
6
5
|
import Dict exposing (Dict)
|
|
7
6
|
import Json.Decode as Decode exposing (Decoder)
|
|
8
7
|
import Json.Encode as Encode
|
|
9
|
-
import Pages.StaticHttp.Request
|
|
10
8
|
|
|
11
9
|
|
|
12
10
|
type alias RequestsAndPending =
|
|
13
|
-
|
|
11
|
+
Decode.Value
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
type ResponseBody
|
|
@@ -20,18 +18,6 @@ type ResponseBody
|
|
|
20
18
|
| WhateverBody
|
|
21
19
|
|
|
22
20
|
|
|
23
|
-
batchDecoder : Decoder (List { request : Pages.StaticHttp.Request.Request, response : Response })
|
|
24
|
-
batchDecoder =
|
|
25
|
-
Decode.map2 (\request response -> { request = request, response = response })
|
|
26
|
-
(Decode.field "request"
|
|
27
|
-
(Pages.StaticHttp.Request.codec
|
|
28
|
-
|> Codec.decoder
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
(Decode.field "response" decoder)
|
|
32
|
-
|> Decode.list
|
|
33
|
-
|
|
34
|
-
|
|
35
21
|
decoder : Decoder Response
|
|
36
22
|
decoder =
|
|
37
23
|
Decode.map2 Response
|
|
@@ -117,6 +103,9 @@ responseDecoder =
|
|
|
117
103
|
|
|
118
104
|
get : String -> RequestsAndPending -> Maybe Response
|
|
119
105
|
get key requestsAndPending =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
Decode.decodeValue
|
|
107
|
+
(Decode.field key
|
|
108
|
+
(Decode.field "response" decoder)
|
|
109
|
+
)
|
|
110
|
+
requestsAndPending
|
|
111
|
+
|> Result.toMaybe
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Result.Extra exposing (combine, isOk, merge)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
isOk : Result x a -> Bool
|
|
5
|
+
isOk result =
|
|
6
|
+
case result of
|
|
7
|
+
Ok _ ->
|
|
8
|
+
True
|
|
9
|
+
|
|
10
|
+
Err _ ->
|
|
11
|
+
False
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
merge : Result a a -> a
|
|
15
|
+
merge r =
|
|
16
|
+
case r of
|
|
17
|
+
Ok rr ->
|
|
18
|
+
rr
|
|
19
|
+
|
|
20
|
+
Err rr ->
|
|
21
|
+
rr
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
combine : List (Result x a) -> Result x (List a)
|
|
25
|
+
combine =
|
|
26
|
+
List.foldr (Result.map2 (::)) (Ok [])
|