elm-pages 3.0.0-beta.4 → 3.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/adapter/netlify.js +207 -0
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2678 -2725
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +17004 -13817
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/dead-code-review/elm.json +9 -7
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
- 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/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1447 -342
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25025 -21739
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/review/elm.json +10 -10
- package/generator/src/RouteBuilder.elm +115 -109
- package/generator/src/SharedTemplate.elm +3 -2
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +209 -92
- package/generator/src/cli.js +292 -88
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +43 -26
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +176 -138
- package/generator/src/dir-helpers.js +9 -26
- package/generator/src/elm-codegen.js +5 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +12 -11
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +23 -23
- package/generator/src/init.js +9 -8
- package/generator/src/pre-render-html.js +39 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +25 -28
- package/generator/src/render.js +321 -142
- package/generator/src/request-cache.js +265 -162
- package/generator/src/resolve-elm-module.js +64 -0
- package/generator/src/rewrite-client-elm-json.js +6 -5
- package/generator/src/rewrite-elm-json-help.js +56 -0
- package/generator/src/rewrite-elm-json.js +17 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +12 -7
- package/generator/src/vite-utils.js +77 -0
- package/generator/static-code/elm-pages.js +10 -0
- package/generator/static-code/hmr.js +79 -13
- package/generator/template/app/Api.elm +6 -5
- package/generator/template/app/Effect.elm +123 -0
- package/generator/template/app/ErrorPage.elm +37 -6
- package/generator/template/app/Route/Index.elm +17 -10
- package/generator/template/app/Shared.elm +24 -47
- package/generator/template/app/Site.elm +19 -6
- package/generator/template/app/View.elm +1 -8
- package/generator/template/elm-tooling.json +0 -3
- package/generator/template/elm.json +32 -24
- package/generator/template/package.json +10 -4
- package/package.json +30 -27
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +325 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +171 -56
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +679 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +69 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +537 -0
- package/src/FatalError.elm +90 -0
- package/src/Head.elm +237 -7
- package/src/HtmlPrinter.elm +7 -3
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/Form.elm +229 -0
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Msg.elm +93 -0
- package/src/Pages/Internal/Platform/Cli.elm +612 -763
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +379 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +65 -276
- package/src/Pages/Internal/Platform/ToJsPayload.elm +6 -9
- package/src/Pages/Internal/Platform.elm +327 -194
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +29 -4
- package/src/Pages/PageUrl.elm +23 -9
- package/src/Pages/ProgramConfig.elm +26 -15
- package/src/Pages/Script.elm +109 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -99
- package/src/Pages/Transition.elm +12 -3
- package/src/PagesMsg.elm +82 -0
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +21 -172
- package/src/RequestsAndPending.elm +37 -20
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +546 -0
- package/src/Scaffold/Route.elm +1402 -0
- package/src/Server/Request.elm +73 -72
- package/src/Server/Session.elm +62 -42
- package/src/Server/SetCookie.elm +12 -4
- package/src/Stub.elm +53 -0
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/DataSource/Env.elm +0 -38
- package/src/DataSource/Http.elm +0 -446
- package/src/DataSource/Internal/Request.elm +0 -20
- package/src/DataSource/Port.elm +0 -90
- package/src/DataSource.elm +0 -538
- package/src/Form/Field.elm +0 -717
- package/src/Form/FieldStatus.elm +0 -36
- package/src/Form/FieldView.elm +0 -417
- package/src/Form/FormData.elm +0 -22
- package/src/Form/Validation.elm +0 -391
- package/src/Form/Value.elm +0 -118
- package/src/Form.elm +0 -1683
- package/src/FormDecoder.elm +0 -102
- package/src/Pages/FormState.elm +0 -256
- package/src/Pages/Generate.elm +0 -800
- package/src/Pages/Internal/Form.elm +0 -17
- package/src/Pages/Msg.elm +0 -79
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
module
|
|
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 [`
|
|
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
|
|
46
|
-
import
|
|
47
|
-
import
|
|
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
|
|
59
|
-
import
|
|
60
|
-
import Decode
|
|
66
|
+
import BackendTask exposing (BackendTask)
|
|
67
|
+
import BackendTask.File as File
|
|
68
|
+
import Decode exposing (Decoder)
|
|
61
69
|
|
|
62
|
-
blogPost :
|
|
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
|
|
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
|
|
95
|
-
import
|
|
96
|
-
import Decode
|
|
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
|
-
|
|
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 :
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
|
153
|
-
import
|
|
154
|
-
import Decode
|
|
190
|
+
import BackendTask exposing (BackendTask)
|
|
191
|
+
import BackendTask.File as File
|
|
192
|
+
import Decode exposing (Decoder)
|
|
155
193
|
|
|
156
|
-
blogPost :
|
|
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 [`
|
|
212
|
+
the [`BackendTask`](BackendTask) API along with [`BackendTask.Glob`](BackendTask-Glob).
|
|
175
213
|
|
|
176
|
-
import
|
|
177
|
-
import
|
|
178
|
-
import Decode
|
|
214
|
+
import BackendTask exposing (BackendTask)
|
|
215
|
+
import BackendTask.File as File
|
|
216
|
+
import Decode exposing (Decoder)
|
|
179
217
|
|
|
180
|
-
blogPostFiles :
|
|
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.
|
|
225
|
+
|> Glob.toBackendTask
|
|
188
226
|
|
|
189
|
-
allMetadata :
|
|
227
|
+
allMetadata : BackendTask (List BlogPostMetadata)
|
|
190
228
|
allMetadata =
|
|
191
229
|
blogPostFiles
|
|
192
|
-
|>
|
|
230
|
+
|> BackendTask.map
|
|
193
231
|
(List.map
|
|
194
232
|
(File.onlyFrontmatter
|
|
195
233
|
blogPostDecoder
|
|
196
234
|
)
|
|
197
235
|
)
|
|
198
|
-
|>
|
|
236
|
+
|> BackendTask.resolve
|
|
199
237
|
|
|
200
238
|
-}
|
|
201
|
-
onlyFrontmatter :
|
|
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
|
-
|
|
204
|
-
|
|
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
|
|
280
|
+
import BackendTask exposing (BackendTask)
|
|
220
281
|
|
|
221
|
-
data :
|
|
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 :
|
|
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
|
|
245
|
-
import
|
|
312
|
+
import BackendTask exposing (BackendTask)
|
|
313
|
+
import BackendTask.File as File
|
|
246
314
|
|
|
247
|
-
elmJsonFile :
|
|
315
|
+
elmJsonFile : BackendTask String
|
|
248
316
|
elmJsonFile =
|
|
249
317
|
File.rawFile "hello.txt"
|
|
250
318
|
|
|
251
319
|
-}
|
|
252
|
-
rawFile : 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
|
|
262
|
-
import
|
|
329
|
+
import BackendTask exposing (BackendTask)
|
|
330
|
+
import BackendTask.File as File
|
|
263
331
|
|
|
264
|
-
sourceDirectories :
|
|
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 :
|
|
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
|
-
|>
|
|
353
|
+
|> BackendTask.andThen
|
|
278
354
|
(\jsonString ->
|
|
279
355
|
jsonString
|
|
280
356
|
|> Decode.decodeString jsonFileDecoder
|
|
281
|
-
|> Result.mapError
|
|
282
|
-
|
|
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 ->
|
|
379
|
+
read : String -> Decoder a -> BackendTask { fatal : FatalError, recoverable : FileReadError error } a
|
|
294
380
|
read filePath decoder =
|
|
295
|
-
|
|
381
|
+
BackendTask.Internal.Request.request
|
|
296
382
|
{ name = "read-file"
|
|
297
|
-
, body =
|
|
298
|
-
, expect =
|
|
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
|
+
)
|