elm-pages 3.0.0-beta.2 → 3.0.0-beta.20
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} +2420 -1592
- 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 +1326 -121
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15215 -13007
- 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 +1 -1
- package/generator/dead-code-review/elm.json +8 -6
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +189 -17
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +255 -21
- 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 +1326 -121
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14620 -12636
- 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 +1 -1
- package/generator/review/elm.json +8 -8
- package/generator/src/RouteBuilder.elm +66 -52
- 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 +122 -86
- package/generator/src/cli.js +247 -51
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +1 -0
- package/generator/src/compile-elm.js +20 -22
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +119 -110
- 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 +14 -21
- package/generator/src/init.js +8 -7
- package/generator/src/pre-render-html.js +41 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +26 -28
- package/generator/src/render.js +322 -142
- package/generator/src/request-cache.js +200 -162
- 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 +16 -2
- package/generator/template/app/Api.elm +3 -3
- package/generator/template/app/Route/Index.elm +3 -3
- package/generator/template/app/Shared.elm +3 -3
- package/generator/template/app/Site.elm +9 -4
- package/package.json +21 -21
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +214 -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 +1 -1
- package/src/Form.elm +72 -92
- package/src/Head/Seo.elm +4 -4
- 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/Generate.elm +775 -132
- 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/Internal/Platform/Cli.elm +479 -747
- package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
- 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 +54 -53
- 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/ProgramConfig.elm +12 -8
- 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/RequestsAndPending.elm +8 -19
- package/src/Result/Extra.elm +21 -0
- package/src/Server/Request.elm +43 -34
- package/src/Server/Session.elm +166 -100
- package/src/Server/SetCookie.elm +89 -31
- 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/DataSource.elm
DELETED
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
module DataSource exposing
|
|
2
|
-
( DataSource
|
|
3
|
-
, map, succeed, fail
|
|
4
|
-
, fromResult
|
|
5
|
-
, andThen, resolve, combine
|
|
6
|
-
, andMap
|
|
7
|
-
, map2, map3, map4, map5, map6, map7, map8, map9
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
{-| In an `elm-pages` app, each page can define a value `data` which is a `DataSource` that will be resolved **before** `init` is called. That means it is also available
|
|
11
|
-
when the page's HTML is pre-rendered during the build step. You can also access the resolved data in `head` to use it for the page's SEO meta tags.
|
|
12
|
-
|
|
13
|
-
A `DataSource` lets you pull in data from:
|
|
14
|
-
|
|
15
|
-
- Local files ([`DataSource.File`](DataSource-File))
|
|
16
|
-
- HTTP requests ([`DataSource.Http`](DataSource-Http))
|
|
17
|
-
- Globs, i.e. listing out local files based on a pattern like `content/*.txt` ([`DataSource.Glob`](DataSource-Glob))
|
|
18
|
-
- Ports, i.e. getting JSON data from running custom NodeJS, similar to a port in a vanilla Elm app except run at build-time in NodeJS, rather than at run-time in the browser ([`DataSource.Port`](DataSource-Port))
|
|
19
|
-
- Hardcoded data (`DataSource.succeed "Hello!"`)
|
|
20
|
-
- Or any combination of the above, using `DataSource.map2`, `DataSource.andThen`, or other combining/continuing helpers from this module
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## Where Does DataSource Data Come From?
|
|
24
|
-
|
|
25
|
-
Data from a `DataSource` is resolved when you load a page in the `elm-pages` dev server, or when you run `elm-pages build`.
|
|
26
|
-
|
|
27
|
-
Because `elm-pages` hydrates into a full Elm single-page app, it does need the data in order to initialize the Elm app.
|
|
28
|
-
So why not just get the data the old-fashioned way, with `elm/http`, for example?
|
|
29
|
-
|
|
30
|
-
A few reasons:
|
|
31
|
-
|
|
32
|
-
1. DataSource's allow you to pull in data that you wouldn't normally be able to access from an Elm app, like local files, or listings of files in a folder. Not only that, but the dev server knows to automatically hot reload the data when the files it depends on change, so you can edit the files you used in your DataSource and see the page hot reload as you save!
|
|
33
|
-
2. Because `elm-pages` has a build step, you know that your `DataSource.Http` requests succeeded, your decoders succeeded, your custom DataSource validations succeeded, and everything went smoothly. If something went wrong, you get a build failure and can deal with the issues before the site goes live. That means your users won't see those errors, and as a developer you don't need to handle those error cases in your code! Think of it as "parse, don't validate", but for your entire build.
|
|
34
|
-
3. You don't have to worry about an API being down, or hitting it repeatedly. You can build in data and it will end up as JSON files served up with all the other assets of your site. If your CDN (static site host) is down, then the rest of your site is probably down anyway. If your site host is up, then so is all of your `DataSource` data. Also, it will be served up extremely quickly without needing to wait for any database queries to be performed, `andThen` requests to be resolved, etc., because all of that work and waiting was done at build-time!
|
|
35
|
-
4. You can pre-render pages, including the SEO meta tags, with all that rich, well-typed Elm data available! That's something you can't accomplish with a vanilla Elm app, and it's one of the main use cases for elm-pages.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## Mental Model
|
|
39
|
-
|
|
40
|
-
You can think of a DataSource as a declarative (not imperative) definition of data. It represents where to get the data from, and how to transform it (map, combine with other DataSources, etc.).
|
|
41
|
-
|
|
42
|
-
Even though an HTTP request is non-deterministic, you should think of it that way as much as possible with a DataSource because elm-pages will only perform a given DataSource.Http request once, and
|
|
43
|
-
it will share the result between any other DataSource.Http requests that have the exact same URL, Method, Body, and Headers.
|
|
44
|
-
|
|
45
|
-
So calling a function to increment a counter on a server through an HTTP request would not be a good fit for a `DataSource`. Let's imagine we have an HTTP endpoint that gives these stateful results when called repeatedly:
|
|
46
|
-
|
|
47
|
-
<https://my-api.example.com/increment-counter>
|
|
48
|
-
-> Returns 1
|
|
49
|
-
<https://my-api.example.com/increment-counter>
|
|
50
|
-
-> Returns 2
|
|
51
|
-
<https://my-api.example.com/increment-counter>
|
|
52
|
-
-> Returns 3
|
|
53
|
-
|
|
54
|
-
If we define a `DataSource` that hits that endpoint:
|
|
55
|
-
|
|
56
|
-
data =
|
|
57
|
-
DataSource.Http.get
|
|
58
|
-
"https://my-api.example.com/increment-counter"
|
|
59
|
-
Decode.int
|
|
60
|
-
|
|
61
|
-
No matter how many places we use that `DataSource`, its response will be "locked in" (let's say the response was `3`, then every page would have the same value of `3` for that request).
|
|
62
|
-
|
|
63
|
-
So even though HTTP requests, JavaScript code, etc. can be non-deterministic, a `DataSource` always represents a single snapshot of a resource, and those values will be re-used as if they were a deterministic, declarative resource.
|
|
64
|
-
So it's best to use that mental model to avoid confusion.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
## Basics
|
|
68
|
-
|
|
69
|
-
@docs DataSource
|
|
70
|
-
|
|
71
|
-
@docs map, succeed, fail
|
|
72
|
-
|
|
73
|
-
@docs fromResult
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
## Chaining Requests
|
|
77
|
-
|
|
78
|
-
@docs andThen, resolve, combine
|
|
79
|
-
|
|
80
|
-
@docs andMap
|
|
81
|
-
|
|
82
|
-
@docs map2, map3, map4, map5, map6, map7, map8, map9
|
|
83
|
-
|
|
84
|
-
-}
|
|
85
|
-
|
|
86
|
-
import Pages.Internal.StaticHttpBody as Body
|
|
87
|
-
import Pages.StaticHttp.Request as HashRequest
|
|
88
|
-
import Pages.StaticHttpRequest exposing (RawRequest(..))
|
|
89
|
-
import RequestsAndPending exposing (RequestsAndPending)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{-| A DataSource represents data that will be gathered at build time. Multiple `DataSource`s can be combined together using the `mapN` functions,
|
|
93
|
-
very similar to how you can manipulate values with Json Decoders in Elm.
|
|
94
|
-
-}
|
|
95
|
-
type alias DataSource value =
|
|
96
|
-
RawRequest value
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{-| Transform a request into an arbitrary value. The same underlying HTTP requests will be performed during the build
|
|
100
|
-
step, but mapping allows you to change the resulting values by applying functions to the results.
|
|
101
|
-
|
|
102
|
-
A common use for this is to map your data into your elm-pages view:
|
|
103
|
-
|
|
104
|
-
import DataSource
|
|
105
|
-
import Json.Decode as Decode exposing (Decoder)
|
|
106
|
-
|
|
107
|
-
view =
|
|
108
|
-
DataSource.Http.get
|
|
109
|
-
(Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
|
110
|
-
(Decode.field "stargazers_count" Decode.int)
|
|
111
|
-
|> DataSource.map
|
|
112
|
-
(\stars ->
|
|
113
|
-
{ view =
|
|
114
|
-
\model viewForPage ->
|
|
115
|
-
{ title = "Current stars: " ++ String.fromInt stars
|
|
116
|
-
, body = Html.text <| "⭐️ " ++ String.fromInt stars
|
|
117
|
-
, head = []
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
-}
|
|
123
|
-
map : (a -> b) -> DataSource a -> DataSource b
|
|
124
|
-
map fn requestInfo =
|
|
125
|
-
case requestInfo of
|
|
126
|
-
RequestError error ->
|
|
127
|
-
RequestError error
|
|
128
|
-
|
|
129
|
-
Request urls lookupFn ->
|
|
130
|
-
Request
|
|
131
|
-
urls
|
|
132
|
-
(mapLookupFn fn lookupFn)
|
|
133
|
-
|
|
134
|
-
ApiRoute value ->
|
|
135
|
-
ApiRoute (fn value)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
mapLookupFn : (a -> b) -> (d -> c -> DataSource a) -> d -> c -> DataSource b
|
|
139
|
-
mapLookupFn fn lookupFn maybeMock requests =
|
|
140
|
-
map fn (lookupFn maybeMock requests)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
{-| Helper to remove an inner layer of Request wrapping.
|
|
144
|
-
-}
|
|
145
|
-
resolve : DataSource (List (DataSource value)) -> DataSource (List value)
|
|
146
|
-
resolve =
|
|
147
|
-
andThen combine
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{-| Turn a list of `StaticHttp.Request`s into a single one.
|
|
151
|
-
|
|
152
|
-
import DataSource
|
|
153
|
-
import Json.Decode as Decode exposing (Decoder)
|
|
154
|
-
|
|
155
|
-
type alias Pokemon =
|
|
156
|
-
{ name : String
|
|
157
|
-
, sprite : String
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
pokemonDetailRequest : StaticHttp.Request (List Pokemon)
|
|
161
|
-
pokemonDetailRequest =
|
|
162
|
-
StaticHttp.get
|
|
163
|
-
(Secrets.succeed "https://pokeapi.co/api/v2/pokemon/?limit=3")
|
|
164
|
-
(Decode.field "results"
|
|
165
|
-
(Decode.list
|
|
166
|
-
(Decode.map2 Tuple.pair
|
|
167
|
-
(Decode.field "name" Decode.string)
|
|
168
|
-
(Decode.field "url" Decode.string)
|
|
169
|
-
|> Decode.map
|
|
170
|
-
(\( name, url ) ->
|
|
171
|
-
StaticHttp.get (Secrets.succeed url)
|
|
172
|
-
(Decode.at
|
|
173
|
-
[ "sprites", "front_default" ]
|
|
174
|
-
Decode.string
|
|
175
|
-
|> Decode.map (Pokemon name)
|
|
176
|
-
)
|
|
177
|
-
)
|
|
178
|
-
)
|
|
179
|
-
)
|
|
180
|
-
)
|
|
181
|
-
|> StaticHttp.andThen StaticHttp.combine
|
|
182
|
-
|
|
183
|
-
-}
|
|
184
|
-
combine : List (DataSource value) -> DataSource (List value)
|
|
185
|
-
combine =
|
|
186
|
-
List.foldr (map2 (::)) (succeed [])
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
{-| Like map, but it takes in two `Request`s.
|
|
190
|
-
|
|
191
|
-
view siteMetadata page =
|
|
192
|
-
StaticHttp.map2
|
|
193
|
-
(\elmPagesStars elmMarkdownStars ->
|
|
194
|
-
{ view =
|
|
195
|
-
\model viewForPage ->
|
|
196
|
-
{ title = "Repo Stargazers"
|
|
197
|
-
, body = starsView elmPagesStars elmMarkdownStars
|
|
198
|
-
}
|
|
199
|
-
, head = head elmPagesStars elmMarkdownStars
|
|
200
|
-
}
|
|
201
|
-
)
|
|
202
|
-
(get
|
|
203
|
-
(Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
|
204
|
-
(Decode.field "stargazers_count" Decode.int)
|
|
205
|
-
)
|
|
206
|
-
(get
|
|
207
|
-
(Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-markdown")
|
|
208
|
-
(Decode.field "stargazers_count" Decode.int)
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
-}
|
|
212
|
-
map2 : (a -> b -> c) -> DataSource a -> DataSource b -> DataSource c
|
|
213
|
-
map2 fn request1 request2 =
|
|
214
|
-
case ( request1, request2 ) of
|
|
215
|
-
( RequestError error, _ ) ->
|
|
216
|
-
RequestError error
|
|
217
|
-
|
|
218
|
-
( _, RequestError error ) ->
|
|
219
|
-
RequestError error
|
|
220
|
-
|
|
221
|
-
( Request urls1 lookupFn1, Request urls2 lookupFn2 ) ->
|
|
222
|
-
Request
|
|
223
|
-
(urls1 ++ urls2)
|
|
224
|
-
(mapReq fn lookupFn1 lookupFn2)
|
|
225
|
-
|
|
226
|
-
( Request urls1 lookupFn1, ApiRoute value2 ) ->
|
|
227
|
-
Request
|
|
228
|
-
urls1
|
|
229
|
-
(mapReq fn lookupFn1 (\_ _ -> ApiRoute value2))
|
|
230
|
-
|
|
231
|
-
( ApiRoute value2, Request urls1 lookupFn1 ) ->
|
|
232
|
-
Request
|
|
233
|
-
urls1
|
|
234
|
-
(mapReq fn (\_ _ -> ApiRoute value2) lookupFn1)
|
|
235
|
-
|
|
236
|
-
( ApiRoute value1, ApiRoute value2 ) ->
|
|
237
|
-
ApiRoute (fn value1 value2)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
mapReq : (a -> b -> c) -> (e -> d -> DataSource a) -> (e -> d -> DataSource b) -> e -> d -> DataSource c
|
|
241
|
-
mapReq fn lookupFn1 lookupFn2 maybeMock rawResponses =
|
|
242
|
-
map2 fn
|
|
243
|
-
(lookupFn1 maybeMock rawResponses)
|
|
244
|
-
(lookupFn2 maybeMock rawResponses)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
lookup : Maybe Pages.StaticHttpRequest.MockResolver -> DataSource value -> RequestsAndPending -> Result Pages.StaticHttpRequest.Error value
|
|
248
|
-
lookup maybeMockResolver requestInfo rawResponses =
|
|
249
|
-
case requestInfo of
|
|
250
|
-
RequestError error ->
|
|
251
|
-
Err error
|
|
252
|
-
|
|
253
|
-
Request urls lookupFn ->
|
|
254
|
-
lookup maybeMockResolver
|
|
255
|
-
(addUrls urls (lookupFn maybeMockResolver rawResponses))
|
|
256
|
-
rawResponses
|
|
257
|
-
|
|
258
|
-
ApiRoute value ->
|
|
259
|
-
Ok value
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
addUrls : List HashRequest.Request -> DataSource value -> DataSource value
|
|
263
|
-
addUrls urlsToAdd requestInfo =
|
|
264
|
-
case requestInfo of
|
|
265
|
-
RequestError error ->
|
|
266
|
-
RequestError error
|
|
267
|
-
|
|
268
|
-
Request initialUrls function ->
|
|
269
|
-
Request (initialUrls ++ urlsToAdd) function
|
|
270
|
-
|
|
271
|
-
ApiRoute value ->
|
|
272
|
-
ApiRoute value
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
{-| The full details to perform a StaticHttp request.
|
|
276
|
-
-}
|
|
277
|
-
type alias RequestDetails =
|
|
278
|
-
{ url : String
|
|
279
|
-
, method : String
|
|
280
|
-
, headers : List ( String, String )
|
|
281
|
-
, body : Body.Body
|
|
282
|
-
, useCache : Bool
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
lookupUrls : DataSource value -> List RequestDetails
|
|
287
|
-
lookupUrls requestInfo =
|
|
288
|
-
case requestInfo of
|
|
289
|
-
RequestError _ ->
|
|
290
|
-
-- TODO should this have URLs passed through?
|
|
291
|
-
[]
|
|
292
|
-
|
|
293
|
-
Request urls _ ->
|
|
294
|
-
urls
|
|
295
|
-
|
|
296
|
-
ApiRoute _ ->
|
|
297
|
-
[]
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
{-| Build off of the response from a previous `DataSource` request to build a follow-up request. You can use the data
|
|
301
|
-
from the previous response to build up the URL, headers, etc. that you send to the subsequent request.
|
|
302
|
-
|
|
303
|
-
import DataSource
|
|
304
|
-
import Json.Decode as Decode exposing (Decoder)
|
|
305
|
-
|
|
306
|
-
licenseData : DataSource String
|
|
307
|
-
licenseData =
|
|
308
|
-
DataSource.Http.get
|
|
309
|
-
(Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
|
310
|
-
(Decode.at [ "license", "url" ] Decode.string)
|
|
311
|
-
|> DataSource.andThen
|
|
312
|
-
(\licenseUrl ->
|
|
313
|
-
DataSource.Http.get (Secrets.succeed licenseUrl) (Decode.field "description" Decode.string)
|
|
314
|
-
)
|
|
315
|
-
|
|
316
|
-
-}
|
|
317
|
-
andThen : (a -> DataSource b) -> DataSource a -> DataSource b
|
|
318
|
-
andThen fn requestInfo =
|
|
319
|
-
Request
|
|
320
|
-
(lookupUrls requestInfo)
|
|
321
|
-
(\maybeMockResolver rawResponses ->
|
|
322
|
-
lookup maybeMockResolver
|
|
323
|
-
requestInfo
|
|
324
|
-
rawResponses
|
|
325
|
-
|> (\result ->
|
|
326
|
-
case result of
|
|
327
|
-
Err error ->
|
|
328
|
-
RequestError error
|
|
329
|
-
|
|
330
|
-
Ok value ->
|
|
331
|
-
case fn value of
|
|
332
|
-
Request values function ->
|
|
333
|
-
Request values function
|
|
334
|
-
|
|
335
|
-
RequestError error ->
|
|
336
|
-
RequestError error
|
|
337
|
-
|
|
338
|
-
ApiRoute finalValue ->
|
|
339
|
-
ApiRoute finalValue
|
|
340
|
-
)
|
|
341
|
-
)
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
{-| A helper for combining `DataSource`s in pipelines.
|
|
345
|
-
-}
|
|
346
|
-
andMap : DataSource a -> DataSource (a -> b) -> DataSource b
|
|
347
|
-
andMap =
|
|
348
|
-
map2 (|>)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
{-| This is useful for prototyping with some hardcoded data, or for having a view that doesn't have any StaticHttp data.
|
|
352
|
-
|
|
353
|
-
import DataSource
|
|
354
|
-
|
|
355
|
-
view :
|
|
356
|
-
List ( PagePath, Metadata )
|
|
357
|
-
->
|
|
358
|
-
{ path : PagePath
|
|
359
|
-
, frontmatter : Metadata
|
|
360
|
-
}
|
|
361
|
-
->
|
|
362
|
-
StaticHttp.Request
|
|
363
|
-
{ view : Model -> View -> { title : String, body : Html Msg }
|
|
364
|
-
, head : List (Head.Tag Pages.PathKey)
|
|
365
|
-
}
|
|
366
|
-
view siteMetadata page =
|
|
367
|
-
StaticHttp.succeed
|
|
368
|
-
{ view =
|
|
369
|
-
\model viewForPage ->
|
|
370
|
-
mainView model viewForPage
|
|
371
|
-
, head = head page.frontmatter
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
-}
|
|
375
|
-
succeed : a -> DataSource a
|
|
376
|
-
succeed value =
|
|
377
|
-
ApiRoute value
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
{-| Stop the StaticHttp chain with the given error message. If you reach a `fail` in your request,
|
|
381
|
-
you will get a build error. Or in the dev server, you will see the error message in an overlay in your browser (and in
|
|
382
|
-
the terminal).
|
|
383
|
-
-}
|
|
384
|
-
fail : String -> DataSource a
|
|
385
|
-
fail errorMessage =
|
|
386
|
-
RequestError (Pages.StaticHttpRequest.UserCalledStaticHttpFail errorMessage)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
{-| Turn an Err into a DataSource failure.
|
|
390
|
-
-}
|
|
391
|
-
fromResult : Result String value -> DataSource value
|
|
392
|
-
fromResult result =
|
|
393
|
-
case result of
|
|
394
|
-
Ok okValue ->
|
|
395
|
-
succeed okValue
|
|
396
|
-
|
|
397
|
-
Err error ->
|
|
398
|
-
fail error
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
{-| -}
|
|
402
|
-
map3 :
|
|
403
|
-
(value1 -> value2 -> value3 -> valueCombined)
|
|
404
|
-
-> DataSource value1
|
|
405
|
-
-> DataSource value2
|
|
406
|
-
-> DataSource value3
|
|
407
|
-
-> DataSource valueCombined
|
|
408
|
-
map3 combineFn request1 request2 request3 =
|
|
409
|
-
succeed combineFn
|
|
410
|
-
|> map2 (|>) request1
|
|
411
|
-
|> map2 (|>) request2
|
|
412
|
-
|> map2 (|>) request3
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
{-| -}
|
|
416
|
-
map4 :
|
|
417
|
-
(value1 -> value2 -> value3 -> value4 -> valueCombined)
|
|
418
|
-
-> DataSource value1
|
|
419
|
-
-> DataSource value2
|
|
420
|
-
-> DataSource value3
|
|
421
|
-
-> DataSource value4
|
|
422
|
-
-> DataSource valueCombined
|
|
423
|
-
map4 combineFn request1 request2 request3 request4 =
|
|
424
|
-
succeed combineFn
|
|
425
|
-
|> map2 (|>) request1
|
|
426
|
-
|> map2 (|>) request2
|
|
427
|
-
|> map2 (|>) request3
|
|
428
|
-
|> map2 (|>) request4
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
{-| -}
|
|
432
|
-
map5 :
|
|
433
|
-
(value1 -> value2 -> value3 -> value4 -> value5 -> valueCombined)
|
|
434
|
-
-> DataSource value1
|
|
435
|
-
-> DataSource value2
|
|
436
|
-
-> DataSource value3
|
|
437
|
-
-> DataSource value4
|
|
438
|
-
-> DataSource value5
|
|
439
|
-
-> DataSource valueCombined
|
|
440
|
-
map5 combineFn request1 request2 request3 request4 request5 =
|
|
441
|
-
succeed combineFn
|
|
442
|
-
|> map2 (|>) request1
|
|
443
|
-
|> map2 (|>) request2
|
|
444
|
-
|> map2 (|>) request3
|
|
445
|
-
|> map2 (|>) request4
|
|
446
|
-
|> map2 (|>) request5
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{-| -}
|
|
450
|
-
map6 :
|
|
451
|
-
(value1 -> value2 -> value3 -> value4 -> value5 -> value6 -> valueCombined)
|
|
452
|
-
-> DataSource value1
|
|
453
|
-
-> DataSource value2
|
|
454
|
-
-> DataSource value3
|
|
455
|
-
-> DataSource value4
|
|
456
|
-
-> DataSource value5
|
|
457
|
-
-> DataSource value6
|
|
458
|
-
-> DataSource valueCombined
|
|
459
|
-
map6 combineFn request1 request2 request3 request4 request5 request6 =
|
|
460
|
-
succeed combineFn
|
|
461
|
-
|> map2 (|>) request1
|
|
462
|
-
|> map2 (|>) request2
|
|
463
|
-
|> map2 (|>) request3
|
|
464
|
-
|> map2 (|>) request4
|
|
465
|
-
|> map2 (|>) request5
|
|
466
|
-
|> map2 (|>) request6
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
{-| -}
|
|
470
|
-
map7 :
|
|
471
|
-
(value1 -> value2 -> value3 -> value4 -> value5 -> value6 -> value7 -> valueCombined)
|
|
472
|
-
-> DataSource value1
|
|
473
|
-
-> DataSource value2
|
|
474
|
-
-> DataSource value3
|
|
475
|
-
-> DataSource value4
|
|
476
|
-
-> DataSource value5
|
|
477
|
-
-> DataSource value6
|
|
478
|
-
-> DataSource value7
|
|
479
|
-
-> DataSource valueCombined
|
|
480
|
-
map7 combineFn request1 request2 request3 request4 request5 request6 request7 =
|
|
481
|
-
succeed combineFn
|
|
482
|
-
|> map2 (|>) request1
|
|
483
|
-
|> map2 (|>) request2
|
|
484
|
-
|> map2 (|>) request3
|
|
485
|
-
|> map2 (|>) request4
|
|
486
|
-
|> map2 (|>) request5
|
|
487
|
-
|> map2 (|>) request6
|
|
488
|
-
|> map2 (|>) request7
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
{-| -}
|
|
492
|
-
map8 :
|
|
493
|
-
(value1 -> value2 -> value3 -> value4 -> value5 -> value6 -> value7 -> value8 -> valueCombined)
|
|
494
|
-
-> DataSource value1
|
|
495
|
-
-> DataSource value2
|
|
496
|
-
-> DataSource value3
|
|
497
|
-
-> DataSource value4
|
|
498
|
-
-> DataSource value5
|
|
499
|
-
-> DataSource value6
|
|
500
|
-
-> DataSource value7
|
|
501
|
-
-> DataSource value8
|
|
502
|
-
-> DataSource valueCombined
|
|
503
|
-
map8 combineFn request1 request2 request3 request4 request5 request6 request7 request8 =
|
|
504
|
-
succeed combineFn
|
|
505
|
-
|> map2 (|>) request1
|
|
506
|
-
|> map2 (|>) request2
|
|
507
|
-
|> map2 (|>) request3
|
|
508
|
-
|> map2 (|>) request4
|
|
509
|
-
|> map2 (|>) request5
|
|
510
|
-
|> map2 (|>) request6
|
|
511
|
-
|> map2 (|>) request7
|
|
512
|
-
|> map2 (|>) request8
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
{-| -}
|
|
516
|
-
map9 :
|
|
517
|
-
(value1 -> value2 -> value3 -> value4 -> value5 -> value6 -> value7 -> value8 -> value9 -> valueCombined)
|
|
518
|
-
-> DataSource value1
|
|
519
|
-
-> DataSource value2
|
|
520
|
-
-> DataSource value3
|
|
521
|
-
-> DataSource value4
|
|
522
|
-
-> DataSource value5
|
|
523
|
-
-> DataSource value6
|
|
524
|
-
-> DataSource value7
|
|
525
|
-
-> DataSource value8
|
|
526
|
-
-> DataSource value9
|
|
527
|
-
-> DataSource valueCombined
|
|
528
|
-
map9 combineFn request1 request2 request3 request4 request5 request6 request7 request8 request9 =
|
|
529
|
-
succeed combineFn
|
|
530
|
-
|> map2 (|>) request1
|
|
531
|
-
|> map2 (|>) request2
|
|
532
|
-
|> map2 (|>) request3
|
|
533
|
-
|> map2 (|>) request4
|
|
534
|
-
|> map2 (|>) request5
|
|
535
|
-
|> map2 (|>) request6
|
|
536
|
-
|> map2 (|>) request7
|
|
537
|
-
|> map2 (|>) request8
|
|
538
|
-
|> map2 (|>) request9
|