elm-pages 3.0.0-beta.4 → 3.0.0-beta.41

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 (148) hide show
  1. package/README.md +10 -1
  2. package/adapter/netlify.js +207 -0
  3. package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2828 -2933
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +17004 -13817
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  14. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  15. package/generator/dead-code-review/elm.json +9 -7
  16. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
  17. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmi +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Internal-RoutePattern.elmo +0 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmi +0 -0
  21. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-NoContractViolations.elmo +0 -0
  22. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  23. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  24. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  25. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  26. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
  27. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25025 -21739
  28. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  29. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  30. package/generator/review/elm.json +10 -10
  31. package/generator/src/RouteBuilder.elm +121 -114
  32. package/generator/src/SharedTemplate.elm +8 -7
  33. package/generator/src/SiteConfig.elm +3 -2
  34. package/generator/src/basepath-middleware.js +3 -3
  35. package/generator/src/build.js +209 -92
  36. package/generator/src/cli.js +292 -88
  37. package/generator/src/codegen.js +29 -27
  38. package/generator/src/compatibility-key.js +3 -0
  39. package/generator/src/compile-elm.js +43 -26
  40. package/generator/src/config.js +39 -0
  41. package/generator/src/copy-dir.js +2 -2
  42. package/generator/src/dev-server.js +176 -138
  43. package/generator/src/dir-helpers.js +9 -26
  44. package/generator/src/elm-codegen.js +5 -4
  45. package/generator/src/elm-file-constants.js +2 -3
  46. package/generator/src/error-formatter.js +12 -11
  47. package/generator/src/file-helpers.js +3 -4
  48. package/generator/src/generate-template-module-connector.js +23 -23
  49. package/generator/src/init.js +9 -8
  50. package/generator/src/pre-render-html.js +39 -28
  51. package/generator/src/render-test.js +109 -0
  52. package/generator/src/render-worker.js +25 -28
  53. package/generator/src/render.js +321 -142
  54. package/generator/src/request-cache.js +265 -162
  55. package/generator/src/resolve-elm-module.js +64 -0
  56. package/generator/src/rewrite-client-elm-json.js +6 -5
  57. package/generator/src/rewrite-elm-json-help.js +56 -0
  58. package/generator/src/rewrite-elm-json.js +17 -7
  59. package/generator/src/route-codegen-helpers.js +16 -31
  60. package/generator/src/seo-renderer.js +12 -7
  61. package/generator/src/vite-utils.js +77 -0
  62. package/generator/static-code/elm-pages.js +10 -0
  63. package/generator/static-code/hmr.js +79 -13
  64. package/generator/template/app/Api.elm +6 -5
  65. package/generator/template/app/Effect.elm +123 -0
  66. package/generator/template/app/ErrorPage.elm +37 -6
  67. package/generator/template/app/Route/Index.elm +17 -10
  68. package/generator/template/app/Shared.elm +24 -47
  69. package/generator/template/app/Site.elm +19 -6
  70. package/generator/template/app/View.elm +1 -8
  71. package/generator/template/elm-tooling.json +0 -3
  72. package/generator/template/elm.json +32 -24
  73. package/generator/template/package.json +10 -4
  74. package/package.json +30 -27
  75. package/src/ApiRoute.elm +199 -61
  76. package/src/BackendTask/Custom.elm +325 -0
  77. package/src/BackendTask/Env.elm +90 -0
  78. package/src/{DataSource → BackendTask}/File.elm +171 -56
  79. package/src/{DataSource → BackendTask}/Glob.elm +136 -125
  80. package/src/BackendTask/Http.elm +679 -0
  81. package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
  82. package/src/BackendTask/Internal/Request.elm +69 -0
  83. package/src/BackendTask/Random.elm +79 -0
  84. package/src/BackendTask/Time.elm +47 -0
  85. package/src/BackendTask.elm +531 -0
  86. package/src/FatalError.elm +90 -0
  87. package/src/Head/Seo.elm +4 -4
  88. package/src/Head.elm +237 -7
  89. package/src/HtmlPrinter.elm +7 -3
  90. package/src/Internal/ApiRoute.elm +7 -5
  91. package/src/PageServerResponse.elm +6 -1
  92. package/src/Pages/ConcurrentSubmission.elm +127 -0
  93. package/src/Pages/Form.elm +340 -0
  94. package/src/Pages/FormData.elm +18 -0
  95. package/src/Pages/GeneratorProgramConfig.elm +15 -0
  96. package/src/Pages/Internal/FatalError.elm +5 -0
  97. package/src/Pages/Internal/Msg.elm +93 -0
  98. package/src/Pages/Internal/NotFoundReason.elm +4 -4
  99. package/src/Pages/Internal/Platform/Cli.elm +617 -768
  100. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  101. package/src/Pages/Internal/Platform/Effect.elm +1 -2
  102. package/src/Pages/Internal/Platform/GeneratorApplication.elm +379 -0
  103. package/src/Pages/Internal/Platform/StaticResponses.elm +65 -276
  104. package/src/Pages/Internal/Platform/ToJsPayload.elm +6 -9
  105. package/src/Pages/Internal/Platform.elm +359 -225
  106. package/src/Pages/Internal/ResponseSketch.elm +2 -2
  107. package/src/Pages/Internal/Script.elm +17 -0
  108. package/src/Pages/Internal/StaticHttpBody.elm +35 -1
  109. package/src/Pages/Manifest.elm +52 -11
  110. package/src/Pages/Navigation.elm +87 -0
  111. package/src/Pages/PageUrl.elm +26 -12
  112. package/src/Pages/ProgramConfig.elm +35 -23
  113. package/src/Pages/Script.elm +166 -0
  114. package/src/Pages/SiteConfig.elm +3 -2
  115. package/src/Pages/StaticHttp/Request.elm +2 -2
  116. package/src/Pages/StaticHttpRequest.elm +23 -99
  117. package/src/Pages/Url.elm +3 -3
  118. package/src/PagesMsg.elm +88 -0
  119. package/src/QueryParams.elm +21 -172
  120. package/src/RenderRequest.elm +7 -7
  121. package/src/RequestsAndPending.elm +37 -20
  122. package/src/Result/Extra.elm +26 -0
  123. package/src/Scaffold/Form.elm +569 -0
  124. package/src/Scaffold/Route.elm +1411 -0
  125. package/src/Server/Request.elm +74 -72
  126. package/src/Server/Session.elm +62 -42
  127. package/src/Server/SetCookie.elm +80 -32
  128. package/src/Stub.elm +53 -0
  129. package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
  130. package/src/{Path.elm → UrlPath.elm} +33 -36
  131. package/src/DataSource/Env.elm +0 -38
  132. package/src/DataSource/Http.elm +0 -446
  133. package/src/DataSource/Internal/Request.elm +0 -20
  134. package/src/DataSource/Port.elm +0 -90
  135. package/src/DataSource.elm +0 -538
  136. package/src/Form/Field.elm +0 -717
  137. package/src/Form/FieldStatus.elm +0 -36
  138. package/src/Form/FieldView.elm +0 -417
  139. package/src/Form/FormData.elm +0 -22
  140. package/src/Form/Validation.elm +0 -391
  141. package/src/Form/Value.elm +0 -118
  142. package/src/Form.elm +0 -1683
  143. package/src/FormDecoder.elm +0 -102
  144. package/src/Pages/FormState.elm +0 -256
  145. package/src/Pages/Generate.elm +0 -800
  146. package/src/Pages/Internal/Form.elm +0 -17
  147. package/src/Pages/Msg.elm +0 -79
  148. package/src/Pages/Transition.elm +0 -70
@@ -1,9 +1,10 @@
1
- module DataSource.File exposing
1
+ module BackendTask.File exposing
2
2
  ( bodyWithFrontmatter, bodyWithoutFrontmatter, onlyFrontmatter
3
3
  , jsonFile, rawFile
4
+ , FileReadError(..)
4
5
  )
5
6
 
6
- {-| This module lets you read files from the local filesystem as a [`DataSource`](DataSource#DataSource).
7
+ {-| This module lets you read files from the local filesystem as a [`BackendTask`](BackendTask#BackendTask).
7
8
  File paths are relative to the root of your `elm-pages` project (next to the `elm.json` file and `src/` directory).
8
9
 
9
10
 
@@ -40,12 +41,19 @@ plain old JSON in Elm.
40
41
 
41
42
  @docs jsonFile, rawFile
42
43
 
44
+
45
+ ## FatalErrors
46
+
47
+ @docs FileReadError
48
+
43
49
  -}
44
50
 
45
- import DataSource exposing (DataSource)
46
- import DataSource.Http
47
- import DataSource.Internal.Request
51
+ import BackendTask exposing (BackendTask)
52
+ import BackendTask.Http
53
+ import BackendTask.Internal.Request
54
+ import FatalError exposing (FatalError)
48
55
  import Json.Decode as Decode exposing (Decoder)
56
+ import TerminalText
49
57
 
50
58
 
51
59
  frontmatter : Decoder frontmatter -> Decoder frontmatter
@@ -55,11 +63,11 @@ frontmatter frontmatterDecoder =
55
63
 
56
64
  {-|
57
65
 
58
- import DataSource exposing (DataSource)
59
- import DataSource.File as File
60
- import Decode as Decode exposing (Decoder)
66
+ import BackendTask exposing (BackendTask)
67
+ import BackendTask.File as File
68
+ import Decode exposing (Decoder)
61
69
 
62
- blogPost : DataSource BlogPostMetadata
70
+ blogPost : BackendTask BlogPostMetadata
63
71
  blogPost =
64
72
  File.bodyWithFrontmatter blogPostDecoder
65
73
  "blog/hello-world.md"
@@ -81,7 +89,7 @@ frontmatter frontmatterDecoder =
81
89
  Decode.map (String.split " ")
82
90
  Decode.string
83
91
 
84
- This will give us a DataSource that results in the following value:
92
+ This will give us a BackendTask that results in the following value:
85
93
 
86
94
  value =
87
95
  { body = "Hey there! This is my first post :)"
@@ -91,13 +99,13 @@ This will give us a DataSource that results in the following value:
91
99
 
92
100
  It's common to parse the body with a markdown parser or other format.
93
101
 
94
- import DataSource exposing (DataSource)
95
- import DataSource.File as File
96
- import Decode as Decode exposing (Decoder)
102
+ import BackendTask exposing (BackendTask)
103
+ import BackendTask.File as File
104
+ import Decode exposing (Decoder)
97
105
  import Html exposing (Html)
98
106
 
99
107
  example :
100
- DataSource
108
+ BackendTask
101
109
  { title : String
102
110
  , body : List (Html msg)
103
111
  }
@@ -133,15 +141,45 @@ It's common to parse the body with a markdown parser or other format.
133
141
  )
134
142
 
135
143
  -}
136
- bodyWithFrontmatter : (String -> Decoder frontmatter) -> String -> DataSource frontmatter
144
+ bodyWithFrontmatter :
145
+ (String -> Decoder frontmatter)
146
+ -> String
147
+ ->
148
+ BackendTask
149
+ { fatal : FatalError
150
+ , recoverable : FileReadError Decode.Error
151
+ }
152
+ frontmatter
137
153
  bodyWithFrontmatter frontmatterDecoder filePath =
138
- read filePath
139
- (body
140
- |> Decode.andThen
141
- (\bodyString ->
142
- frontmatter (frontmatterDecoder bodyString)
143
- )
144
- )
154
+ BackendTask.Internal.Request.request2
155
+ { name = "read-file"
156
+ , body = BackendTask.Http.stringBody "" filePath
157
+ , expect =
158
+ body
159
+ |> Decode.andThen
160
+ (\bodyString ->
161
+ frontmatter (frontmatterDecoder bodyString)
162
+ )
163
+ , errorDecoder = Decode.field "errorCode" (errorDecoder filePath)
164
+ , onError =
165
+ \frontmatterDecodeError ->
166
+ { fatal =
167
+ { title = "BackendTask.File Decoder Error"
168
+ , body =
169
+ "I encountered a Json Decoder error from a call to BackendTask.File.bodyWithFrontmatter.\n\n"
170
+ ++ Decode.errorToString frontmatterDecodeError
171
+ }
172
+ |> FatalError.build
173
+ , recoverable = DecodingError frontmatterDecodeError
174
+ }
175
+ }
176
+
177
+
178
+ {-| -}
179
+ type FileReadError decoding
180
+ = FileDoesntExist
181
+ | FileReadError String
182
+ | DecodingError decoding
145
183
 
146
184
 
147
185
  {-| Same as `bodyWithFrontmatter` except it doesn't include the body.
@@ -149,11 +187,11 @@ bodyWithFrontmatter frontmatterDecoder filePath =
149
187
  This is often useful when you're aggregating data, for example getting a listing of blog posts and need to extract
150
188
  just the metadata.
151
189
 
152
- import DataSource exposing (DataSource)
153
- import DataSource.File as File
154
- import Decode as Decode exposing (Decoder)
190
+ import BackendTask exposing (BackendTask)
191
+ import BackendTask.File as File
192
+ import Decode exposing (Decoder)
155
193
 
156
- blogPost : DataSource BlogPostMetadata
194
+ blogPost : BackendTask BlogPostMetadata
157
195
  blogPost =
158
196
  File.onlyFrontmatter
159
197
  blogPostDecoder
@@ -171,37 +209,60 @@ just the metadata.
171
209
  (Decode.field "tags" (Decode.list Decode.string))
172
210
 
173
211
  If you wanted to use this to get this metadata for all blog posts in a folder, you could use
174
- the [`DataSource`](DataSource) API along with [`DataSource.Glob`](DataSource-Glob).
212
+ the [`BackendTask`](BackendTask) API along with [`BackendTask.Glob`](BackendTask-Glob).
175
213
 
176
- import DataSource exposing (DataSource)
177
- import DataSource.File as File
178
- import Decode as Decode exposing (Decoder)
214
+ import BackendTask exposing (BackendTask)
215
+ import BackendTask.File as File
216
+ import Decode exposing (Decoder)
179
217
 
180
- blogPostFiles : DataSource (List String)
218
+ blogPostFiles : BackendTask (List String)
181
219
  blogPostFiles =
182
220
  Glob.succeed identity
183
221
  |> Glob.captureFilePath
184
222
  |> Glob.match (Glob.literal "content/blog/")
185
223
  |> Glob.match Glob.wildcard
186
224
  |> Glob.match (Glob.literal ".md")
187
- |> Glob.toDataSource
225
+ |> Glob.toBackendTask
188
226
 
189
- allMetadata : DataSource (List BlogPostMetadata)
227
+ allMetadata : BackendTask (List BlogPostMetadata)
190
228
  allMetadata =
191
229
  blogPostFiles
192
- |> DataSource.map
230
+ |> BackendTask.map
193
231
  (List.map
194
232
  (File.onlyFrontmatter
195
233
  blogPostDecoder
196
234
  )
197
235
  )
198
- |> DataSource.resolve
236
+ |> BackendTask.resolve
199
237
 
200
238
  -}
201
- onlyFrontmatter : Decoder frontmatter -> String -> DataSource frontmatter
239
+ onlyFrontmatter :
240
+ Decoder frontmatter
241
+ -> String
242
+ ->
243
+ BackendTask
244
+ { fatal : FatalError
245
+ , recoverable : FileReadError Decode.Error
246
+ }
247
+ frontmatter
202
248
  onlyFrontmatter frontmatterDecoder filePath =
203
- read filePath
204
- (frontmatter frontmatterDecoder)
249
+ BackendTask.Internal.Request.request2
250
+ { name = "read-file"
251
+ , body = BackendTask.Http.stringBody "" filePath
252
+ , expect = frontmatter frontmatterDecoder
253
+ , errorDecoder = Decode.field "errorCode" (errorDecoder filePath)
254
+ , onError =
255
+ \frontmatterDecodeError ->
256
+ { fatal =
257
+ { title = "BackendTask.File Decoder Error"
258
+ , body =
259
+ "I encountered a Json Decoder error from a call to BackendTask.File.onlyFrontmatter.\n\n"
260
+ ++ Decode.errorToString frontmatterDecodeError
261
+ }
262
+ |> FatalError.build
263
+ , recoverable = DecodingError frontmatterDecodeError
264
+ }
265
+ }
205
266
 
206
267
 
207
268
  {-| Same as `bodyWithFrontmatter` except it doesn't include the frontmatter.
@@ -216,16 +277,23 @@ tags: elm
216
277
  Hey there! This is my first post :)
217
278
  ```
218
279
 
219
- import DataSource exposing (DataSource)
280
+ import BackendTask exposing (BackendTask)
220
281
 
221
- data : DataSource String
282
+ data : BackendTask String
222
283
  data =
223
284
  bodyWithoutFrontmatter "blog/hello-world.md"
224
285
 
225
286
  Then data will yield the value `"Hey there! This is my first post :)"`.
226
287
 
227
288
  -}
228
- bodyWithoutFrontmatter : String -> DataSource String
289
+ bodyWithoutFrontmatter :
290
+ String
291
+ ->
292
+ BackendTask
293
+ { fatal : FatalError
294
+ , recoverable : FileReadError decoderError
295
+ }
296
+ String
229
297
  bodyWithoutFrontmatter filePath =
230
298
  read filePath
231
299
  body
@@ -241,15 +309,15 @@ use `jsonFile` to get the benefits of the `Decode` here.
241
309
 
242
310
  You could read a file called `hello.txt` in your root project directory like this:
243
311
 
244
- import DataSource exposing (DataSource)
245
- import DataSource.File as File
312
+ import BackendTask exposing (BackendTask)
313
+ import BackendTask.File as File
246
314
 
247
- elmJsonFile : DataSource String
315
+ elmJsonFile : BackendTask String
248
316
  elmJsonFile =
249
317
  File.rawFile "hello.txt"
250
318
 
251
319
  -}
252
- rawFile : String -> DataSource String
320
+ rawFile : String -> BackendTask { fatal : FatalError, recoverable : FileReadError decoderError } String
253
321
  rawFile filePath =
254
322
  read filePath (Decode.field "rawFile" Decode.string)
255
323
 
@@ -258,10 +326,10 @@ rawFile filePath =
258
326
 
259
327
  The Decode will strip off any unused JSON data.
260
328
 
261
- import DataSource exposing (DataSource)
262
- import DataSource.File as File
329
+ import BackendTask exposing (BackendTask)
330
+ import BackendTask.File as File
263
331
 
264
- sourceDirectories : DataSource (List String)
332
+ sourceDirectories : BackendTask (List String)
265
333
  sourceDirectories =
266
334
  File.jsonFile
267
335
  (Decode.field
@@ -271,15 +339,33 @@ The Decode will strip off any unused JSON data.
271
339
  "elm.json"
272
340
 
273
341
  -}
274
- jsonFile : Decoder a -> String -> DataSource a
342
+ jsonFile :
343
+ Decoder a
344
+ -> String
345
+ ->
346
+ BackendTask
347
+ { fatal : FatalError
348
+ , recoverable : FileReadError Decode.Error
349
+ }
350
+ a
275
351
  jsonFile jsonFileDecoder filePath =
276
352
  rawFile filePath
277
- |> DataSource.andThen
353
+ |> BackendTask.andThen
278
354
  (\jsonString ->
279
355
  jsonString
280
356
  |> Decode.decodeString jsonFileDecoder
281
- |> Result.mapError Decode.errorToString
282
- |> DataSource.fromResult
357
+ |> Result.mapError
358
+ (\jsonDecodeError ->
359
+ FatalError.recoverable
360
+ { title = "JSON Decoding Error"
361
+ , body =
362
+ [ TerminalText.text (Decode.errorToString jsonDecodeError)
363
+ ]
364
+ |> TerminalText.toString
365
+ }
366
+ (DecodingError jsonDecodeError)
367
+ )
368
+ |> BackendTask.fromResult
283
369
  )
284
370
 
285
371
 
@@ -290,10 +376,39 @@ body =
290
376
  Decode.field "withoutFrontmatter" Decode.string
291
377
 
292
378
 
293
- read : String -> Decoder a -> DataSource a
379
+ read : String -> Decoder a -> BackendTask { fatal : FatalError, recoverable : FileReadError error } a
294
380
  read filePath decoder =
295
- DataSource.Internal.Request.request
381
+ BackendTask.Internal.Request.request
296
382
  { name = "read-file"
297
- , body = DataSource.Http.stringBody "" filePath
298
- , expect = decoder |> DataSource.Http.expectJson
383
+ , body = BackendTask.Http.stringBody "" filePath
384
+ , expect =
385
+ Decode.oneOf
386
+ [ Decode.field "errorCode"
387
+ (Decode.map Err (errorDecoder filePath))
388
+ , decoder |> Decode.map Ok
389
+ ]
390
+ |> BackendTask.Http.expectJson
299
391
  }
392
+ |> BackendTask.andThen BackendTask.fromResult
393
+
394
+
395
+ errorDecoder :
396
+ String
397
+ ->
398
+ Decoder
399
+ { fatal : FatalError
400
+ , recoverable : FileReadError decoding
401
+ }
402
+ errorDecoder filePath =
403
+ Decode.succeed
404
+ (FatalError.recoverable
405
+ { title = "File Doesn't Exist"
406
+ , body =
407
+ [ TerminalText.text "Couldn't find file at path `"
408
+ , TerminalText.yellow filePath
409
+ , TerminalText.text "`"
410
+ ]
411
+ |> TerminalText.toString
412
+ }
413
+ FileDoesntExist
414
+ )