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.
- package/README.md +10 -1
- package/adapter/netlify.js +207 -0
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2828 -2933
- 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 +121 -114
- package/generator/src/SharedTemplate.elm +8 -7
- 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 +531 -0
- package/src/FatalError.elm +90 -0
- package/src/Head/Seo.elm +4 -4
- 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/ConcurrentSubmission.elm +127 -0
- package/src/Pages/Form.elm +340 -0
- package/src/Pages/FormData.elm +18 -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/NotFoundReason.elm +4 -4
- package/src/Pages/Internal/Platform/Cli.elm +617 -768
- 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 +359 -225
- package/src/Pages/Internal/ResponseSketch.elm +2 -2
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +52 -11
- package/src/Pages/Navigation.elm +87 -0
- package/src/Pages/PageUrl.elm +26 -12
- package/src/Pages/ProgramConfig.elm +35 -23
- package/src/Pages/Script.elm +166 -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/Url.elm +3 -3
- package/src/PagesMsg.elm +88 -0
- package/src/QueryParams.elm +21 -172
- package/src/RenderRequest.elm +7 -7
- package/src/RequestsAndPending.elm +37 -20
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +569 -0
- package/src/Scaffold/Route.elm +1411 -0
- package/src/Server/Request.elm +74 -72
- package/src/Server/Session.elm +62 -42
- package/src/Server/SetCookie.elm +80 -32
- package/src/Stub.elm +53 -0
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/{Path.elm → UrlPath.elm} +33 -36
- 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
- package/src/Pages/Transition.elm +0 -70
package/src/Server/SetCookie.elm
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module Server.SetCookie exposing
|
|
2
|
-
( SetCookie
|
|
3
|
-
,
|
|
4
|
-
,
|
|
5
|
-
, withImmediateExpiration, makeVisibleToJavaScript, nonSecure,
|
|
2
|
+
( SetCookie, setCookie
|
|
3
|
+
, Options, options
|
|
4
|
+
, SameSite(..), withSameSite
|
|
5
|
+
, withImmediateExpiration, makeVisibleToJavaScript, nonSecure, withDomain, withExpiration, withMaxAge, withPath, withoutPath
|
|
6
6
|
, toString
|
|
7
7
|
)
|
|
8
8
|
|
|
@@ -20,16 +20,29 @@ You can learn more about the basics of cookies in the Web Platform in these help
|
|
|
20
20
|
- <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
|
|
21
21
|
- <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies>
|
|
22
22
|
|
|
23
|
-
@docs SetCookie
|
|
23
|
+
@docs SetCookie, setCookie
|
|
24
24
|
|
|
25
|
-
@docs SameSite
|
|
26
25
|
|
|
26
|
+
## Building Options
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Usually you'll want to start by creating default `Options` with `options` and then overriding defaults using the `with...` helpers.
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
import Server.SetCookie as SetCookie
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
options : SetCookie.Options
|
|
33
|
+
options =
|
|
34
|
+
SetCookie.options
|
|
35
|
+
|> SetCookie.nonSecure
|
|
36
|
+
|> SetCookie.withMaxAge 123
|
|
37
|
+
|> SetCookie.makeVisibleToJavaScript
|
|
38
|
+
|> SetCookie.withoutPath
|
|
39
|
+
|> SetCookie.setCookie "id" "a3fWa"
|
|
40
|
+
|
|
41
|
+
@docs Options, options
|
|
42
|
+
|
|
43
|
+
@docs SameSite, withSameSite
|
|
44
|
+
|
|
45
|
+
@docs withImmediateExpiration, makeVisibleToJavaScript, nonSecure, withDomain, withExpiration, withMaxAge, withPath, withoutPath
|
|
33
46
|
|
|
34
47
|
|
|
35
48
|
## Internal
|
|
@@ -51,7 +64,8 @@ type alias SetCookie =
|
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
|
|
54
|
-
{-|
|
|
67
|
+
{-| The set of possible configuration options. You can configure this record directly, or use the `with...` helpers.
|
|
68
|
+
-}
|
|
55
69
|
type alias Options =
|
|
56
70
|
{ expiration : Maybe Time.Posix
|
|
57
71
|
, visibleToJavaScript : Bool
|
|
@@ -63,7 +77,15 @@ type alias Options =
|
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
|
|
66
|
-
{-| -
|
|
80
|
+
{-| Possible values for [the cookie's same-site value](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value).
|
|
81
|
+
|
|
82
|
+
The default option is [`Lax`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#lax) (Lax does not send
|
|
83
|
+
cookies in cross-origin requests so it is a good default for most cases, but [`Strict`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#strict)
|
|
84
|
+
is even more restrictive).
|
|
85
|
+
|
|
86
|
+
Override the default option using [`withSameSite`](#withSameSite).
|
|
87
|
+
|
|
88
|
+
-}
|
|
67
89
|
type SameSite
|
|
68
90
|
= Strict
|
|
69
91
|
| Lax
|
|
@@ -95,24 +117,24 @@ toString builder =
|
|
|
95
117
|
else
|
|
96
118
|
""
|
|
97
119
|
|
|
98
|
-
|
|
99
|
-
|
|
120
|
+
options_ : Options
|
|
121
|
+
options_ =
|
|
100
122
|
builder.options
|
|
101
123
|
|
|
102
124
|
httpOnly : Bool
|
|
103
125
|
httpOnly =
|
|
104
|
-
not
|
|
126
|
+
not options_.visibleToJavaScript
|
|
105
127
|
in
|
|
106
128
|
builder.name
|
|
107
129
|
++ "="
|
|
108
130
|
++ Url.percentEncode builder.value
|
|
109
|
-
++ option "Expires" (
|
|
110
|
-
++ option "Max-Age" (
|
|
111
|
-
++ option "Path"
|
|
112
|
-
++ option "Domain"
|
|
113
|
-
++ option "SameSite" (
|
|
131
|
+
++ option "Expires" (options_.expiration |> Maybe.map Utc.fromTime)
|
|
132
|
+
++ option "Max-Age" (options_.maxAge |> Maybe.map String.fromInt)
|
|
133
|
+
++ option "Path" options_.path
|
|
134
|
+
++ option "Domain" options_.domain
|
|
135
|
+
++ option "SameSite" (options_.sameSite |> Maybe.map sameSiteToString)
|
|
114
136
|
++ boolOption "HttpOnly" httpOnly
|
|
115
|
-
++ boolOption "Secure"
|
|
137
|
+
++ boolOption "Secure" options_.secure
|
|
116
138
|
|
|
117
139
|
|
|
118
140
|
sameSiteToString : SameSite -> String
|
|
@@ -128,22 +150,26 @@ sameSiteToString sameSite =
|
|
|
128
150
|
"None"
|
|
129
151
|
|
|
130
152
|
|
|
131
|
-
{-| -
|
|
153
|
+
{-| Create a `SetCookie` record with the given name, value, and [`Options`](Options]. To add a `Set-Cookie` header, you can
|
|
154
|
+
pass this value with [`Server.Response.withSetCookieHeader`](Server-Response#withSetCookieHeader). Or for more low-level
|
|
155
|
+
uses you can stringify the value manually with [`toString`](#toString).
|
|
156
|
+
-}
|
|
132
157
|
setCookie : String -> String -> Options -> SetCookie
|
|
133
|
-
setCookie name value
|
|
158
|
+
setCookie name value options_ =
|
|
134
159
|
{ name = name
|
|
135
160
|
, value = value
|
|
136
|
-
, options =
|
|
161
|
+
, options = options_
|
|
137
162
|
}
|
|
138
163
|
|
|
139
164
|
|
|
140
|
-
{-|
|
|
141
|
-
|
|
142
|
-
|
|
165
|
+
{-| Initialize the default `SetCookie` `Options`. Can be configured directly through a record update, or with `withExpiration`, etc.
|
|
166
|
+
-}
|
|
167
|
+
options : Options
|
|
168
|
+
options =
|
|
143
169
|
{ expiration = Nothing
|
|
144
170
|
, visibleToJavaScript = False
|
|
145
171
|
, maxAge = Nothing
|
|
146
|
-
, path =
|
|
172
|
+
, path = Just "/"
|
|
147
173
|
, domain = Nothing
|
|
148
174
|
, secure = True
|
|
149
175
|
, sameSite = Nothing
|
|
@@ -158,7 +184,9 @@ withExpiration time builder =
|
|
|
158
184
|
}
|
|
159
185
|
|
|
160
186
|
|
|
161
|
-
{-| -
|
|
187
|
+
{-| Sets [`Expires`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#expiresdate) to `Time.millisToPosix 0`,
|
|
188
|
+
which effectively tells the browser to delete the cookie immediately (by giving it an expiration date in the past).
|
|
189
|
+
-}
|
|
162
190
|
withImmediateExpiration : Options -> Options
|
|
163
191
|
withImmediateExpiration builder =
|
|
164
192
|
{ builder
|
|
@@ -174,7 +202,7 @@ dynamically). In this API you opt into exposing a cookie you set to JavaScript t
|
|
|
174
202
|
|
|
175
203
|
In general if you can accomplish your goal using HttpOnly cookies (i.e. not using `makeVisibleToJavaScript`) then
|
|
176
204
|
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 `
|
|
205
|
+
in session data from cookies in a `BackendTask` (which is resolved server-side before it ever reaches the browser).
|
|
178
206
|
|
|
179
207
|
-}
|
|
180
208
|
makeVisibleToJavaScript : Options -> Options
|
|
@@ -184,7 +212,8 @@ makeVisibleToJavaScript builder =
|
|
|
184
212
|
}
|
|
185
213
|
|
|
186
214
|
|
|
187
|
-
{-| -
|
|
215
|
+
{-| Sets the `Set-Cookie`'s [`Max-Age`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#max-agenumber).
|
|
216
|
+
-}
|
|
188
217
|
withMaxAge : Int -> Options -> Options
|
|
189
218
|
withMaxAge maxAge builder =
|
|
190
219
|
{ builder
|
|
@@ -192,7 +221,11 @@ withMaxAge maxAge builder =
|
|
|
192
221
|
}
|
|
193
222
|
|
|
194
223
|
|
|
195
|
-
{-| -
|
|
224
|
+
{-| Sets the `Set-Cookie`'s [`Path`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#pathpath-value).
|
|
225
|
+
|
|
226
|
+
The default value is `/`, which will match any sub-directories or the root directory. See also [\`withoutPath](#withoutPath)
|
|
227
|
+
|
|
228
|
+
-}
|
|
196
229
|
withPath : String -> Options -> Options
|
|
197
230
|
withPath path builder =
|
|
198
231
|
{ builder
|
|
@@ -200,7 +233,22 @@ withPath path builder =
|
|
|
200
233
|
}
|
|
201
234
|
|
|
202
235
|
|
|
203
|
-
{-|
|
|
236
|
+
{-|
|
|
237
|
+
|
|
238
|
+
> If the server omits the Path attribute, the user agent will use the "directory" of the request-uri's path component as the default value.
|
|
239
|
+
|
|
240
|
+
Source: <https://www.rfc-editor.org/rfc/rfc6265>. See <https://stackoverflow.com/a/43336097>.
|
|
241
|
+
|
|
242
|
+
-}
|
|
243
|
+
withoutPath : Options -> Options
|
|
244
|
+
withoutPath builder =
|
|
245
|
+
{ builder
|
|
246
|
+
| path = Nothing
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
{-| Sets the `Set-Cookie`'s [`Domain`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#domaindomain-value).
|
|
251
|
+
-}
|
|
204
252
|
withDomain : String -> Options -> Options
|
|
205
253
|
withDomain domain builder =
|
|
206
254
|
{ builder
|
package/src/Stub.elm
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Stub exposing (Id, Model, Task(..), map2, nextId)
|
|
2
|
+
|
|
3
|
+
import Json.Decode as Decode
|
|
4
|
+
import Set exposing (Set)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
type alias Id =
|
|
8
|
+
Int
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
type alias Model =
|
|
12
|
+
{ nextId : Id
|
|
13
|
+
, sentIds : Set Id
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
--task : Task error value
|
|
19
|
+
--task =
|
|
20
|
+
-- Pending
|
|
21
|
+
-- (\id -> id)
|
|
22
|
+
-- (\value model -> ( model, Done (Ok value) ))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
type Task error value
|
|
26
|
+
= Pending (Id -> Id) (Decode.Value -> Model -> ( Model, Task error value ))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
map2 : (value1 -> value2 -> combined) -> Task error value1 -> Task error value2 -> Task error combined
|
|
30
|
+
map2 mapFn task1 task2 =
|
|
31
|
+
case ( task1, task2 ) of
|
|
32
|
+
( Pending toId1 _, Pending toId2 _ ) ->
|
|
33
|
+
Pending
|
|
34
|
+
(\id ->
|
|
35
|
+
max (toId1 id) (toId2 id)
|
|
36
|
+
|> nextId
|
|
37
|
+
)
|
|
38
|
+
(\_ _ ->
|
|
39
|
+
Debug.todo ""
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
_ ->
|
|
43
|
+
Debug.todo ""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
nextId : Int -> Int
|
|
47
|
+
nextId id =
|
|
48
|
+
id + 1
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
--(Task toId1 resolve1)
|
|
53
|
+
--(Task toId2 resolve2)
|
|
@@ -130,17 +130,16 @@ nodeRecordToString options { tag, children, facts } =
|
|
|
130
130
|
|> String.join " "
|
|
131
131
|
|> Just
|
|
132
132
|
|
|
133
|
-
boolToString b =
|
|
134
|
-
case b of
|
|
135
|
-
True ->
|
|
136
|
-
"True"
|
|
137
|
-
|
|
138
|
-
False ->
|
|
139
|
-
"False"
|
|
140
|
-
|
|
141
133
|
boolAttributes =
|
|
142
134
|
Dict.toList facts.boolAttributes
|
|
143
|
-
|> List.
|
|
135
|
+
|> List.filterMap
|
|
136
|
+
(\( k, v ) ->
|
|
137
|
+
if v then
|
|
138
|
+
Just k
|
|
139
|
+
|
|
140
|
+
else
|
|
141
|
+
Nothing
|
|
142
|
+
)
|
|
144
143
|
|> String.join " "
|
|
145
144
|
|> Just
|
|
146
145
|
in
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module
|
|
2
|
-
(
|
|
1
|
+
module UrlPath exposing
|
|
2
|
+
( UrlPath, join, fromString
|
|
3
3
|
, toAbsolute, toRelative, toSegments
|
|
4
4
|
)
|
|
5
5
|
|
|
@@ -9,27 +9,27 @@ This helper lets you combine together path parts without worrying about having t
|
|
|
9
9
|
These two examples will result in the same URL, even though the first example has trailing and leading slashes, and the
|
|
10
10
|
second does not.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|>
|
|
12
|
+
UrlPath.join [ "/blog/", "/post-1/" ]
|
|
13
|
+
|> UrlPath.toAbsolute
|
|
14
14
|
--> "/blog/post-1"
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|>
|
|
16
|
+
UrlPath.join [ "blog", "post-1" ]
|
|
17
|
+
|> UrlPath.toAbsolute
|
|
18
18
|
--> "/blog/post-1"
|
|
19
19
|
|
|
20
20
|
We can also safely join Strings that include multiple path parts, a single path part per string, or a mix of the two:
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|>
|
|
22
|
+
UrlPath.join [ "/articles/archive/", "1977", "06", "10", "post-1" ]
|
|
23
|
+
|> UrlPath.toAbsolute
|
|
24
24
|
--> "/articles/archive/1977/06/10/post-1"
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
## Creating
|
|
27
|
+
## Creating UrlPaths
|
|
28
28
|
|
|
29
|
-
@docs
|
|
29
|
+
@docs UrlPath, join, fromString
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
## Turning
|
|
32
|
+
## Turning UrlPaths to String
|
|
33
33
|
|
|
34
34
|
@docs toAbsolute, toRelative, toSegments
|
|
35
35
|
|
|
@@ -40,54 +40,51 @@ import Pages.Internal.String exposing (chopEnd, chopStart)
|
|
|
40
40
|
|
|
41
41
|
{-| The path portion of the URL, normalized to ensure that path segments are joined with `/`s in the right places (no doubled up or missing slashes).
|
|
42
42
|
-}
|
|
43
|
-
type
|
|
44
|
-
|
|
43
|
+
type alias UrlPath =
|
|
44
|
+
List String
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
{-|
|
|
48
|
-
multi-part path part, like `blog/post-1`.
|
|
47
|
+
{-| Turn a Path to a relative URL.
|
|
49
48
|
-}
|
|
50
|
-
join :
|
|
49
|
+
join : UrlPath -> UrlPath
|
|
51
50
|
join parts =
|
|
52
51
|
parts
|
|
53
52
|
|> List.filter (\segment -> segment /= "/")
|
|
54
53
|
|> List.map normalize
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
{-| Turn a UrlPath to a relative URL.
|
|
57
|
+
-}
|
|
58
|
+
toRelative : UrlPath -> String
|
|
59
|
+
toRelative parts =
|
|
60
|
+
join parts
|
|
55
61
|
|> String.join "/"
|
|
56
|
-
|> Path
|
|
57
62
|
|
|
58
63
|
|
|
59
|
-
{-| Create a
|
|
64
|
+
{-| Create a UrlPath from a path String.
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|>
|
|
66
|
+
UrlPath.fromString "blog/post-1/"
|
|
67
|
+
|> UrlPath.toAbsolute
|
|
63
68
|
|> Expect.equal "/blog/post-1"
|
|
64
69
|
|
|
65
70
|
-}
|
|
66
|
-
fromString : String ->
|
|
71
|
+
fromString : String -> UrlPath
|
|
67
72
|
fromString path =
|
|
68
73
|
path
|
|
69
|
-
|>
|
|
70
|
-
|> Path
|
|
74
|
+
|> toSegments
|
|
71
75
|
|
|
72
76
|
|
|
73
77
|
{-| -}
|
|
74
|
-
toSegments :
|
|
75
|
-
toSegments
|
|
78
|
+
toSegments : String -> List String
|
|
79
|
+
toSegments path =
|
|
76
80
|
path |> String.split "/" |> List.filter ((/=) "")
|
|
77
81
|
|
|
78
82
|
|
|
79
|
-
{-| Turn a
|
|
83
|
+
{-| Turn a UrlPath to an absolute URL (with no trailing slash).
|
|
80
84
|
-}
|
|
81
|
-
toAbsolute :
|
|
82
|
-
toAbsolute
|
|
83
|
-
"/" ++ path
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{-| Turn a Path to a relative URL.
|
|
87
|
-
-}
|
|
88
|
-
toRelative : Path -> String
|
|
89
|
-
toRelative (Path path) =
|
|
90
|
-
path
|
|
85
|
+
toAbsolute : UrlPath -> String
|
|
86
|
+
toAbsolute path =
|
|
87
|
+
"/" ++ toRelative path
|
|
91
88
|
|
|
92
89
|
|
|
93
90
|
normalize : String -> String
|
package/src/DataSource/Env.elm
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module DataSource.Env exposing (get, expect)
|
|
2
|
-
|
|
3
|
-
{-|
|
|
4
|
-
|
|
5
|
-
@docs get, expect
|
|
6
|
-
|
|
7
|
-
-}
|
|
8
|
-
|
|
9
|
-
import DataSource exposing (DataSource)
|
|
10
|
-
import DataSource.Http
|
|
11
|
-
import DataSource.Internal.Request
|
|
12
|
-
import Json.Decode as Decode
|
|
13
|
-
import Json.Encode as Encode
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{-| -}
|
|
17
|
-
get : String -> DataSource (Maybe String)
|
|
18
|
-
get envVariableName =
|
|
19
|
-
DataSource.Internal.Request.request
|
|
20
|
-
{ name = "env"
|
|
21
|
-
, body = DataSource.Http.jsonBody (Encode.string envVariableName)
|
|
22
|
-
, expect =
|
|
23
|
-
DataSource.Http.expectJson
|
|
24
|
-
(Decode.nullable Decode.string)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{-| -}
|
|
29
|
-
expect : String -> DataSource String
|
|
30
|
-
expect envVariableName =
|
|
31
|
-
envVariableName
|
|
32
|
-
|> get
|
|
33
|
-
|> DataSource.andThen
|
|
34
|
-
(\maybeValue ->
|
|
35
|
-
maybeValue
|
|
36
|
-
|> Result.fromMaybe ("DataSource.Env.expect was expecting a variable `" ++ envVariableName ++ "` but couldn't find a variable with that name.")
|
|
37
|
-
|> DataSource.fromResult
|
|
38
|
-
)
|