elm-pages 2.1.11 → 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 +1 -0
- package/generator/template/{public/index.js → index.ts} +7 -3
- package/generator/template/package.json +4 -4
- 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
package/src/DataSource/Http.elm
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
module DataSource.Http exposing
|
|
2
2
|
( RequestDetails
|
|
3
3
|
, get, request
|
|
4
|
+
, Expect, expectString, expectJson, expectBytes, expectWhatever
|
|
5
|
+
, Response(..), Metadata, Error(..)
|
|
6
|
+
, expectStringResponse, expectBytesResponse
|
|
4
7
|
, Body, emptyBody, stringBody, jsonBody
|
|
5
|
-
,
|
|
6
|
-
, Expect, expectString, expectUnoptimizedJson
|
|
8
|
+
, uncachedRequest
|
|
7
9
|
)
|
|
8
10
|
|
|
9
11
|
{-| `DataSource.Http` requests are an alternative to doing Elm HTTP requests the traditional way using the `elm/http` package.
|
|
@@ -11,8 +13,6 @@ module DataSource.Http exposing
|
|
|
11
13
|
The key differences are:
|
|
12
14
|
|
|
13
15
|
- `DataSource.Http.Request`s are performed once at build time (`Http.Request`s are performed at runtime, at whenever point you perform them)
|
|
14
|
-
- `DataSource.Http.Request`s strip out unused JSON data from the data your decoder doesn't touch to minimize the JSON payload
|
|
15
|
-
- `DataSource.Http.Request`s can use [`Pages.Secrets`](Pages.Secrets) to securely use credentials from your environment variables which are completely masked in the production assets.
|
|
16
16
|
- `DataSource.Http.Request`s have a built-in `DataSource.andThen` that allows you to perform follow-up requests without using tasks
|
|
17
17
|
|
|
18
18
|
|
|
@@ -39,6 +39,18 @@ in [this article introducing DataSource.Http requests and some concepts around i
|
|
|
39
39
|
@docs get, request
|
|
40
40
|
|
|
41
41
|
|
|
42
|
+
## Decoding Request Body
|
|
43
|
+
|
|
44
|
+
@docs Expect, expectString, expectJson, expectBytes, expectWhatever
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Expecting Responses
|
|
48
|
+
|
|
49
|
+
@docs Response, Metadata, Error
|
|
50
|
+
|
|
51
|
+
@docs expectStringResponse, expectBytesResponse
|
|
52
|
+
|
|
53
|
+
|
|
42
54
|
## Building a DataSource.Http Request Body
|
|
43
55
|
|
|
44
56
|
The way you build a body is analogous to the `elm/http` package. Currently, only `emptyBody` and
|
|
@@ -48,36 +60,22 @@ and describe your use case!
|
|
|
48
60
|
@docs Body, emptyBody, stringBody, jsonBody
|
|
49
61
|
|
|
50
62
|
|
|
51
|
-
##
|
|
52
|
-
|
|
53
|
-
Warning - use these at your own risk! It's highly recommended that you use the other request functions that make use of
|
|
54
|
-
`zwilias/json-decode-exploration` in order to allow you to reduce down your JSON to only the values that are used by
|
|
55
|
-
your decoders. This can significantly reduce download sizes for your DataSource.Http requests.
|
|
63
|
+
## Uncached Requests
|
|
56
64
|
|
|
57
|
-
@docs
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### Expect for unoptimized requests
|
|
61
|
-
|
|
62
|
-
@docs Expect, expectString, expectUnoptimizedJson
|
|
65
|
+
@docs uncachedRequest
|
|
63
66
|
|
|
64
67
|
-}
|
|
65
68
|
|
|
69
|
+
import Bytes exposing (Bytes)
|
|
70
|
+
import Bytes.Decode
|
|
66
71
|
import DataSource exposing (DataSource)
|
|
67
|
-
import Dict
|
|
68
|
-
import Internal.OptimizedDecoder
|
|
72
|
+
import Dict exposing (Dict)
|
|
69
73
|
import Json.Decode
|
|
70
|
-
import Json.Decode.Exploration
|
|
71
74
|
import Json.Encode as Encode
|
|
72
|
-
import KeepOrDiscard
|
|
73
|
-
import OptimizedDecoder as Decode exposing (Decoder)
|
|
74
|
-
import Pages.Internal.ApplicationType as ApplicationType
|
|
75
75
|
import Pages.Internal.StaticHttpBody as Body
|
|
76
|
-
import Pages.Secrets
|
|
77
76
|
import Pages.StaticHttp.Request as HashRequest
|
|
78
77
|
import Pages.StaticHttpRequest exposing (RawRequest(..))
|
|
79
78
|
import RequestsAndPending
|
|
80
|
-
import Secrets
|
|
81
79
|
|
|
82
80
|
|
|
83
81
|
{-| Build an empty body for a DataSource.Http request. See [elm/http's `Http.emptyBody`](https://package.elm-lang.org/packages/elm/http/latest/Http#emptyBody).
|
|
@@ -121,28 +119,27 @@ type alias Body =
|
|
|
121
119
|
getRequest : DataSource Int
|
|
122
120
|
getRequest =
|
|
123
121
|
DataSource.Http.get
|
|
124
|
-
|
|
122
|
+
"https://api.github.com/repos/dillonkearns/elm-pages"
|
|
125
123
|
(Decode.field "stargazers_count" Decode.int)
|
|
126
124
|
|
|
127
125
|
-}
|
|
128
126
|
get :
|
|
129
|
-
|
|
130
|
-
-> Decoder a
|
|
127
|
+
String
|
|
128
|
+
-> Json.Decode.Decoder a
|
|
131
129
|
-> DataSource a
|
|
132
130
|
get url decoder =
|
|
133
131
|
request
|
|
134
|
-
(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
)
|
|
132
|
+
((\okUrl ->
|
|
133
|
+
-- wrap in new variant
|
|
134
|
+
{ url = okUrl
|
|
135
|
+
, method = "GET"
|
|
136
|
+
, headers = []
|
|
137
|
+
, body = emptyBody
|
|
138
|
+
}
|
|
139
|
+
)
|
|
143
140
|
url
|
|
144
141
|
)
|
|
145
|
-
decoder
|
|
142
|
+
(expectJson decoder)
|
|
146
143
|
|
|
147
144
|
|
|
148
145
|
{-| The full details to perform a DataSource.Http request.
|
|
@@ -155,66 +152,41 @@ type alias RequestDetails =
|
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
|
|
158
|
-
|
|
159
|
-
requestToString requestDetails =
|
|
160
|
-
requestDetails.url
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
{-| Build a `DataSource.Http` request (analagous to [Http.request](https://package.elm-lang.org/packages/elm/http/latest/Http#request)).
|
|
164
|
-
This function takes in all the details to build a `DataSource.Http` request, but you can build your own simplified helper functions
|
|
165
|
-
with this as a low-level detail, or you can use functions like [DataSource.Http.get](#get).
|
|
166
|
-
-}
|
|
167
|
-
request :
|
|
168
|
-
Pages.Secrets.Value RequestDetails
|
|
169
|
-
-> Decoder a
|
|
170
|
-
-> DataSource a
|
|
171
|
-
request urlWithSecrets decoder =
|
|
172
|
-
unoptimizedRequest urlWithSecrets (ExpectJson decoder)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
{-| Analgous to the `Expect` type in the `elm/http` package. This represents how you will process the data that comes
|
|
155
|
+
{-| Analogous to the `Expect` type in the `elm/http` package. This represents how you will process the data that comes
|
|
176
156
|
back in your DataSource.Http request.
|
|
177
157
|
|
|
178
|
-
You can derive `
|
|
158
|
+
You can derive `ExpectJson` from `ExpectString`. Or you could build your own helper to process the String
|
|
179
159
|
as XML, for example, or give an `elm-pages` build error if the response can't be parsed as XML.
|
|
180
160
|
|
|
181
161
|
-}
|
|
182
162
|
type Expect value
|
|
183
|
-
=
|
|
184
|
-
|
|
|
185
|
-
|
|
|
163
|
+
= ExpectJson (Json.Decode.Decoder value)
|
|
164
|
+
| ExpectString (String -> value)
|
|
165
|
+
| ExpectResponse (Response String -> value)
|
|
166
|
+
| ExpectBytesResponse (Response Bytes -> value)
|
|
167
|
+
| ExpectBytes (Bytes.Decode.Decoder value)
|
|
168
|
+
| ExpectWhatever value
|
|
186
169
|
|
|
187
170
|
|
|
188
|
-
{-|
|
|
189
|
-
in something besides JSON. Be sure to use the `DataSource.Http.request` function if you want an optimized request that
|
|
190
|
-
strips out unused JSON to optimize your asset size.
|
|
171
|
+
{-| Gives the HTTP response body as a raw String.
|
|
191
172
|
|
|
192
|
-
|
|
193
|
-
|
|
173
|
+
import DataSource exposing (DataSource)
|
|
174
|
+
import DataSource.Http
|
|
194
175
|
|
|
176
|
+
request : DataSource String
|
|
195
177
|
request =
|
|
196
|
-
DataSource.Http.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
(DataSource.Http.expectString
|
|
205
|
-
(\string ->
|
|
206
|
-
if String.toUpper string == string then
|
|
207
|
-
Ok string
|
|
208
|
-
|
|
209
|
-
else
|
|
210
|
-
Err "String was not uppercased"
|
|
211
|
-
)
|
|
212
|
-
)
|
|
178
|
+
DataSource.Http.request
|
|
179
|
+
{ url = "https://example.com/file.txt"
|
|
180
|
+
, method = "GET"
|
|
181
|
+
, headers = []
|
|
182
|
+
, body = DataSource.Http.emptyBody
|
|
183
|
+
}
|
|
184
|
+
DataSource.Http.expectString
|
|
213
185
|
|
|
214
186
|
-}
|
|
215
|
-
expectString :
|
|
187
|
+
expectString : Expect String
|
|
216
188
|
expectString =
|
|
217
|
-
ExpectString
|
|
189
|
+
ExpectString identity
|
|
218
190
|
|
|
219
191
|
|
|
220
192
|
{-| Handle the incoming response as JSON and don't optimize the asset and strip out unused values.
|
|
@@ -226,242 +198,249 @@ If the function you pass to `expectString` yields an `Err`, then you will get a
|
|
|
226
198
|
fail your `elm-pages` build and print out the String from the `Err`.
|
|
227
199
|
|
|
228
200
|
-}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
201
|
+
expectJson : Json.Decode.Decoder value -> Expect value
|
|
202
|
+
expectJson =
|
|
203
|
+
ExpectJson
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
{-| -}
|
|
207
|
+
expectBytes : Bytes.Decode.Decoder value -> Expect value
|
|
208
|
+
expectBytes =
|
|
209
|
+
ExpectBytes
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
{-| -}
|
|
213
|
+
expectWhatever : value -> Expect value
|
|
214
|
+
expectWhatever =
|
|
215
|
+
ExpectWhatever
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
{-| -}
|
|
219
|
+
expectStringResponse : Expect (Response String)
|
|
220
|
+
expectStringResponse =
|
|
221
|
+
ExpectResponse identity
|
|
232
222
|
|
|
233
223
|
|
|
234
|
-
{-|
|
|
235
|
-
|
|
236
|
-
|
|
224
|
+
{-| -}
|
|
225
|
+
expectBytesResponse : Expect (Response Bytes)
|
|
226
|
+
expectBytesResponse =
|
|
227
|
+
ExpectBytesResponse identity
|
|
237
228
|
|
|
238
|
-
You may want to use this function instead if you need XML data or plaintext. Or maybe you're hitting a GraphQL API,
|
|
239
|
-
so you don't need any additional optimization as the payload is already reduced down to exactly what you requested.
|
|
240
229
|
|
|
230
|
+
expectToString : Expect a -> String
|
|
231
|
+
expectToString expect =
|
|
232
|
+
case expect of
|
|
233
|
+
ExpectJson _ ->
|
|
234
|
+
"ExpectJson"
|
|
235
|
+
|
|
236
|
+
ExpectString _ ->
|
|
237
|
+
"ExpectString"
|
|
238
|
+
|
|
239
|
+
ExpectResponse _ ->
|
|
240
|
+
"ExpectResponse"
|
|
241
|
+
|
|
242
|
+
ExpectBytes _ ->
|
|
243
|
+
"ExpectBytes"
|
|
244
|
+
|
|
245
|
+
ExpectWhatever _ ->
|
|
246
|
+
"ExpectWhatever"
|
|
247
|
+
|
|
248
|
+
ExpectBytesResponse _ ->
|
|
249
|
+
"ExpectBytesResponse"
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
{-| -}
|
|
253
|
+
request :
|
|
254
|
+
RequestDetails
|
|
255
|
+
-> Expect a
|
|
256
|
+
-> DataSource a
|
|
257
|
+
request request__ expect =
|
|
258
|
+
let
|
|
259
|
+
request_ : HashRequest.Request
|
|
260
|
+
request_ =
|
|
261
|
+
{ url = request__.url
|
|
262
|
+
, headers = request__.headers
|
|
263
|
+
, method = request__.method
|
|
264
|
+
, body = request__.body
|
|
265
|
+
, useCache = True
|
|
266
|
+
}
|
|
267
|
+
in
|
|
268
|
+
requestRaw request_ expect
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
{-| -}
|
|
272
|
+
uncachedRequest :
|
|
273
|
+
RequestDetails
|
|
274
|
+
-> Expect a
|
|
275
|
+
-> DataSource a
|
|
276
|
+
uncachedRequest request__ expect =
|
|
277
|
+
let
|
|
278
|
+
request_ : HashRequest.Request
|
|
279
|
+
request_ =
|
|
280
|
+
{ url = request__.url
|
|
281
|
+
, headers = request__.headers
|
|
282
|
+
, method = request__.method
|
|
283
|
+
, body = request__.body
|
|
284
|
+
, useCache = False
|
|
285
|
+
}
|
|
286
|
+
in
|
|
287
|
+
requestRaw request_ expect
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
{-| Build a `DataSource.Http` request (analogous to [Http.request](https://package.elm-lang.org/packages/elm/http/latest/Http#request)).
|
|
291
|
+
This function takes in all the details to build a `DataSource.Http` request, but you can build your own simplified helper functions
|
|
292
|
+
with this as a low-level detail, or you can use functions like [DataSource.Http.get](#get).
|
|
241
293
|
-}
|
|
242
|
-
|
|
243
|
-
|
|
294
|
+
requestRaw :
|
|
295
|
+
HashRequest.Request
|
|
244
296
|
-> Expect a
|
|
245
297
|
-> DataSource a
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
Json.Decode.Exploration.Errors errors ->
|
|
289
|
-
errors
|
|
290
|
-
|> Json.Decode.Exploration.errorsToString
|
|
291
|
-
|> Pages.StaticHttpRequest.DecoderError
|
|
292
|
-
|> Err
|
|
293
|
-
|
|
294
|
-
Json.Decode.Exploration.WithWarnings _ a ->
|
|
295
|
-
Ok a
|
|
296
|
-
|
|
297
|
-
Json.Decode.Exploration.Success a ->
|
|
298
|
-
Ok a
|
|
299
|
-
)
|
|
300
|
-
|> Result.map
|
|
301
|
-
(\finalRequest ->
|
|
302
|
-
( case keepOrDiscard of
|
|
303
|
-
KeepOrDiscard.Keep ->
|
|
304
|
-
strippedResponses
|
|
305
|
-
|> Dict.insert
|
|
306
|
-
(Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
307
|
-
(Pages.StaticHttpRequest.StripResponse
|
|
308
|
-
(Decode.map (\_ -> ()) decoder)
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
KeepOrDiscard.Discard ->
|
|
312
|
-
strippedResponses
|
|
313
|
-
|> Dict.insert
|
|
314
|
-
(Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
315
|
-
Pages.StaticHttpRequest.CliOnly
|
|
316
|
-
, finalRequest
|
|
317
|
-
)
|
|
318
|
-
)
|
|
319
|
-
)
|
|
320
|
-
|> toResult
|
|
321
|
-
|
|
322
|
-
ApplicationType.Browser ->
|
|
323
|
-
rawResponseDict
|
|
324
|
-
|> RequestsAndPending.get (Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
325
|
-
|> (\maybeResponse ->
|
|
326
|
-
case maybeResponse of
|
|
327
|
-
Just rawResponse ->
|
|
328
|
-
Ok
|
|
329
|
-
( -- TODO should this be an empty Dict? Shouldn't matter in the browser.
|
|
330
|
-
Dict.singleton (Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
331
|
-
Pages.StaticHttpRequest.UseRawResponse
|
|
332
|
-
, rawResponse
|
|
333
|
-
)
|
|
334
|
-
|
|
335
|
-
Nothing ->
|
|
336
|
-
Err
|
|
337
|
-
(Pages.StaticHttpRequest.MissingHttpResponse (requestToString (Secrets.maskedLookup requestWithSecrets))
|
|
338
|
-
[ requestWithSecrets ]
|
|
339
|
-
)
|
|
340
|
-
)
|
|
341
|
-
|> Result.andThen
|
|
342
|
-
(\( strippedResponses, rawResponse ) ->
|
|
343
|
-
rawResponse
|
|
344
|
-
|> Json.Decode.decodeString (decoder |> Internal.OptimizedDecoder.jd)
|
|
345
|
-
|> (\decodeResult ->
|
|
346
|
-
case decodeResult of
|
|
347
|
-
Err error ->
|
|
348
|
-
Pages.StaticHttpRequest.DecoderError
|
|
349
|
-
("Payload sent back invalid JSON\n"
|
|
350
|
-
++ rawResponse
|
|
351
|
-
++ "\n KEYS"
|
|
352
|
-
++ (Dict.keys strippedResponses |> String.join " - ")
|
|
353
|
-
++ Json.Decode.errorToString error
|
|
354
|
-
)
|
|
355
|
-
|> Err
|
|
356
|
-
|
|
357
|
-
Ok a ->
|
|
358
|
-
Ok a
|
|
359
|
-
)
|
|
360
|
-
|> Result.map
|
|
361
|
-
(\finalRequest ->
|
|
362
|
-
( strippedResponses
|
|
363
|
-
, finalRequest
|
|
364
|
-
)
|
|
365
|
-
)
|
|
366
|
-
)
|
|
367
|
-
|> toResult
|
|
368
|
-
)
|
|
369
|
-
|
|
370
|
-
ExpectUnoptimizedJson decoder ->
|
|
371
|
-
Request Dict.empty
|
|
372
|
-
( [ requestWithSecrets ]
|
|
373
|
-
, \_ _ rawResponseDict ->
|
|
374
|
-
rawResponseDict
|
|
375
|
-
|> RequestsAndPending.get (Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
376
|
-
|> (\maybeResponse ->
|
|
377
|
-
case maybeResponse of
|
|
378
|
-
Just rawResponse ->
|
|
379
|
-
Ok
|
|
380
|
-
( -- TODO check keepOrDiscard
|
|
381
|
-
Dict.singleton (Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
382
|
-
Pages.StaticHttpRequest.UseRawResponse
|
|
383
|
-
, rawResponse
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
Nothing ->
|
|
387
|
-
Err
|
|
388
|
-
(Pages.StaticHttpRequest.MissingHttpResponse (requestToString (Secrets.maskedLookup requestWithSecrets))
|
|
389
|
-
[ requestWithSecrets ]
|
|
390
|
-
)
|
|
391
|
-
)
|
|
392
|
-
|> Result.andThen
|
|
393
|
-
(\( strippedResponses, rawResponse ) ->
|
|
394
|
-
rawResponse
|
|
395
|
-
|> Json.Decode.decodeString decoder
|
|
396
|
-
|> (\decodeResult ->
|
|
397
|
-
case decodeResult of
|
|
398
|
-
Err error ->
|
|
399
|
-
error
|
|
400
|
-
|> Decode.errorToString
|
|
401
|
-
|> Pages.StaticHttpRequest.DecoderError
|
|
402
|
-
|> Err
|
|
403
|
-
|
|
404
|
-
Ok a ->
|
|
405
|
-
Ok a
|
|
406
|
-
)
|
|
407
|
-
|> Result.map
|
|
408
|
-
(\finalRequest ->
|
|
409
|
-
( -- TODO check keepOrDiscard
|
|
410
|
-
strippedResponses
|
|
411
|
-
|> Dict.insert
|
|
412
|
-
(Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
413
|
-
Pages.StaticHttpRequest.UseRawResponse
|
|
414
|
-
, finalRequest
|
|
415
|
-
)
|
|
298
|
+
requestRaw request__ expect =
|
|
299
|
+
let
|
|
300
|
+
request_ : HashRequest.Request
|
|
301
|
+
request_ =
|
|
302
|
+
{ url = request__.url
|
|
303
|
+
, headers =
|
|
304
|
+
( "elm-pages-internal", expectToString expect )
|
|
305
|
+
:: request__.headers
|
|
306
|
+
, method = request__.method
|
|
307
|
+
, body = request__.body
|
|
308
|
+
, useCache = False
|
|
309
|
+
}
|
|
310
|
+
in
|
|
311
|
+
Request
|
|
312
|
+
[ request_ ]
|
|
313
|
+
(\maybeMockResolver rawResponseDict ->
|
|
314
|
+
(case maybeMockResolver of
|
|
315
|
+
Just mockResolver ->
|
|
316
|
+
mockResolver request_
|
|
317
|
+
|
|
318
|
+
Nothing ->
|
|
319
|
+
rawResponseDict |> RequestsAndPending.get (request_ |> HashRequest.hash)
|
|
320
|
+
)
|
|
321
|
+
|> (\maybeResponse ->
|
|
322
|
+
case maybeResponse of
|
|
323
|
+
Just rawResponse ->
|
|
324
|
+
Ok rawResponse
|
|
325
|
+
|
|
326
|
+
Nothing ->
|
|
327
|
+
Err (Pages.StaticHttpRequest.MissingHttpResponse request_.url [ request_ ])
|
|
328
|
+
)
|
|
329
|
+
|> Result.andThen
|
|
330
|
+
(\(RequestsAndPending.Response maybeResponse body) ->
|
|
331
|
+
case ( expect, body, maybeResponse ) of
|
|
332
|
+
( ExpectJson decoder, RequestsAndPending.JsonBody json, _ ) ->
|
|
333
|
+
json
|
|
334
|
+
|> Json.Decode.decodeValue decoder
|
|
335
|
+
|> Result.mapError
|
|
336
|
+
(\error ->
|
|
337
|
+
error
|
|
338
|
+
|> Json.Decode.errorToString
|
|
339
|
+
|> Pages.StaticHttpRequest.DecoderError
|
|
416
340
|
)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
ExpectString mapStringFn ->
|
|
422
|
-
Request Dict.empty
|
|
423
|
-
( [ requestWithSecrets ]
|
|
424
|
-
, \_ _ rawResponseDict ->
|
|
425
|
-
rawResponseDict
|
|
426
|
-
|> RequestsAndPending.get (Secrets.maskedLookup requestWithSecrets |> HashRequest.hash)
|
|
427
|
-
|> (\maybeResponse ->
|
|
428
|
-
case maybeResponse of
|
|
429
|
-
Just rawResponse ->
|
|
430
|
-
Ok
|
|
431
|
-
( -- TODO check keepOrDiscard
|
|
432
|
-
Dict.singleton (Secrets.maskedLookup requestWithSecrets |> HashRequest.hash) Pages.StaticHttpRequest.UseRawResponse
|
|
433
|
-
, rawResponse
|
|
434
|
-
)
|
|
435
|
-
|
|
436
|
-
Nothing ->
|
|
437
|
-
Err
|
|
438
|
-
(Pages.StaticHttpRequest.MissingHttpResponse (requestToString (Secrets.maskedLookup requestWithSecrets))
|
|
439
|
-
[ requestWithSecrets ]
|
|
440
|
-
)
|
|
441
|
-
)
|
|
442
|
-
|> Result.andThen
|
|
443
|
-
(\( strippedResponses, rawResponse ) ->
|
|
444
|
-
rawResponse
|
|
341
|
+
|
|
342
|
+
( ExpectString mapStringFn, RequestsAndPending.StringBody string, _ ) ->
|
|
343
|
+
string
|
|
445
344
|
|> mapStringFn
|
|
446
|
-
|>
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
345
|
+
|> Ok
|
|
346
|
+
|
|
347
|
+
( ExpectResponse mapResponse, RequestsAndPending.StringBody asStringBody, Just rawResponse ) ->
|
|
348
|
+
let
|
|
349
|
+
asMetadata : Metadata
|
|
350
|
+
asMetadata =
|
|
351
|
+
{ url = rawResponse.url
|
|
352
|
+
, statusCode = rawResponse.statusCode
|
|
353
|
+
, statusText = rawResponse.statusText
|
|
354
|
+
, headers = rawResponse.headers
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
rawResponseToResponse : Response String
|
|
358
|
+
rawResponseToResponse =
|
|
359
|
+
if 200 <= rawResponse.statusCode && rawResponse.statusCode < 300 then
|
|
360
|
+
GoodStatus_ asMetadata asStringBody
|
|
361
|
+
|
|
362
|
+
else
|
|
363
|
+
BadStatus_ asMetadata asStringBody
|
|
364
|
+
in
|
|
365
|
+
rawResponseToResponse
|
|
366
|
+
|> mapResponse
|
|
367
|
+
|> Ok
|
|
368
|
+
|
|
369
|
+
( ExpectBytesResponse mapResponse, RequestsAndPending.BytesBody rawBytesBody, Just rawResponse ) ->
|
|
370
|
+
let
|
|
371
|
+
asMetadata : Metadata
|
|
372
|
+
asMetadata =
|
|
373
|
+
{ url = rawResponse.url
|
|
374
|
+
, statusCode = rawResponse.statusCode
|
|
375
|
+
, statusText = rawResponse.statusText
|
|
376
|
+
, headers = rawResponse.headers
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
rawResponseToResponse : Response Bytes
|
|
380
|
+
rawResponseToResponse =
|
|
381
|
+
if 200 <= rawResponse.statusCode && rawResponse.statusCode < 300 then
|
|
382
|
+
GoodStatus_ asMetadata rawBytesBody
|
|
383
|
+
|
|
384
|
+
else
|
|
385
|
+
BadStatus_ asMetadata rawBytesBody
|
|
386
|
+
in
|
|
387
|
+
rawResponseToResponse
|
|
388
|
+
|> mapResponse
|
|
389
|
+
|> Ok
|
|
390
|
+
|
|
391
|
+
( ExpectBytes bytesDecoder, RequestsAndPending.BytesBody rawBytes, _ ) ->
|
|
392
|
+
rawBytes
|
|
393
|
+
|> Bytes.Decode.decode bytesDecoder
|
|
394
|
+
|> Result.fromMaybe
|
|
395
|
+
(Pages.StaticHttpRequest.DecoderError
|
|
396
|
+
"Bytes decoding failed."
|
|
454
397
|
)
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
398
|
+
|
|
399
|
+
( ExpectWhatever whateverValue, RequestsAndPending.WhateverBody, _ ) ->
|
|
400
|
+
Ok whateverValue
|
|
401
|
+
|
|
402
|
+
_ ->
|
|
403
|
+
Err
|
|
404
|
+
(Pages.StaticHttpRequest.DecoderError
|
|
405
|
+
"Internal error - unexpected body, expect, and raw response combination."
|
|
406
|
+
)
|
|
407
|
+
)
|
|
408
|
+
|> toResult
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
{-| -}
|
|
413
|
+
type alias Metadata =
|
|
414
|
+
{ url : String
|
|
415
|
+
, statusCode : Int
|
|
416
|
+
, statusText : String
|
|
417
|
+
, headers : Dict String String
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
{-| -}
|
|
422
|
+
type Response body
|
|
423
|
+
= BadUrl_ String
|
|
424
|
+
| Timeout_
|
|
425
|
+
| NetworkError_
|
|
426
|
+
| BadStatus_ Metadata body
|
|
427
|
+
| GoodStatus_ Metadata body
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
{-| -}
|
|
431
|
+
type Error
|
|
432
|
+
= BadUrl String
|
|
433
|
+
| Timeout
|
|
434
|
+
| NetworkError
|
|
435
|
+
| BadStatus Metadata String
|
|
436
|
+
| BadBody String
|
|
458
437
|
|
|
459
438
|
|
|
460
|
-
toResult : Result Pages.StaticHttpRequest.Error
|
|
439
|
+
toResult : Result Pages.StaticHttpRequest.Error b -> RawRequest b
|
|
461
440
|
toResult result =
|
|
462
441
|
case result of
|
|
463
442
|
Err error ->
|
|
464
443
|
RequestError error
|
|
465
444
|
|
|
466
|
-
Ok
|
|
467
|
-
ApiRoute
|
|
445
|
+
Ok okValue ->
|
|
446
|
+
ApiRoute okValue
|