elm-pages 3.0.0-beta.3 → 3.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +10 -1
  2. package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2864 -2589
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1327 -122
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15295 -13271
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  14. package/generator/dead-code-review/elm.json +8 -6
  15. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
  16. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
  17. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  21. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1327 -122
  22. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14621 -12637
  23. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  24. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
  25. package/generator/review/elm.json +8 -8
  26. package/generator/src/RouteBuilder.elm +113 -107
  27. package/generator/src/SharedTemplate.elm +3 -2
  28. package/generator/src/SiteConfig.elm +3 -2
  29. package/generator/src/basepath-middleware.js +3 -3
  30. package/generator/src/build.js +123 -87
  31. package/generator/src/cli.js +256 -77
  32. package/generator/src/codegen.js +29 -27
  33. package/generator/src/compatibility-key.js +3 -0
  34. package/generator/src/compile-elm.js +25 -25
  35. package/generator/src/config.js +39 -0
  36. package/generator/src/copy-dir.js +2 -2
  37. package/generator/src/dev-server.js +150 -133
  38. package/generator/src/dir-helpers.js +9 -26
  39. package/generator/src/elm-codegen.js +5 -4
  40. package/generator/src/elm-file-constants.js +2 -3
  41. package/generator/src/error-formatter.js +12 -11
  42. package/generator/src/file-helpers.js +3 -4
  43. package/generator/src/generate-template-module-connector.js +23 -22
  44. package/generator/src/init.js +9 -8
  45. package/generator/src/pre-render-html.js +39 -28
  46. package/generator/src/render-test.js +109 -0
  47. package/generator/src/render-worker.js +25 -28
  48. package/generator/src/render.js +322 -142
  49. package/generator/src/request-cache.js +252 -163
  50. package/generator/src/rewrite-client-elm-json.js +5 -5
  51. package/generator/src/rewrite-elm-json.js +7 -7
  52. package/generator/src/route-codegen-helpers.js +16 -31
  53. package/generator/src/seo-renderer.js +12 -7
  54. package/generator/src/vite-utils.js +77 -0
  55. package/generator/static-code/hmr.js +79 -13
  56. package/generator/template/app/Api.elm +6 -5
  57. package/generator/template/app/Effect.elm +123 -0
  58. package/generator/template/app/ErrorPage.elm +37 -6
  59. package/generator/template/app/Route/Index.elm +17 -10
  60. package/generator/template/app/Shared.elm +24 -47
  61. package/generator/template/app/Site.elm +19 -6
  62. package/generator/template/app/View.elm +1 -8
  63. package/generator/template/elm-tooling.json +0 -3
  64. package/generator/template/elm.json +34 -25
  65. package/generator/template/package.json +10 -4
  66. package/package.json +23 -22
  67. package/src/ApiRoute.elm +199 -61
  68. package/src/BackendTask/Custom.elm +325 -0
  69. package/src/BackendTask/Env.elm +90 -0
  70. package/src/{DataSource → BackendTask}/File.elm +128 -43
  71. package/src/{DataSource → BackendTask}/Glob.elm +136 -125
  72. package/src/BackendTask/Http.elm +673 -0
  73. package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
  74. package/src/BackendTask/Internal/Request.elm +28 -0
  75. package/src/BackendTask/Random.elm +79 -0
  76. package/src/BackendTask/Time.elm +47 -0
  77. package/src/BackendTask.elm +537 -0
  78. package/src/FatalError.elm +89 -0
  79. package/src/Form/Field.elm +21 -9
  80. package/src/Form/FieldView.elm +94 -14
  81. package/src/Form.elm +275 -400
  82. package/src/Head.elm +237 -7
  83. package/src/HtmlPrinter.elm +7 -3
  84. package/src/Internal/ApiRoute.elm +7 -5
  85. package/src/PageServerResponse.elm +6 -1
  86. package/src/Pages/FormState.elm +6 -5
  87. package/src/Pages/GeneratorProgramConfig.elm +15 -0
  88. package/src/Pages/Internal/FatalError.elm +5 -0
  89. package/src/Pages/Internal/Form.elm +21 -1
  90. package/src/Pages/{Msg.elm → Internal/Msg.elm} +26 -16
  91. package/src/Pages/Internal/Platform/Cli.elm +507 -763
  92. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  93. package/src/Pages/Internal/Platform/Effect.elm +1 -2
  94. package/src/Pages/Internal/Platform/GeneratorApplication.elm +373 -0
  95. package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
  96. package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
  97. package/src/Pages/Internal/Platform.elm +215 -102
  98. package/src/Pages/Internal/Script.elm +17 -0
  99. package/src/Pages/Internal/StaticHttpBody.elm +35 -1
  100. package/src/Pages/Manifest.elm +29 -4
  101. package/src/Pages/PageUrl.elm +23 -9
  102. package/src/Pages/ProgramConfig.elm +14 -10
  103. package/src/Pages/Script.elm +109 -0
  104. package/src/Pages/SiteConfig.elm +3 -2
  105. package/src/Pages/StaticHttp/Request.elm +2 -2
  106. package/src/Pages/StaticHttpRequest.elm +23 -98
  107. package/src/PagesMsg.elm +92 -0
  108. package/src/Path.elm +16 -19
  109. package/src/QueryParams.elm +21 -172
  110. package/src/RequestsAndPending.elm +8 -19
  111. package/src/Result/Extra.elm +26 -0
  112. package/src/Scaffold/Form.elm +484 -0
  113. package/src/Scaffold/Route.elm +1376 -0
  114. package/src/Server/Request.elm +43 -37
  115. package/src/Server/Session.elm +34 -34
  116. package/src/Server/SetCookie.elm +1 -1
  117. package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
  118. package/src/DataSource/Env.elm +0 -38
  119. package/src/DataSource/Http.elm +0 -446
  120. package/src/DataSource/Internal/Request.elm +0 -20
  121. package/src/DataSource/Port.elm +0 -90
  122. package/src/DataSource.elm +0 -538
  123. package/src/Pages/Generate.elm +0 -800
@@ -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
66
+ import BackendTask exposing (BackendTask)
67
+ import BackendTask.File as File
60
68
  import Decode as 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
102
+ import BackendTask exposing (BackendTask)
103
+ import BackendTask.File as File
96
104
  import Decode as 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,7 +141,15 @@ 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
154
  read filePath
139
155
  (body
@@ -144,16 +160,23 @@ bodyWithFrontmatter frontmatterDecoder filePath =
144
160
  )
145
161
 
146
162
 
163
+ {-| -}
164
+ type FileReadError decoding
165
+ = FileDoesntExist
166
+ | FileReadError String
167
+ | DecodingError decoding
168
+
169
+
147
170
  {-| Same as `bodyWithFrontmatter` except it doesn't include the body.
148
171
 
149
172
  This is often useful when you're aggregating data, for example getting a listing of blog posts and need to extract
150
173
  just the metadata.
151
174
 
152
- import DataSource exposing (DataSource)
153
- import DataSource.File as File
175
+ import BackendTask exposing (BackendTask)
176
+ import BackendTask.File as File
154
177
  import Decode as Decode exposing (Decoder)
155
178
 
156
- blogPost : DataSource BlogPostMetadata
179
+ blogPost : BackendTask BlogPostMetadata
157
180
  blogPost =
158
181
  File.onlyFrontmatter
159
182
  blogPostDecoder
@@ -171,34 +194,42 @@ just the metadata.
171
194
  (Decode.field "tags" (Decode.list Decode.string))
172
195
 
173
196
  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).
197
+ the [`BackendTask`](BackendTask) API along with [`BackendTask.Glob`](BackendTask-Glob).
175
198
 
176
- import DataSource exposing (DataSource)
177
- import DataSource.File as File
199
+ import BackendTask exposing (BackendTask)
200
+ import BackendTask.File as File
178
201
  import Decode as Decode exposing (Decoder)
179
202
 
180
- blogPostFiles : DataSource (List String)
203
+ blogPostFiles : BackendTask (List String)
181
204
  blogPostFiles =
182
205
  Glob.succeed identity
183
206
  |> Glob.captureFilePath
184
207
  |> Glob.match (Glob.literal "content/blog/")
185
208
  |> Glob.match Glob.wildcard
186
209
  |> Glob.match (Glob.literal ".md")
187
- |> Glob.toDataSource
210
+ |> Glob.toBackendTask
188
211
 
189
- allMetadata : DataSource (List BlogPostMetadata)
212
+ allMetadata : BackendTask (List BlogPostMetadata)
190
213
  allMetadata =
191
214
  blogPostFiles
192
- |> DataSource.map
215
+ |> BackendTask.map
193
216
  (List.map
194
217
  (File.onlyFrontmatter
195
218
  blogPostDecoder
196
219
  )
197
220
  )
198
- |> DataSource.resolve
221
+ |> BackendTask.resolve
199
222
 
200
223
  -}
201
- onlyFrontmatter : Decoder frontmatter -> String -> DataSource frontmatter
224
+ onlyFrontmatter :
225
+ Decoder frontmatter
226
+ -> String
227
+ ->
228
+ BackendTask
229
+ { fatal : FatalError
230
+ , recoverable : FileReadError Decode.Error
231
+ }
232
+ frontmatter
202
233
  onlyFrontmatter frontmatterDecoder filePath =
203
234
  read filePath
204
235
  (frontmatter frontmatterDecoder)
@@ -216,16 +247,23 @@ tags: elm
216
247
  Hey there! This is my first post :)
217
248
  ```
218
249
 
219
- import DataSource exposing (DataSource)
250
+ import BackendTask exposing (BackendTask)
220
251
 
221
- data : DataSource String
252
+ data : BackendTask String
222
253
  data =
223
254
  bodyWithoutFrontmatter "blog/hello-world.md"
224
255
 
225
256
  Then data will yield the value `"Hey there! This is my first post :)"`.
226
257
 
227
258
  -}
228
- bodyWithoutFrontmatter : String -> DataSource String
259
+ bodyWithoutFrontmatter :
260
+ String
261
+ ->
262
+ BackendTask
263
+ { fatal : FatalError
264
+ , recoverable : FileReadError decoderError
265
+ }
266
+ String
229
267
  bodyWithoutFrontmatter filePath =
230
268
  read filePath
231
269
  body
@@ -241,15 +279,15 @@ use `jsonFile` to get the benefits of the `Decode` here.
241
279
 
242
280
  You could read a file called `hello.txt` in your root project directory like this:
243
281
 
244
- import DataSource exposing (DataSource)
245
- import DataSource.File as File
282
+ import BackendTask exposing (BackendTask)
283
+ import BackendTask.File as File
246
284
 
247
- elmJsonFile : DataSource String
285
+ elmJsonFile : BackendTask String
248
286
  elmJsonFile =
249
287
  File.rawFile "hello.txt"
250
288
 
251
289
  -}
252
- rawFile : String -> DataSource String
290
+ rawFile : String -> BackendTask { fatal : FatalError, recoverable : FileReadError decoderError } String
253
291
  rawFile filePath =
254
292
  read filePath (Decode.field "rawFile" Decode.string)
255
293
 
@@ -258,10 +296,10 @@ rawFile filePath =
258
296
 
259
297
  The Decode will strip off any unused JSON data.
260
298
 
261
- import DataSource exposing (DataSource)
262
- import DataSource.File as File
299
+ import BackendTask exposing (BackendTask)
300
+ import BackendTask.File as File
263
301
 
264
- sourceDirectories : DataSource (List String)
302
+ sourceDirectories : BackendTask (List String)
265
303
  sourceDirectories =
266
304
  File.jsonFile
267
305
  (Decode.field
@@ -271,15 +309,33 @@ The Decode will strip off any unused JSON data.
271
309
  "elm.json"
272
310
 
273
311
  -}
274
- jsonFile : Decoder a -> String -> DataSource a
312
+ jsonFile :
313
+ Decoder a
314
+ -> String
315
+ ->
316
+ BackendTask
317
+ { fatal : FatalError
318
+ , recoverable : FileReadError Decode.Error
319
+ }
320
+ a
275
321
  jsonFile jsonFileDecoder filePath =
276
322
  rawFile filePath
277
- |> DataSource.andThen
323
+ |> BackendTask.andThen
278
324
  (\jsonString ->
279
325
  jsonString
280
326
  |> Decode.decodeString jsonFileDecoder
281
- |> Result.mapError Decode.errorToString
282
- |> DataSource.fromResult
327
+ |> Result.mapError
328
+ (\jsonDecodeError ->
329
+ FatalError.recoverable
330
+ { title = "JSON Decoding Error"
331
+ , body =
332
+ [ TerminalText.text (Decode.errorToString jsonDecodeError)
333
+ ]
334
+ |> TerminalText.toString
335
+ }
336
+ (DecodingError jsonDecodeError)
337
+ )
338
+ |> BackendTask.fromResult
283
339
  )
284
340
 
285
341
 
@@ -290,10 +346,39 @@ body =
290
346
  Decode.field "withoutFrontmatter" Decode.string
291
347
 
292
348
 
293
- read : String -> Decoder a -> DataSource a
349
+ read : String -> Decoder a -> BackendTask { fatal : FatalError, recoverable : FileReadError error } a
294
350
  read filePath decoder =
295
- DataSource.Internal.Request.request
351
+ BackendTask.Internal.Request.request
296
352
  { name = "read-file"
297
- , body = DataSource.Http.stringBody "" filePath
298
- , expect = decoder |> DataSource.Http.expectJson
353
+ , body = BackendTask.Http.stringBody "" filePath
354
+ , expect =
355
+ Decode.oneOf
356
+ [ Decode.field "errorCode"
357
+ (Decode.map Err (errorDecoder filePath))
358
+ , decoder |> Decode.map Ok
359
+ ]
360
+ |> BackendTask.Http.expectJson
299
361
  }
362
+ |> BackendTask.andThen BackendTask.fromResult
363
+
364
+
365
+ errorDecoder :
366
+ String
367
+ ->
368
+ Decoder
369
+ { fatal : FatalError
370
+ , recoverable : FileReadError decoding
371
+ }
372
+ errorDecoder filePath =
373
+ Decode.succeed
374
+ (FatalError.recoverable
375
+ { title = "File Doesn't Exist"
376
+ , body =
377
+ [ TerminalText.text "Couldn't find file at path `"
378
+ , TerminalText.yellow filePath
379
+ , TerminalText.text "`"
380
+ ]
381
+ |> TerminalText.toString
382
+ }
383
+ FileDoesntExist
384
+ )