elm-pages 3.0.0-beta.0 → 3.0.0-beta.10

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 (62) hide show
  1. package/README.md +10 -1
  2. package/codegen/elm-pages-codegen.js +39026 -0
  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.elmi +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/Reporter.elmi +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
  14. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  15. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -0
  16. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +6795 -0
  17. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25835 -0
  18. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +110 -0
  19. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +187 -0
  20. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/package.json +1 -0
  21. package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Reporter.elm +26 -0
  22. package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Runner.elm +62 -0
  23. package/generator/dead-code-review/elm.json +35 -0
  24. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +304 -0
  25. package/generator/dead-code-review/src/ReviewConfig.elm +9 -0
  26. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +673 -0
  27. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  28. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  29. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  30. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  31. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  32. package/generator/src/SharedTemplate.elm +1 -1
  33. package/generator/src/build.js +75 -42
  34. package/generator/src/compatibility-key.js +1 -0
  35. package/generator/src/config.js +41 -0
  36. package/generator/src/dev-server.js +36 -56
  37. package/generator/src/generate-template-module-connector.js +2 -28
  38. package/generator/src/pre-render-html.js +31 -17
  39. package/generator/src/render.js +2 -0
  40. package/generator/src/seo-renderer.js +11 -4
  41. package/generator/src/vite-utils.js +78 -0
  42. package/generator/template/app/Api.elm +1 -1
  43. package/generator/template/app/Site.elm +6 -1
  44. package/package.json +5 -3
  45. package/src/ApiRoute.elm +0 -3
  46. package/src/DataSource/File.elm +1 -1
  47. package/src/DataSource/Internal/Request.elm +0 -5
  48. package/src/DataSource.elm +39 -31
  49. package/src/Form/Field.elm +1 -1
  50. package/src/Form.elm +1 -1
  51. package/src/Head/Seo.elm +16 -27
  52. package/src/Head.elm +126 -0
  53. package/src/HtmlPrinter.elm +7 -3
  54. package/src/Pages/Generate.elm +544 -102
  55. package/src/Pages/Internal/NotFoundReason.elm +3 -2
  56. package/src/Pages/Internal/Platform/Cli.elm +91 -27
  57. package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
  58. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  59. package/src/Pages/Internal/Platform.elm +34 -27
  60. package/src/Pages/ProgramConfig.elm +6 -3
  61. package/src/Server/Session.elm +149 -83
  62. package/src/Server/SetCookie.elm +89 -31
@@ -1,15 +1,38 @@
1
1
  module Server.SetCookie exposing
2
- ( SetCookie, SameSite(..)
3
- , withImmediateExpiration, httpOnly, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
2
+ ( SetCookie
3
+ , SameSite(..)
4
+ , Options, initOptions
5
+ , withImmediateExpiration, makeVisibleToJavaScript, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
4
6
  , toString
5
7
  )
6
8
 
7
- {-| <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
9
+ {-| Server-rendered pages in your `elm-pages` can set cookies. `elm-pages` provides two high-level ways to work with cookies:
8
10
 
9
- <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies>
11
+ - [`Server.Session.withSession`](Server-Session#withSession)
12
+ - [`Server.Response.withSetCookieHeader`](Server-Response#withSetCookieHeader)
10
13
 
11
- @docs SetCookie, SameSite
12
- @docs withImmediateExpiration, httpOnly, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
14
+ [`Server.Session.withSession`](Server-Session#withSession) provides a high-level way to manage key-value pairs of data using cookie storage,
15
+ whereas `Server.Response.withSetCookieHeader` gives a more low-level tool for setting cookies. It's often best to use the
16
+ most high-level tool that will fit your use case.
17
+
18
+ You can learn more about the basics of cookies in the Web Platform in these helpful MDN documentation pages:
19
+
20
+ - <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
21
+ - <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies>
22
+
23
+ @docs SetCookie
24
+
25
+ @docs SameSite
26
+
27
+
28
+ ## Options
29
+
30
+ @docs Options, initOptions
31
+
32
+ @docs withImmediateExpiration, makeVisibleToJavaScript, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
33
+
34
+
35
+ ## Internal
13
36
 
14
37
  @docs toString
15
38
 
@@ -24,8 +47,14 @@ import Utc
24
47
  type alias SetCookie =
25
48
  { name : String
26
49
  , value : String
27
- , expiration : Maybe Time.Posix
28
- , httpOnly : Bool
50
+ , options : Options
51
+ }
52
+
53
+
54
+ {-| -}
55
+ type alias Options =
56
+ { expiration : Maybe Time.Posix
57
+ , visibleToJavaScript : Bool
29
58
  , maxAge : Maybe Int
30
59
  , path : Maybe String
31
60
  , domain : Maybe String
@@ -41,7 +70,11 @@ type SameSite
41
70
  | None
42
71
 
43
72
 
44
- {-| -}
73
+ {-| Usually you'll want to use [`Server.Response.withSetCookieHeader`](Server-Response#withSetCookieHeader) instead.
74
+
75
+ This is a low-level helper that's there in case you want it but most users will never need this.
76
+
77
+ -}
45
78
  toString : SetCookie -> String
46
79
  toString builder =
47
80
  let
@@ -61,17 +94,25 @@ toString builder =
61
94
 
62
95
  else
63
96
  ""
97
+
98
+ options : Options
99
+ options =
100
+ builder.options
101
+
102
+ httpOnly : Bool
103
+ httpOnly =
104
+ not options.visibleToJavaScript
64
105
  in
65
106
  builder.name
66
107
  ++ "="
67
108
  ++ Url.percentEncode builder.value
68
- ++ option "Expires" (builder.expiration |> Maybe.map Utc.fromTime)
69
- ++ option "Max-Age" (builder.maxAge |> Maybe.map String.fromInt)
70
- ++ option "Path" builder.path
71
- ++ option "Domain" builder.domain
72
- ++ option "SameSite" (builder.sameSite |> Maybe.map sameSiteToString)
73
- ++ boolOption "HttpOnly" builder.httpOnly
74
- ++ boolOption "Secure" builder.secure
109
+ ++ option "Expires" (options.expiration |> Maybe.map Utc.fromTime)
110
+ ++ option "Max-Age" (options.maxAge |> Maybe.map String.fromInt)
111
+ ++ option "Path" options.path
112
+ ++ option "Domain" options.domain
113
+ ++ option "SameSite" (options.sameSite |> Maybe.map sameSiteToString)
114
+ ++ boolOption "HttpOnly" httpOnly
115
+ ++ boolOption "Secure" options.secure
75
116
 
76
117
 
77
118
  sameSiteToString : SameSite -> String
@@ -88,12 +129,19 @@ sameSiteToString sameSite =
88
129
 
89
130
 
90
131
  {-| -}
91
- setCookie : String -> String -> SetCookie
92
- setCookie name value =
132
+ setCookie : String -> String -> Options -> SetCookie
133
+ setCookie name value options =
93
134
  { name = name
94
135
  , value = value
95
- , expiration = Nothing
96
- , httpOnly = False
136
+ , options = options
137
+ }
138
+
139
+
140
+ {-| -}
141
+ initOptions : Options
142
+ initOptions =
143
+ { expiration = Nothing
144
+ , visibleToJavaScript = False
97
145
  , maxAge = Nothing
98
146
  , path = Nothing
99
147
  , domain = Nothing
@@ -103,7 +151,7 @@ setCookie name value =
103
151
 
104
152
 
105
153
  {-| -}
106
- withExpiration : Time.Posix -> SetCookie -> SetCookie
154
+ withExpiration : Time.Posix -> Options -> Options
107
155
  withExpiration time builder =
108
156
  { builder
109
157
  | expiration = Just time
@@ -111,23 +159,33 @@ withExpiration time builder =
111
159
 
112
160
 
113
161
  {-| -}
114
- withImmediateExpiration : SetCookie -> SetCookie
162
+ withImmediateExpiration : Options -> Options
115
163
  withImmediateExpiration builder =
116
164
  { builder
117
165
  | expiration = Just (Time.millisToPosix 0)
118
166
  }
119
167
 
120
168
 
121
- {-| -}
122
- httpOnly : SetCookie -> SetCookie
123
- httpOnly builder =
169
+ {-| The default option in this API is for HttpOnly cookies <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#httponly>.
170
+
171
+ Cookies can be exposed so you can read them from JavaScript using `Document.cookie`. When this is intended and understood
172
+ then there's nothing unsafe about that (for example, if you are setting a `darkMode` cookie and what to access that
173
+ dynamically). In this API you opt into exposing a cookie you set to JavaScript to ensure cookies aren't exposed to JS unintentionally.
174
+
175
+ In general if you can accomplish your goal using HttpOnly cookies (i.e. not using `makeVisibleToJavaScript`) then
176
+ it's a good practice. With server-rendered `elm-pages` applications you can often manage your session state by pulling
177
+ in session data from cookies in a `DataSource` (which is resolved server-side before it ever reaches the browser).
178
+
179
+ -}
180
+ makeVisibleToJavaScript : Options -> Options
181
+ makeVisibleToJavaScript builder =
124
182
  { builder
125
- | httpOnly = True
183
+ | visibleToJavaScript = True
126
184
  }
127
185
 
128
186
 
129
187
  {-| -}
130
- withMaxAge : Int -> SetCookie -> SetCookie
188
+ withMaxAge : Int -> Options -> Options
131
189
  withMaxAge maxAge builder =
132
190
  { builder
133
191
  | maxAge = Just maxAge
@@ -135,7 +193,7 @@ withMaxAge maxAge builder =
135
193
 
136
194
 
137
195
  {-| -}
138
- withPath : String -> SetCookie -> SetCookie
196
+ withPath : String -> Options -> Options
139
197
  withPath path builder =
140
198
  { builder
141
199
  | path = Just path
@@ -143,7 +201,7 @@ withPath path builder =
143
201
 
144
202
 
145
203
  {-| -}
146
- withDomain : String -> SetCookie -> SetCookie
204
+ withDomain : String -> Options -> Options
147
205
  withDomain domain builder =
148
206
  { builder
149
207
  | domain = Just domain
@@ -153,7 +211,7 @@ withDomain domain builder =
153
211
  {-| Secure (only sent over https, or localhost on http) is the default. This overrides that and
154
212
  removes the `Secure` attribute from the cookie.
155
213
  -}
156
- nonSecure : SetCookie -> SetCookie
214
+ nonSecure : Options -> Options
157
215
  nonSecure builder =
158
216
  { builder
159
217
  | secure = False
@@ -162,7 +220,7 @@ nonSecure builder =
162
220
 
163
221
  {-| The default SameSite policy is Lax if one is not explicitly set. See the SameSite section in <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes>.
164
222
  -}
165
- withSameSite : SameSite -> SetCookie -> SetCookie
223
+ withSameSite : SameSite -> Options -> Options
166
224
  withSameSite sameSite builder =
167
225
  { builder
168
226
  | sameSite = Just sameSite