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.
Files changed (136) hide show
  1. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  2. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  3. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  4. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  5. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmi +0 -0
  6. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolationsTest.elmo +0 -0
  7. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
  8. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
  9. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
  10. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
  11. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  12. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  13. package/generator/{template/public/style.css → review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock} +0 -0
  14. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  15. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -0
  16. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +6795 -0
  17. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +27617 -0
  18. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +110 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +187 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/js/package.json +1 -0
  21. package/generator/review/elm-stuff/tests-0.19.1/src/Reporter.elm +26 -0
  22. package/generator/review/elm-stuff/tests-0.19.1/src/Runner.elm +62 -0
  23. package/generator/review/elm.json +13 -4
  24. package/{src → generator/review/src}/Pages/Review/NoContractViolations.elm +148 -148
  25. package/generator/review/tests/Pages/Review/NoContractViolationsTest.elm +331 -0
  26. package/generator/src/RouteBuilder.elm +420 -0
  27. package/generator/src/SharedTemplate.elm +4 -5
  28. package/generator/src/SiteConfig.elm +3 -9
  29. package/generator/src/build.js +308 -95
  30. package/generator/src/cli.js +103 -8
  31. package/generator/src/codegen.js +192 -35
  32. package/generator/src/compile-elm.js +183 -31
  33. package/generator/src/dev-server.js +353 -96
  34. package/generator/src/elm-application.json +3 -1
  35. package/generator/src/elm-codegen.js +34 -0
  36. package/generator/src/elm-file-constants.js +2 -0
  37. package/generator/src/error-formatter.js +20 -1
  38. package/generator/src/generate-template-module-connector.js +120 -924
  39. package/generator/src/hello.ts +5 -0
  40. package/generator/src/pre-render-html.js +58 -104
  41. package/generator/src/render-worker.js +27 -13
  42. package/generator/src/render.js +252 -197
  43. package/generator/src/request-cache-fs.js +18 -0
  44. package/generator/src/request-cache.js +128 -56
  45. package/generator/src/rewrite-client-elm-json.js +49 -0
  46. package/generator/src/route-codegen-helpers.js +62 -1
  47. package/generator/static-code/dev-style.css +22 -0
  48. package/generator/static-code/elm-pages.js +43 -39
  49. package/generator/static-code/hmr.js +98 -88
  50. package/generator/template/app/Api.elm +25 -0
  51. package/generator/template/app/ErrorPage.elm +38 -0
  52. package/generator/template/app/Route/Index.elm +87 -0
  53. package/generator/template/{src → app}/Shared.elm +34 -13
  54. package/generator/template/app/Site.elm +19 -0
  55. package/generator/template/{src → app}/View.elm +0 -0
  56. package/generator/template/elm-pages.config.mjs +5 -0
  57. package/generator/template/elm.json +1 -0
  58. package/generator/template/{public/index.js → index.ts} +7 -3
  59. package/generator/template/package.json +4 -4
  60. package/generator/template/public/favicon.ico +0 -0
  61. package/generator/template/public/images/icon-png.png +0 -0
  62. package/generator/template/src/.gitkeep +0 -0
  63. package/generator/template/style.css +4 -0
  64. package/package.json +30 -23
  65. package/src/ApiRoute.elm +176 -43
  66. package/src/BuildError.elm +10 -1
  67. package/src/CookieParser.elm +84 -0
  68. package/src/DataSource/Env.elm +38 -0
  69. package/src/DataSource/File.elm +27 -16
  70. package/src/DataSource/Glob.elm +126 -80
  71. package/src/DataSource/Http.elm +283 -304
  72. package/src/DataSource/Internal/Glob.elm +5 -21
  73. package/src/DataSource/Internal/Request.elm +25 -0
  74. package/src/DataSource/Port.elm +17 -14
  75. package/src/DataSource.elm +55 -318
  76. package/src/Form/Field.elm +717 -0
  77. package/src/Form/FieldStatus.elm +36 -0
  78. package/src/Form/FieldView.elm +417 -0
  79. package/src/Form/FormData.elm +22 -0
  80. package/src/Form/Validation.elm +391 -0
  81. package/src/Form/Value.elm +118 -0
  82. package/src/Form.elm +1683 -0
  83. package/src/FormData.elm +58 -0
  84. package/src/FormDecoder.elm +102 -0
  85. package/src/Head/Seo.elm +12 -4
  86. package/src/Head.elm +12 -2
  87. package/src/HtmlPrinter.elm +1 -1
  88. package/src/Internal/ApiRoute.elm +17 -4
  89. package/src/Internal/Request.elm +7 -0
  90. package/src/PageServerResponse.elm +68 -0
  91. package/src/Pages/ContentCache.elm +1 -229
  92. package/src/Pages/Fetcher.elm +58 -0
  93. package/src/Pages/FormState.elm +256 -0
  94. package/src/Pages/Generate.elm +800 -0
  95. package/src/Pages/Internal/Form.elm +17 -0
  96. package/src/Pages/Internal/NotFoundReason.elm +3 -55
  97. package/src/Pages/Internal/Platform/Cli.elm +777 -579
  98. package/src/Pages/Internal/Platform/Effect.elm +5 -5
  99. package/src/Pages/Internal/Platform/StaticResponses.elm +178 -394
  100. package/src/Pages/Internal/Platform/ToJsPayload.elm +24 -23
  101. package/src/Pages/Internal/Platform.elm +1244 -504
  102. package/src/Pages/Internal/ResponseSketch.elm +19 -0
  103. package/src/Pages/Internal/RoutePattern.elm +596 -45
  104. package/src/Pages/Manifest.elm +26 -0
  105. package/src/Pages/Msg.elm +79 -0
  106. package/src/Pages/ProgramConfig.elm +67 -14
  107. package/src/Pages/SiteConfig.elm +3 -6
  108. package/src/Pages/StaticHttp/Request.elm +4 -2
  109. package/src/Pages/StaticHttpRequest.elm +50 -215
  110. package/src/Pages/Transition.elm +70 -0
  111. package/src/Path.elm +1 -0
  112. package/src/Pattern.elm +98 -0
  113. package/src/RenderRequest.elm +2 -2
  114. package/src/RequestsAndPending.elm +111 -9
  115. package/src/Server/Request.elm +1253 -0
  116. package/src/Server/Response.elm +292 -0
  117. package/src/Server/Session.elm +316 -0
  118. package/src/Server/SetCookie.elm +169 -0
  119. package/src/TerminalText.elm +1 -1
  120. package/src/Test/Html/Internal/ElmHtml/Markdown.elm +0 -1
  121. package/src/Test/Html/Internal/ElmHtml/ToString.elm +1 -1
  122. package/generator/src/Page.elm +0 -359
  123. package/generator/src/codegen-template-module.js +0 -183
  124. package/generator/src/elm-pages-js-minified.js +0 -1
  125. package/generator/template/src/Api.elm +0 -14
  126. package/generator/template/src/Page/Index.elm +0 -69
  127. package/generator/template/src/Site.elm +0 -41
  128. package/src/DataSource/ServerRequest.elm +0 -60
  129. package/src/Internal/OptimizedDecoder.elm +0 -18
  130. package/src/KeepOrDiscard.elm +0 -6
  131. package/src/OptimizedDecoder/Pipeline.elm +0 -335
  132. package/src/OptimizedDecoder.elm +0 -818
  133. package/src/Pages/Internal/ApplicationType.elm +0 -6
  134. package/src/Pages/Secrets.elm +0 -83
  135. package/src/Secrets.elm +0 -111
  136. package/src/SecretsDict.elm +0 -45
@@ -1,86 +1,37 @@
1
- module Pages.Internal.Platform.StaticResponses exposing (FinishKind(..), NextStep(..), StaticResponses, batchUpdate, error, nextStep, renderApiRequest, renderSingleRoute)
1
+ module Pages.Internal.Platform.StaticResponses exposing (FinishKind(..), NextStep(..), StaticResponses, batchUpdate, empty, nextStep, renderApiRequest, renderSingleRoute)
2
2
 
3
- import ApiRoute
4
3
  import BuildError exposing (BuildError)
5
4
  import DataSource exposing (DataSource)
6
- import DataSource.Http exposing (RequestDetails)
7
5
  import Dict exposing (Dict)
8
6
  import Dict.Extra
9
- import Html exposing (Html)
10
- import HtmlPrinter exposing (htmlToString)
11
- import Internal.ApiRoute exposing (ApiRoute(..))
12
- import Pages.Internal.ApplicationType as ApplicationType
13
7
  import Pages.Internal.NotFoundReason exposing (NotFoundReason)
14
- import Pages.SiteConfig exposing (SiteConfig)
15
8
  import Pages.StaticHttp.Request as HashRequest
16
9
  import Pages.StaticHttpRequest as StaticHttpRequest
17
- import Path exposing (Path)
18
10
  import RequestsAndPending exposing (RequestsAndPending)
19
- import Secrets
20
- import SecretsDict exposing (SecretsDict)
21
11
  import Set exposing (Set)
22
- import TerminalText as Terminal
23
12
 
24
13
 
25
14
  type StaticResponses
26
15
  = ApiRequest StaticHttpResult
27
- | StaticResponses (Dict String StaticHttpResult)
28
- | CheckIfHandled (DataSource (Maybe NotFoundReason)) StaticHttpResult (Dict String StaticHttpResult)
16
+ | StaticResponses StaticHttpResult
17
+ | CheckIfHandled (DataSource (Maybe NotFoundReason)) StaticHttpResult StaticHttpResult
29
18
 
30
19
 
31
20
  type StaticHttpResult
32
21
  = NotFetched (DataSource ()) (Dict String (Result () String))
33
22
 
34
23
 
35
- error : StaticResponses
36
- error =
37
- StaticResponses Dict.empty
38
-
39
-
40
- buildTimeFilesRequest :
41
- { config
42
- | apiRoutes :
43
- (Html Never -> String)
44
- -> List (ApiRoute.ApiRoute ApiRoute.Response)
45
- }
46
- -> DataSource (List (Result String { path : List String, content : String }))
47
- buildTimeFilesRequest config =
48
- config.apiRoutes htmlToString
49
- |> List.map
50
- (\(ApiRoute handler) ->
51
- handler.buildTimeRoutes
52
- |> DataSource.andThen
53
- (\paths ->
54
- paths
55
- |> List.map
56
- (\path ->
57
- handler.matchesToResponse path
58
- |> DataSource.map
59
- (\maybeResponse ->
60
- case maybeResponse of
61
- Nothing ->
62
- Err ""
63
-
64
- Just response ->
65
- Ok { path = path |> String.split "/", content = response.body }
66
- )
67
- )
68
- |> DataSource.combine
69
- )
70
- )
71
- |> DataSource.combine
72
- |> DataSource.map List.concat
24
+ empty : StaticResponses
25
+ empty =
26
+ StaticResponses
27
+ (NotFetched (DataSource.succeed ()) Dict.empty)
73
28
 
74
29
 
75
30
  renderSingleRoute :
76
- { config
77
- | routeToPath : route -> List String
78
- }
79
- -> { path : Path, frontmatter : route }
80
- -> DataSource a
31
+ DataSource a
81
32
  -> DataSource (Maybe NotFoundReason)
82
33
  -> StaticResponses
83
- renderSingleRoute config pathAndRoute request cliData =
34
+ renderSingleRoute request cliData =
84
35
  CheckIfHandled cliData
85
36
  (NotFetched
86
37
  (cliData
@@ -88,12 +39,7 @@ renderSingleRoute config pathAndRoute request cliData =
88
39
  )
89
40
  Dict.empty
90
41
  )
91
- (Dict.fromList
92
- [ ( config.routeToPath pathAndRoute.frontmatter |> String.join "/"
93
- , NotFetched (DataSource.map (\_ -> ()) request) Dict.empty
94
- )
95
- ]
96
- )
42
+ (NotFetched (DataSource.map (\_ -> ()) request) Dict.empty)
97
43
 
98
44
 
99
45
  renderApiRequest :
@@ -109,221 +55,176 @@ renderApiRequest request =
109
55
 
110
56
  batchUpdate :
111
57
  List
112
- { request :
113
- { masked : RequestDetails, unmasked : RequestDetails }
114
- , response : String
58
+ { request : HashRequest.Request
59
+ , response : RequestsAndPending.Response
115
60
  }
116
61
  ->
117
62
  { model
118
63
  | staticResponses : StaticResponses
119
- , allRawResponses : Dict String (Maybe String)
64
+ , allRawResponses : RequestsAndPending
120
65
  }
121
66
  ->
122
67
  { model
123
68
  | staticResponses : StaticResponses
124
- , allRawResponses : Dict String (Maybe String)
69
+ , allRawResponses : RequestsAndPending
125
70
  }
126
71
  batchUpdate newEntries model =
127
- let
128
- newResponses : Dict String String
129
- newResponses =
130
- newEntries
131
- |> List.map
132
- (\newEntry ->
133
- ( HashRequest.hash newEntry.request.masked, newEntry.response )
134
- )
135
- |> Dict.fromList
136
-
137
- updatedAllResponses : Dict String (Maybe String)
138
- updatedAllResponses =
139
- Dict.merge
140
- (\key a -> Dict.insert key (Just a))
141
- (\key a _ -> Dict.insert key (Just a))
142
- (\key b -> Dict.insert key b)
143
- newResponses
144
- model.allRawResponses
145
- Dict.empty
146
- in
147
72
  { model
148
- | allRawResponses = updatedAllResponses
73
+ | allRawResponses = insertAll newEntries model.allRawResponses
149
74
  }
150
75
 
151
76
 
152
- encode : RequestsAndPending -> Dict String StaticHttpResult -> Result (List BuildError) (Dict String (Dict String String))
153
- encode requestsAndPending staticResponses =
154
- staticResponses
155
- |> Dict.filter
156
- (\key _ ->
157
- key /= cliDictKey
158
- )
159
- |> Dict.toList
160
- |> List.map
161
- (\( key, NotFetched request _ ) ->
162
- StaticHttpRequest.strippedResponsesEncode ApplicationType.Cli request requestsAndPending
163
- |> Result.map (Tuple.pair key)
164
- )
165
- |> combineMultipleErrors
166
- |> Result.mapError List.concat
167
- |> Result.map Dict.fromList
168
-
77
+ insertAll :
78
+ List
79
+ { request : HashRequest.Request
80
+ , response : RequestsAndPending.Response
81
+ }
82
+ -> RequestsAndPending
83
+ -> RequestsAndPending
84
+ insertAll newEntries dict =
85
+ case newEntries of
86
+ [] ->
87
+ dict
169
88
 
170
- cliDictKey : String
171
- cliDictKey =
172
- "////elm-pages-CLI////"
89
+ info :: rest ->
90
+ insertAll
91
+ rest
92
+ (Dict.update (HashRequest.hash info.request) (\_ -> Just (Just info.response)) dict)
173
93
 
174
94
 
175
95
  type NextStep route
176
- = Continue (Dict String (Maybe String)) (List { masked : RequestDetails, unmasked : RequestDetails }) (Maybe (List route))
96
+ = Continue RequestsAndPending (List HashRequest.Request) (Maybe (List route))
177
97
  | Finish (FinishKind route)
178
98
 
179
99
 
180
100
  type FinishKind route
181
101
  = ApiResponse
182
102
  | Errors (List BuildError)
183
- | Page (Dict String String)
184
103
 
185
104
 
186
105
  nextStep :
187
- { config
188
- | getStaticRoutes : DataSource (List route)
189
- , routeToPath : route -> List String
190
- , data : route -> DataSource pageData
191
- , sharedData : DataSource sharedData
192
- , site : Maybe (SiteConfig siteData)
193
- , apiRoutes : (Html Never -> String) -> List (ApiRoute.ApiRoute ApiRoute.Response)
106
+ { model
107
+ | staticResponses : StaticResponses
108
+ , errors : List BuildError
109
+ , allRawResponses : RequestsAndPending
194
110
  }
195
- ->
196
- { model
197
- | staticResponses : StaticResponses
198
- , secrets : SecretsDict
199
- , errors : List BuildError
200
- , allRawResponses : Dict String (Maybe String)
201
- }
202
111
  -> Maybe (List route)
203
112
  -> ( StaticResponses, NextStep route )
204
- nextStep config ({ secrets, allRawResponses, errors } as model) maybeRoutes =
113
+ nextStep ({ allRawResponses, errors } as model) maybeRoutes =
205
114
  let
206
- staticResponses : Dict String StaticHttpResult
115
+ staticRequestsStatus : StaticHttpRequest.Status ()
116
+ staticRequestsStatus =
117
+ allRawResponses
118
+ |> StaticHttpRequest.cacheRequestResolution request
119
+
120
+ request : DataSource ()
121
+ request =
122
+ case staticResponses of
123
+ NotFetched request_ _ ->
124
+ request_
125
+
126
+ staticResponses : StaticHttpResult
207
127
  staticResponses =
208
128
  case model.staticResponses of
209
129
  StaticResponses s ->
210
130
  s
211
131
 
212
132
  ApiRequest staticHttpResult ->
213
- Dict.singleton cliDictKey staticHttpResult
133
+ staticHttpResult
214
134
 
215
135
  CheckIfHandled _ staticHttpResult _ ->
216
- Dict.singleton cliDictKey staticHttpResult
217
-
218
- generatedFiles : List (Result String { path : List String, content : String })
219
- generatedFiles =
220
- resolvedGenerateFilesResult |> Result.withDefault []
221
-
222
- resolvedGenerateFilesResult : Result StaticHttpRequest.Error (List (Result String { path : List String, content : String }))
223
- resolvedGenerateFilesResult =
224
- StaticHttpRequest.resolve ApplicationType.Cli
225
- (buildTimeFilesRequest config)
226
- (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value))
227
-
228
- generatedFileErrors : List BuildError
229
- generatedFileErrors =
230
- generatedFiles
231
- |> List.filterMap
232
- (\result ->
233
- case result of
234
- Ok _ ->
235
- Nothing
236
-
237
- Err error_ ->
238
- Just
239
- { title = "Generate Files Error"
240
- , message =
241
- [ Terminal.text "I encountered an Err from your generateFiles function. Message:\n"
242
- , Terminal.text <| "Error: " ++ error_
243
- ]
244
- , path = "Site.elm"
245
- , fatal = True
246
- }
247
- )
248
-
249
- allErrors : List BuildError
250
- allErrors =
251
- errors ++ failedRequests ++ generatedFileErrors
136
+ staticHttpResult
252
137
 
253
138
  pendingRequests : Bool
254
139
  pendingRequests =
255
- staticResponses
256
- |> Dict.Extra.any
257
- (\_ entry ->
258
- case entry of
259
- NotFetched request rawResponses ->
260
- let
261
- staticRequestsStatus : StaticHttpRequest.Status ()
262
- staticRequestsStatus =
263
- allRawResponses
264
- |> StaticHttpRequest.cacheRequestResolution ApplicationType.Cli request
140
+ case staticResponses of
141
+ NotFetched _ rawResponses ->
142
+ let
143
+ hasPermanentError : Bool
144
+ hasPermanentError =
145
+ case staticRequestsStatus of
146
+ StaticHttpRequest.HasPermanentError _ ->
147
+ True
265
148
 
266
- hasPermanentError : Bool
267
- hasPermanentError =
268
- case staticRequestsStatus of
269
- StaticHttpRequest.HasPermanentError _ ->
270
- True
149
+ _ ->
150
+ False
271
151
 
272
- _ ->
273
- False
152
+ hasPermanentHttpError : Bool
153
+ hasPermanentHttpError =
154
+ not (List.isEmpty errors)
274
155
 
275
- hasPermanentHttpError : Bool
276
- hasPermanentHttpError =
277
- not (List.isEmpty errors)
156
+ ( allUrlsKnown, knownUrlsToFetch ) =
157
+ case staticRequestsStatus of
158
+ StaticHttpRequest.Incomplete newUrlsToFetch ->
159
+ ( False, newUrlsToFetch )
278
160
 
279
- ( allUrlsKnown, knownUrlsToFetch ) =
280
- case staticRequestsStatus of
281
- StaticHttpRequest.Incomplete newUrlsToFetch ->
282
- ( False, newUrlsToFetch )
161
+ _ ->
162
+ ( True, [] )
283
163
 
284
- _ ->
285
- ( True, [] )
286
-
287
- fetchedAllKnownUrls : Bool
288
- fetchedAllKnownUrls =
289
- (rawResponses
290
- |> Dict.keys
291
- |> Set.fromList
292
- |> Set.union (allRawResponses |> Dict.keys |> Set.fromList)
293
- )
294
- |> Set.diff
295
- (knownUrlsToFetch
296
- |> List.map Secrets.maskedLookup
297
- |> List.map HashRequest.hash
298
- |> Set.fromList
299
- )
300
- |> Set.isEmpty
301
- in
302
- if hasPermanentHttpError || hasPermanentError || (allUrlsKnown && fetchedAllKnownUrls) then
303
- False
164
+ fetchedAllKnownUrls : Bool
165
+ fetchedAllKnownUrls =
166
+ (rawResponses
167
+ |> Dict.keys
168
+ |> Set.fromList
169
+ |> Set.union (allRawResponses |> Dict.keys |> Set.fromList)
170
+ )
171
+ |> Set.diff
172
+ (knownUrlsToFetch
173
+ |> List.map HashRequest.hash
174
+ |> Set.fromList
175
+ )
176
+ |> Set.isEmpty
177
+ in
178
+ not (hasPermanentHttpError || hasPermanentError || (allUrlsKnown && fetchedAllKnownUrls))
179
+ in
180
+ if pendingRequests then
181
+ let
182
+ urlsToPerform : List HashRequest.Request
183
+ urlsToPerform =
184
+ -- TODO is this redundant with cacheRequestResolution?
185
+ StaticHttpRequest.resolveUrls request allRawResponses
186
+
187
+ newAllRawResponses : RequestsAndPending
188
+ newAllRawResponses =
189
+ Dict.union allRawResponses dictOfNewUrlsToPerform
190
+
191
+ dictOfNewUrlsToPerform : RequestsAndPending
192
+ dictOfNewUrlsToPerform =
193
+ urlsToPerform
194
+ |> List.map (\url -> ( HashRequest.hash url, Nothing ))
195
+ |> Dict.fromList
196
+
197
+ maskedToUnmasked : Dict String HashRequest.Request
198
+ maskedToUnmasked =
199
+ urlsToPerform
200
+ |> List.map
201
+ (\secureUrl ->
202
+ ( HashRequest.hash secureUrl, secureUrl )
203
+ )
204
+ |> Dict.fromList
205
+
206
+ alreadyPerformed : Set String
207
+ alreadyPerformed =
208
+ allRawResponses
209
+ |> Dict.keys
210
+ |> Set.fromList
211
+
212
+ newThing : List HashRequest.Request
213
+ newThing =
214
+ maskedToUnmasked
215
+ |> Dict.Extra.removeMany alreadyPerformed
216
+ |> Dict.values
217
+ in
218
+ ( model.staticResponses, Continue newAllRawResponses newThing maybeRoutes )
304
219
 
305
- else
306
- True
307
- )
308
-
309
- failedRequests : List BuildError
310
- failedRequests =
311
- staticResponses
312
- |> Dict.toList
313
- |> List.concatMap
314
- (\( path, NotFetched request _ ) ->
220
+ else
221
+ let
222
+ allErrors : List BuildError
223
+ allErrors =
224
+ let
225
+ failedRequests : List BuildError
226
+ failedRequests =
315
227
  let
316
- staticRequestsStatus : StaticHttpRequest.Status ()
317
- staticRequestsStatus =
318
- StaticHttpRequest.cacheRequestResolution
319
- ApplicationType.Cli
320
- request
321
- usableRawResponses
322
-
323
- usableRawResponses : RequestsAndPending
324
- usableRawResponses =
325
- allRawResponses
326
-
327
228
  maybePermanentError : Maybe StaticHttpRequest.Error
328
229
  maybePermanentError =
329
230
  case staticRequestsStatus of
@@ -336,205 +237,88 @@ nextStep config ({ secrets, allRawResponses, errors } as model) maybeRoutes =
336
237
  decoderErrors : List BuildError
337
238
  decoderErrors =
338
239
  maybePermanentError
339
- |> Maybe.map (StaticHttpRequest.toBuildError path)
240
+ |> Maybe.map (StaticHttpRequest.toBuildError "TODO PATH")
340
241
  |> Maybe.map List.singleton
341
242
  |> Maybe.withDefault []
342
243
  in
343
244
  decoderErrors
344
- )
345
- in
346
- if pendingRequests then
347
- let
348
- requestContinuations : List ( String, DataSource () )
349
- requestContinuations =
350
- staticResponses
351
- |> Dict.toList
352
- |> List.map
353
- (\( path, NotFetched request _ ) ->
354
- ( path, request )
355
- )
356
- in
357
- case
358
- performStaticHttpRequests allRawResponses secrets requestContinuations
359
- of
360
- Ok urlsToPerform ->
361
- let
362
- newAllRawResponses : Dict String (Maybe String)
363
- newAllRawResponses =
364
- Dict.union allRawResponses dictOfNewUrlsToPerform
365
-
366
- dictOfNewUrlsToPerform : Dict String (Maybe String)
367
- dictOfNewUrlsToPerform =
368
- urlsToPerform
369
- |> List.map .masked
370
- |> List.map HashRequest.hash
371
- |> List.map (\hashedUrl -> ( hashedUrl, Nothing ))
372
- |> Dict.fromList
373
-
374
- maskedToUnmasked : Dict String { masked : RequestDetails, unmasked : RequestDetails }
375
- maskedToUnmasked =
376
- urlsToPerform
377
- -- |> List.map (\secureUrl -> ( Pages.Internal.Secrets.masked secureUrl, secureUrl ))
378
- |> List.map
379
- (\secureUrl ->
380
- -- ( hashUrl secureUrl, { unmasked = secureUrl, masked = secureUrl } )
381
- ( HashRequest.hash secureUrl.masked, secureUrl )
382
- )
383
- |> Dict.fromList
384
-
385
- alreadyPerformed : Set String
386
- alreadyPerformed =
387
- allRawResponses
388
- |> Dict.keys
389
- |> Set.fromList
390
-
391
- newThing : List { masked : RequestDetails, unmasked : RequestDetails }
392
- newThing =
393
- maskedToUnmasked
394
- |> Dict.Extra.removeMany alreadyPerformed
395
- |> Dict.toList
396
- |> List.map
397
- (\( _, secureUrl ) ->
398
- secureUrl
399
- )
400
245
  in
401
- ( model.staticResponses, Continue newAllRawResponses newThing maybeRoutes )
402
-
403
- Err error_ ->
404
- ( model.staticResponses, Finish (Errors <| (error_ ++ failedRequests ++ errors)) )
405
-
406
- else
246
+ errors ++ failedRequests
247
+ in
407
248
  case model.staticResponses of
408
249
  StaticResponses _ ->
409
- --let
410
- -- siteStaticData =
411
- -- StaticHttpRequest.resolve ApplicationType.Cli
412
- -- config.site.staticData
413
- -- (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value))
414
- -- |> Result.mapError (StaticHttpRequest.toBuildError "Site.elm")
415
- --in
416
- --case siteStaticData of
417
- -- Err siteStaticDataError ->
418
- -- ( staticResponses_
419
- -- , ToJsPayload.toJsPayload
420
- -- (encode allRawResponses mode staticResponses)
421
- -- generatedOkayFiles
422
- -- allRawResponses
423
- -- (siteStaticDataError :: allErrors)
424
- -- |> Finish
425
- -- )
426
- --
427
- -- Ok okSiteStaticData ->
428
250
  ( model.staticResponses
429
- , case encode allRawResponses staticResponses of
430
- Ok encodedResponses ->
431
- -- TODO send all global head tags on initial call
432
- if List.length allErrors > 0 then
433
- allErrors
434
- |> Errors
435
- |> Finish
436
-
437
- else
438
- Page (encodedResponses |> Dict.values |> List.head |> Maybe.withDefault Dict.empty)
439
- |> Finish
440
-
441
- Err buildErrors ->
442
- (allErrors ++ buildErrors)
443
- |> Errors
444
- |> Finish
251
+ , if List.length allErrors > 0 then
252
+ allErrors
253
+ |> Errors
254
+ |> Finish
255
+
256
+ else
257
+ Finish ApiResponse
445
258
  )
446
259
 
447
260
  ApiRequest _ ->
448
261
  ( model.staticResponses
449
- , ApiResponse
450
- |> Finish
262
+ , if List.length allErrors > 0 then
263
+ allErrors
264
+ |> Errors
265
+ |> Finish
266
+
267
+ else
268
+ ApiResponse
269
+ |> Finish
451
270
  )
452
271
 
453
272
  CheckIfHandled pageFoundDataSource (NotFetched _ _) andThenRequest ->
454
273
  let
455
274
  pageFoundResult : Result StaticHttpRequest.Error (Maybe NotFoundReason)
456
275
  pageFoundResult =
457
- StaticHttpRequest.resolve ApplicationType.Cli
276
+ StaticHttpRequest.resolve
458
277
  pageFoundDataSource
459
- (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value))
278
+ allRawResponses
460
279
  in
461
280
  case pageFoundResult of
462
281
  Ok Nothing ->
463
- nextStep config { model | staticResponses = StaticResponses andThenRequest } maybeRoutes
282
+ nextStep { model | staticResponses = StaticResponses andThenRequest } maybeRoutes
464
283
 
465
284
  Ok (Just _) ->
466
- ( StaticResponses Dict.empty
285
+ ( empty
467
286
  , Finish ApiResponse
468
- -- TODO should there be a new type for 404response? Or something else?
287
+ -- TODO change data type here so you can avoid running `resolve` again from `Cli.elm` since it can be expensive
469
288
  )
470
289
 
471
290
  Err error_ ->
291
+ let
292
+ failedRequests : List BuildError
293
+ failedRequests =
294
+ let
295
+ maybePermanentError : Maybe StaticHttpRequest.Error
296
+ maybePermanentError =
297
+ case staticRequestsStatus of
298
+ StaticHttpRequest.HasPermanentError theError ->
299
+ Just theError
300
+
301
+ _ ->
302
+ Nothing
303
+
304
+ decoderErrors : List BuildError
305
+ decoderErrors =
306
+ maybePermanentError
307
+ |> Maybe.map (StaticHttpRequest.toBuildError "TODO PATH")
308
+ |> Maybe.map List.singleton
309
+ |> Maybe.withDefault []
310
+ in
311
+ decoderErrors
312
+ in
472
313
  ( model.staticResponses
473
314
  , Finish
474
315
  (Errors <|
475
- ([ StaticHttpRequest.toBuildError
316
+ (StaticHttpRequest.toBuildError
476
317
  -- TODO give more fine-grained error reference
477
318
  "get static routes"
478
319
  error_
479
- ]
480
- ++ failedRequests
320
+ :: failedRequests
481
321
  ++ errors
482
322
  )
483
323
  )
484
324
  )
485
-
486
-
487
- performStaticHttpRequests :
488
- Dict String (Maybe String)
489
- -> SecretsDict
490
- -> List ( String, DataSource a )
491
- -> Result (List BuildError) (List { unmasked : RequestDetails, masked : RequestDetails })
492
- performStaticHttpRequests allRawResponses secrets staticRequests =
493
- staticRequests
494
- -- TODO look for performance bottleneck in this double nesting
495
- |> List.map
496
- (\( _, request ) ->
497
- StaticHttpRequest.resolveUrls ApplicationType.Cli request allRawResponses
498
- )
499
- |> List.concat
500
- -- TODO prevent duplicates... can't because Set needs comparable
501
- -- |> Set.fromList
502
- -- |> Set.toList
503
- |> List.map
504
- (\urlBuilder ->
505
- urlBuilder
506
- |> Secrets.lookup secrets
507
- |> Result.map
508
- (\unmasked ->
509
- { unmasked = unmasked
510
- , masked = Secrets.maskedLookup urlBuilder
511
- }
512
- )
513
- )
514
- |> combineMultipleErrors
515
- |> Result.mapError List.concat
516
-
517
-
518
- combineMultipleErrors : List (Result error a) -> Result (List error) (List a)
519
- combineMultipleErrors results =
520
- List.foldr
521
- (\result soFarResult ->
522
- case soFarResult of
523
- Ok soFarOk ->
524
- case result of
525
- Ok value ->
526
- value :: soFarOk |> Ok
527
-
528
- Err error_ ->
529
- Err [ error_ ]
530
-
531
- Err errorsSoFar ->
532
- case result of
533
- Ok _ ->
534
- Err errorsSoFar
535
-
536
- Err error_ ->
537
- Err <| error_ :: errorsSoFar
538
- )
539
- (Ok [])
540
- results