elm-pages 3.0.0-beta.17 → 3.0.0-beta.19

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 (46) hide show
  1. package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +0 -0
  2. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  5. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  6. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  7. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  8. package/generator/src/basepath-middleware.js +3 -3
  9. package/generator/src/build.js +36 -30
  10. package/generator/src/cli.js +30 -23
  11. package/generator/src/codegen.js +19 -18
  12. package/generator/src/compatibility-key.js +1 -1
  13. package/generator/src/compile-elm.js +20 -22
  14. package/generator/src/config.js +2 -4
  15. package/generator/src/dev-server.js +47 -30
  16. package/generator/src/dir-helpers.js +9 -25
  17. package/generator/src/elm-codegen.js +2 -4
  18. package/generator/src/elm-file-constants.js +2 -3
  19. package/generator/src/error-formatter.js +5 -5
  20. package/generator/src/file-helpers.js +3 -4
  21. package/generator/src/generate-template-module-connector.js +14 -15
  22. package/generator/src/init.js +8 -7
  23. package/generator/src/pre-render-html.js +11 -12
  24. package/generator/src/render-worker.js +21 -26
  25. package/generator/src/render.js +122 -162
  26. package/generator/src/request-cache.js +13 -8
  27. package/generator/src/rewrite-client-elm-json.js +5 -5
  28. package/generator/src/rewrite-elm-json.js +5 -5
  29. package/generator/src/route-codegen-helpers.js +16 -31
  30. package/generator/src/seo-renderer.js +1 -3
  31. package/generator/src/vite-utils.js +1 -2
  32. package/package.json +9 -8
  33. package/src/BackendTask/Custom.elm +1 -1
  34. package/src/BackendTask/File.elm +1 -1
  35. package/src/BackendTask/Glob.elm +4 -2
  36. package/src/BackendTask/Http.elm +6 -6
  37. package/src/FatalError.elm +2 -14
  38. package/src/Form.elm +26 -47
  39. package/src/Pages/Generate.elm +42 -13
  40. package/src/Pages/Internal/Form.elm +14 -1
  41. package/src/Pages/Internal/Platform/Cli.elm +8 -6
  42. package/src/Pages/Internal/Platform/Effect.elm +1 -1
  43. package/src/Pages/Internal/Platform/GeneratorApplication.elm +8 -6
  44. package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
  45. package/src/Pages/Script.elm +2 -2
  46. package/src/Server/Request.elm +21 -13
@@ -3,6 +3,7 @@ module Pages.Generate exposing
3
3
  , Type(..)
4
4
  , serverRender
5
5
  , preRender, single
6
+ , addDeclarations
6
7
  )
7
8
 
8
9
  {-| This module provides some functions for scaffolding code for a new Route Module. It uses [`elm-codegen`'s API](https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/) for generating code.
@@ -27,6 +28,11 @@ Learn more about [the `elm-pages run` CLI command in its docs page](https://elm-
27
28
 
28
29
  @docs preRender, single
29
30
 
31
+
32
+ ## Including Additional elm-codegen Declarations
33
+
34
+ @docs addDeclarations
35
+
30
36
  -}
31
37
 
32
38
  import Elm
@@ -54,12 +60,14 @@ typeToDeclaration name type_ =
54
60
  {-| -}
55
61
  type Builder
56
62
  = ServerRender
63
+ (List Elm.Declaration)
57
64
  { data : ( Type, Elm.Expression -> Elm.Expression )
58
65
  , action : ( Type, Elm.Expression -> Elm.Expression )
59
66
  , head : Elm.Expression -> Elm.Expression
60
67
  , moduleName : List String
61
68
  }
62
69
  | PreRender
70
+ (List Elm.Declaration)
63
71
  { data : ( Type, Elm.Expression -> Elm.Expression )
64
72
  , pages : Maybe Elm.Expression
65
73
  , head : Elm.Expression -> Elm.Expression
@@ -76,7 +84,7 @@ serverRender :
76
84
  }
77
85
  -> Builder
78
86
  serverRender =
79
- ServerRender
87
+ ServerRender []
80
88
 
81
89
 
82
90
  {-| -}
@@ -96,7 +104,7 @@ preRender input =
96
104
  -- |> Maybe.map RoutePattern.hasRouteParams
97
105
  -- |> Maybe.withDefault False
98
106
  --in
99
- PreRender
107
+ PreRender []
100
108
  { data = input.data
101
109
  , pages =
102
110
  input.pages
@@ -118,7 +126,7 @@ single :
118
126
  }
119
127
  -> Builder
120
128
  single input =
121
- PreRender
129
+ PreRender []
122
130
  { data = ( Tuple.first input.data, \_ -> Tuple.second input.data )
123
131
  , pages = Nothing
124
132
  , head = input.head
@@ -134,7 +142,7 @@ buildNoState :
134
142
  -> Elm.File
135
143
  buildNoState definitions builder_ =
136
144
  case builder_ of
137
- ServerRender builder ->
145
+ ServerRender declarations builder ->
138
146
  userFunction builder.moduleName
139
147
  { view =
140
148
  \maybeUrl sharedModel _ app ->
@@ -153,9 +161,10 @@ buildNoState definitions builder_ =
153
161
  , data = builder.data |> Tuple.first
154
162
  , actionData = builder.action |> Tuple.first
155
163
  }
164
+ , declarations = declarations
156
165
  }
157
166
 
158
- PreRender builder ->
167
+ PreRender declarations builder ->
159
168
  userFunction builder.moduleName
160
169
  { view =
161
170
  \maybeUrl sharedModel _ app ->
@@ -177,9 +186,21 @@ buildNoState definitions builder_ =
177
186
  (Elm.Annotation.list (Elm.Annotation.named [] "RouteParams"))
178
187
  |> Alias
179
188
  }
189
+ , declarations = declarations
180
190
  }
181
191
 
182
192
 
193
+ {-| -}
194
+ addDeclarations : List Elm.Declaration -> Builder -> Builder
195
+ addDeclarations declarations builder =
196
+ case builder of
197
+ ServerRender existingDeclarations record ->
198
+ ServerRender (existingDeclarations ++ declarations) record
199
+
200
+ PreRender existingDeclarations record ->
201
+ PreRender (existingDeclarations ++ declarations) record
202
+
203
+
183
204
  {-| -}
184
205
  buildWithLocalState :
185
206
  { view :
@@ -213,7 +234,7 @@ buildWithLocalState :
213
234
  -> Elm.File
214
235
  buildWithLocalState definitions builder_ =
215
236
  case builder_ of
216
- ServerRender builder ->
237
+ ServerRender declarations builder ->
217
238
  userFunction builder.moduleName
218
239
  { view =
219
240
  \maybeUrl sharedModel model app ->
@@ -261,9 +282,10 @@ buildWithLocalState definitions builder_ =
261
282
  , data = builder.data |> Tuple.first
262
283
  , actionData = builder.action |> Tuple.first
263
284
  }
285
+ , declarations = declarations
264
286
  }
265
287
 
266
- PreRender builder ->
288
+ PreRender declarations builder ->
267
289
  userFunction builder.moduleName
268
290
  { view =
269
291
  \maybeUrl sharedModel model app ->
@@ -314,6 +336,7 @@ buildWithLocalState definitions builder_ =
314
336
  (Elm.Annotation.list (Elm.Annotation.named [] "RouteParams"))
315
337
  |> Alias
316
338
  }
339
+ , declarations = declarations
317
340
  }
318
341
 
319
342
 
@@ -350,7 +373,7 @@ buildWithSharedState :
350
373
  -> Elm.File
351
374
  buildWithSharedState definitions builder_ =
352
375
  case builder_ of
353
- ServerRender builder ->
376
+ ServerRender declarations builder ->
354
377
  userFunction builder.moduleName
355
378
  { view =
356
379
  \maybeUrl sharedModel model app ->
@@ -398,9 +421,10 @@ buildWithSharedState definitions builder_ =
398
421
  , data = builder.data |> Tuple.first
399
422
  , actionData = builder.action |> Tuple.first
400
423
  }
424
+ , declarations = declarations
401
425
  }
402
426
 
403
- PreRender builder ->
427
+ PreRender declarations builder ->
404
428
  userFunction builder.moduleName
405
429
  { view =
406
430
  \maybeUrl sharedModel model app ->
@@ -451,6 +475,7 @@ buildWithSharedState definitions builder_ =
451
475
  (Elm.Annotation.list (Elm.Annotation.named [] "RouteParams"))
452
476
  |> Alias
453
477
  }
478
+ , declarations = declarations
454
479
  }
455
480
 
456
481
 
@@ -480,6 +505,7 @@ userFunction :
480
505
  , action : ActionOrPages
481
506
  , head : Elm.Expression -> Elm.Expression
482
507
  , types : { model : Type, msg : Type, data : Type, actionData : Type }
508
+ , declarations : List Elm.Declaration
483
509
  }
484
510
  -> Elm.File
485
511
  userFunction moduleName definitions =
@@ -694,8 +720,8 @@ userFunction moduleName definitions =
694
720
  )
695
721
  in
696
722
  Elm.file ("Route" :: moduleName)
697
- ([ definitions.types.model |> typeToDeclaration "Model"
698
- , definitions.types.msg |> typeToDeclaration "Msg"
723
+ ([ definitions.types.model |> typeToDeclaration "Model" |> Elm.expose
724
+ , definitions.types.msg |> typeToDeclaration "Msg" |> Elm.expose
699
725
  , Elm.alias "RouteParams"
700
726
  (Elm.Annotation.record
701
727
  (RoutePattern.fromModuleName moduleName
@@ -704,6 +730,7 @@ userFunction moduleName definitions =
704
730
  |> Maybe.withDefault []
705
731
  )
706
732
  )
733
+ |> Elm.expose
707
734
  , Elm.declaration "route"
708
735
  ((case definitions.action of
709
736
  Action _ ->
@@ -782,6 +809,7 @@ userFunction moduleName definitions =
782
809
  )
783
810
  )
784
811
  )
812
+ |> Elm.expose
785
813
  ]
786
814
  ++ (case localDefinitions of
787
815
  Just local ->
@@ -793,8 +821,8 @@ userFunction moduleName definitions =
793
821
  Nothing ->
794
822
  []
795
823
  )
796
- ++ [ definitions.types.data |> typeToDeclaration "Data"
797
- , definitions.types.actionData |> typeToDeclaration "ActionData"
824
+ ++ [ definitions.types.data |> typeToDeclaration "Data" |> Elm.expose
825
+ , definitions.types.actionData |> typeToDeclaration "ActionData" |> Elm.expose
798
826
  , dataFn.declaration
799
827
  , headFn.declaration
800
828
  , viewFn.declaration
@@ -803,6 +831,7 @@ userFunction moduleName definitions =
803
831
  ]
804
832
  |> List.filterMap identity
805
833
  )
834
+ ++ definitions.declarations
806
835
  )
807
836
 
808
837
 
@@ -1,4 +1,4 @@
1
- module Pages.Internal.Form exposing (Validation(..), ViewField)
1
+ module Pages.Internal.Form exposing (Response(..), Validation(..), ViewField, unwrapResponse)
2
2
 
3
3
  import Dict exposing (Dict)
4
4
  import Form.FieldStatus exposing (FieldStatus)
@@ -15,3 +15,16 @@ type alias ViewField kind =
15
15
  , status : FieldStatus
16
16
  , kind : ( kind, List ( String, Encode.Value ) )
17
17
  }
18
+
19
+
20
+ {-| -}
21
+ type Response error
22
+ = Response
23
+ { fields : List ( String, String )
24
+ , errors : Dict String (List error)
25
+ }
26
+
27
+
28
+ unwrapResponse : Response error -> { fields : List ( String, String ), errors : Dict String (List error) }
29
+ unwrapResponse (Response response) =
30
+ response
@@ -209,8 +209,13 @@ perform site renderRequest config effect =
209
209
  Effect.Batch list ->
210
210
  flatten site renderRequest config list
211
211
 
212
- Effect.FetchHttp unmasked ->
213
- ToJsPayload.DoHttp (Pages.StaticHttp.Request.hash unmasked) unmasked
212
+ Effect.FetchHttp requests ->
213
+ requests
214
+ |> List.map
215
+ (\request ->
216
+ ( Pages.StaticHttp.Request.hash request, request )
217
+ )
218
+ |> ToJsPayload.DoHttp
214
219
  |> Codec.encoder (ToJsPayload.successCodecNew2 canonicalSiteUrl "")
215
220
  |> config.toJsPort
216
221
  |> Cmd.map never
@@ -817,10 +822,7 @@ nextStepToEffect model nextStep =
817
822
  ( { model
818
823
  | staticResponses = updatedStaticResponsesModel
819
824
  }
820
- , (httpRequests
821
- |> List.map Effect.FetchHttp
822
- )
823
- |> Effect.Batch
825
+ , Effect.FetchHttp httpRequests
824
826
  )
825
827
 
826
828
  StaticResponses.FinishedWithErrors errors ->
@@ -7,7 +7,7 @@ import Pages.StaticHttp.Request as StaticHttp
7
7
 
8
8
  type Effect
9
9
  = NoEffect
10
- | FetchHttp StaticHttp.Request
10
+ | FetchHttp (List StaticHttp.Request)
11
11
  | Batch (List Effect)
12
12
  | SendSinglePage ToJsSuccessPayloadNewCombined
13
13
  | SendSinglePageNew Bytes ToJsSuccessPayloadNewCombined
@@ -183,8 +183,13 @@ perform config effect =
183
183
  Effect.Batch list ->
184
184
  flatten config list
185
185
 
186
- Effect.FetchHttp unmasked ->
187
- ToJsPayload.DoHttp (Pages.StaticHttp.Request.hash unmasked) unmasked
186
+ Effect.FetchHttp requests ->
187
+ requests
188
+ |> List.map
189
+ (\request ->
190
+ ( Pages.StaticHttp.Request.hash request, request )
191
+ )
192
+ |> ToJsPayload.DoHttp
188
193
  |> Codec.encoder (ToJsPayload.successCodecNew2 canonicalSiteUrl "")
189
194
  |> config.toJsPort
190
195
  |> Cmd.map never
@@ -349,10 +354,7 @@ nextStepToEffect model nextStep =
349
354
  ( { model
350
355
  | staticResponses = updatedStaticResponsesModel
351
356
  }
352
- , (httpRequests
353
- |> List.map Effect.FetchHttp
354
- )
355
- |> Effect.Batch
357
+ , Effect.FetchHttp httpRequests
356
358
  )
357
359
 
358
360
  StaticResponses.Finish () ->
@@ -89,7 +89,7 @@ headCodec canonicalSiteUrl currentPagePath =
89
89
  type ToJsSuccessPayloadNewCombined
90
90
  = PageProgress ToJsSuccessPayloadNew
91
91
  | SendApiResponse { body : Json.Encode.Value, staticHttpCache : Dict String String, statusCode : Int }
92
- | DoHttp String Pages.StaticHttp.Request.Request
92
+ | DoHttp (List ( String, Pages.StaticHttp.Request.Request ))
93
93
  | Port String
94
94
  | Errors (List BuildError)
95
95
  | ApiResponse
@@ -109,8 +109,8 @@ successCodecNew2 canonicalSiteUrl currentPagePath =
109
109
  PageProgress payload ->
110
110
  success payload
111
111
 
112
- DoHttp hash requestUrl ->
113
- vDoHttp hash requestUrl
112
+ DoHttp hashRequestPairs ->
113
+ vDoHttp hashRequestPairs
114
114
 
115
115
  SendApiResponse record ->
116
116
  vSendApiResponse record
@@ -121,10 +121,7 @@ successCodecNew2 canonicalSiteUrl currentPagePath =
121
121
  |> Codec.variant1 "Errors" Errors errorCodec
122
122
  |> Codec.variant0 "ApiResponse" ApiResponse
123
123
  |> Codec.variant1 "PageProgress" PageProgress (successCodecNew canonicalSiteUrl currentPagePath)
124
- |> Codec.variant2 "DoHttp"
125
- DoHttp
126
- Codec.string
127
- Pages.StaticHttp.Request.codec
124
+ |> Codec.variant1 "DoHttp" DoHttp (Codec.list (Codec.tuple Codec.string Pages.StaticHttp.Request.codec))
128
125
  |> Codec.variant1 "ApiResponse"
129
126
  SendApiResponse
130
127
  (Codec.object (\body staticHttpCache statusCode -> { body = body, staticHttpCache = staticHttpCache, statusCode = statusCode })
@@ -34,7 +34,7 @@ import BackendTask.Http
34
34
  import BackendTask.Internal.Request
35
35
  import Cli.OptionsParser as OptionsParser
36
36
  import Cli.Program as Program
37
- import FatalError exposing (FatalError, Recoverable)
37
+ import FatalError exposing (FatalError)
38
38
  import Json.Decode as Decode
39
39
  import Json.Encode as Encode
40
40
  import Pages.Internal.Script
@@ -52,7 +52,7 @@ type Error
52
52
 
53
53
 
54
54
  {-| -}
55
- writeFile : { path : String, body : String } -> BackendTask (Recoverable Error) ()
55
+ writeFile : { path : String, body : String } -> BackendTask { fatal : FatalError, recoverable : Error } ()
56
56
  writeFile { path, body } =
57
57
  BackendTask.Internal.Request.request
58
58
  { name = "write-file"
@@ -903,7 +903,7 @@ formDataWithServerValidation formParsers =
903
903
  case ( maybeParsed, errors2 |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
904
904
  ( Just decodedFinal, Nothing ) ->
905
905
  Ok
906
- ( Form.Response
906
+ ( Pages.Internal.Form.Response
907
907
  { fields = rawFormData_
908
908
  , errors = Dict.empty
909
909
  }
@@ -912,7 +912,7 @@ formDataWithServerValidation formParsers =
912
912
 
913
913
  ( _, maybeErrors ) ->
914
914
  Err
915
- (Form.Response
915
+ (Pages.Internal.Form.Response
916
916
  { fields = rawFormData_
917
917
  , errors =
918
918
  maybeErrors
@@ -926,7 +926,7 @@ formDataWithServerValidation formParsers =
926
926
 
927
927
  ( _, maybeErrors ) ->
928
928
  Err
929
- (Form.Response
929
+ (Pages.Internal.Form.Response
930
930
  { fields = rawFormData_
931
931
  , errors =
932
932
  maybeErrors
@@ -943,7 +943,7 @@ formDataWithServerValidation formParsers =
943
943
  {-| -}
944
944
  formData :
945
945
  Form.ServerForms error combined
946
- -> Parser (Result { fields : List ( String, String ), errors : Dict String (List error) } combined)
946
+ -> Parser ( Form.Response error, Result { fields : List ( String, String ), errors : Dict String (List error) } combined )
947
947
  formData formParsers =
948
948
  rawFormData
949
949
  |> andThen
@@ -956,18 +956,26 @@ formData formParsers =
956
956
  in
957
957
  case ( maybeDecoded, errors |> Dict.toList |> List.filter (\( _, value ) -> value |> List.isEmpty |> not) |> List.NonEmpty.fromList ) of
958
958
  ( Just decoded, Nothing ) ->
959
- Ok decoded
959
+ ( Pages.Internal.Form.Response { fields = [], errors = Dict.empty }
960
+ , Ok decoded
961
+ )
960
962
  |> succeed
961
963
 
962
964
  ( _, maybeErrors ) ->
963
- Err
964
- { fields = rawFormData_
965
- , errors =
966
- maybeErrors
967
- |> Maybe.map List.NonEmpty.toList
968
- |> Maybe.withDefault []
969
- |> Dict.fromList
970
- }
965
+ let
966
+ record : { fields : List ( String, String ), errors : Dict String (List error) }
967
+ record =
968
+ { fields = rawFormData_
969
+ , errors =
970
+ maybeErrors
971
+ |> Maybe.map List.NonEmpty.toList
972
+ |> Maybe.withDefault []
973
+ |> Dict.fromList
974
+ }
975
+ in
976
+ ( Pages.Internal.Form.Response record
977
+ , Err record
978
+ )
971
979
  |> succeed
972
980
  )
973
981