mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 11:05:46 +03:00
Rename types in ApiRoute module.
This commit is contained in:
parent
9c1b1196b8
commit
b78f8c008b
@ -19,7 +19,7 @@ import Time
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[ ApiRoute.succeed
|
||||
(\userId ->
|
||||
@ -134,7 +134,7 @@ rss :
|
||||
, indexPage : List String
|
||||
}
|
||||
-> DataSource.DataSource (List Rss.Item)
|
||||
-> ApiRoute.Done ApiRoute.Response
|
||||
-> ApiRoute.ApiRoute ApiRoute.Response
|
||||
rss options itemsRequest =
|
||||
ApiRoute.succeed
|
||||
(itemsRequest
|
||||
|
@ -13,6 +13,6 @@ import Secrets
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[]
|
||||
|
@ -9,6 +9,6 @@ import Route exposing (Route)
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[]
|
||||
|
@ -9,6 +9,6 @@ import Route exposing (Route)
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[]
|
||||
|
59
examples/routing/package-lock.json
generated
59
examples/routing/package-lock.json
generated
@ -20,38 +20,39 @@
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"chokidar": "^3.5.1",
|
||||
"commander": "^7.2.0",
|
||||
"chokidar": "3.5.2",
|
||||
"commander": "8.0.0",
|
||||
"connect": "^3.7.0",
|
||||
"cross-spawn": "7.0.3",
|
||||
"elm-doc-preview": "^5.0.5",
|
||||
"elm-hot": "^1.1.6",
|
||||
"elm-optimize-level-2": "^0.1.5",
|
||||
"fs-extra": "^10.0.0",
|
||||
"globby": "^11.0.3",
|
||||
"globby": "11.0.4",
|
||||
"gray-matter": "^4.0.3",
|
||||
"kleur": "^4.1.4",
|
||||
"micromatch": "^4.0.4",
|
||||
"object-hash": "^2.2.0",
|
||||
"serve-static": "^1.14.1",
|
||||
"terser": "^5.7.0",
|
||||
"xhr2": "^0.2.1"
|
||||
"terser": "5.7.1",
|
||||
"undici": "4.2.1"
|
||||
},
|
||||
"bin": {
|
||||
"elm-pages": "generator/src/cli.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/fs-extra": "^9.0.11",
|
||||
"@types/fs-extra": "9.0.12",
|
||||
"@types/micromatch": "^4.0.1",
|
||||
"@types/node": "12.20.12",
|
||||
"@types/serve-static": "^1.13.9",
|
||||
"cypress": "^7.4.0",
|
||||
"@types/serve-static": "1.13.10",
|
||||
"cypress": "^8.0.0",
|
||||
"elm-review": "^2.5.3",
|
||||
"elm-test": "^0.19.1-revision7",
|
||||
"elm-tooling": "^1.3.0",
|
||||
"elm-verify-examples": "^5.0.0",
|
||||
"mocha": "^8.4.0",
|
||||
"typescript": "^4.2.4"
|
||||
"typescript": "4.3.5"
|
||||
}
|
||||
},
|
||||
"../../node_modules/@nodelib/fs.scandir": {
|
||||
@ -1182,15 +1183,6 @@
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
},
|
||||
"../../node_modules/xhr2": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.2.1.tgz",
|
||||
"integrity": "sha512-sID0rrVCqkVNUn8t6xuv9+6FViXjUVXq8H5rWOH2rz9fDNQEd4g0EA2XlcEdJXRz5BMEn4O1pJFdT+z4YHhoWw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/async": {
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
|
||||
@ -1493,15 +1485,15 @@
|
||||
"version": "file:../..",
|
||||
"requires": {
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/fs-extra": "^9.0.11",
|
||||
"@types/fs-extra": "9.0.12",
|
||||
"@types/micromatch": "^4.0.1",
|
||||
"@types/node": "12.20.12",
|
||||
"@types/serve-static": "^1.13.9",
|
||||
"chokidar": "^3.5.1",
|
||||
"commander": "^7.2.0",
|
||||
"@types/serve-static": "1.13.10",
|
||||
"chokidar": "3.5.2",
|
||||
"commander": "8.0.0",
|
||||
"connect": "^3.7.0",
|
||||
"cross-spawn": "7.0.3",
|
||||
"cypress": "^7.4.0",
|
||||
"cypress": "^8.0.0",
|
||||
"elm-doc-preview": "^5.0.5",
|
||||
"elm-hot": "^1.1.6",
|
||||
"elm-optimize-level-2": "^0.1.5",
|
||||
@ -1510,15 +1502,16 @@
|
||||
"elm-tooling": "^1.3.0",
|
||||
"elm-verify-examples": "^5.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"globby": "^11.0.3",
|
||||
"globby": "11.0.4",
|
||||
"gray-matter": "^4.0.3",
|
||||
"kleur": "^4.1.4",
|
||||
"micromatch": "^4.0.4",
|
||||
"mocha": "^8.4.0",
|
||||
"object-hash": "^2.2.0",
|
||||
"serve-static": "^1.14.1",
|
||||
"terser": "^5.7.0",
|
||||
"typescript": "^4.2.4",
|
||||
"xhr2": "^0.2.1"
|
||||
"terser": "5.7.1",
|
||||
"typescript": "4.3.5",
|
||||
"undici": "4.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nodelib/fs.scandir": {
|
||||
@ -1628,8 +1621,7 @@
|
||||
"dev": true
|
||||
},
|
||||
"commander": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
|
||||
"version": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
|
||||
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
|
||||
"dev": true
|
||||
},
|
||||
@ -1857,8 +1849,7 @@
|
||||
}
|
||||
},
|
||||
"globby": {
|
||||
"version": "11.0.3",
|
||||
"resolved": "https://registry.npmjs.org/globby/-/globby-11.0.3.tgz",
|
||||
"version": "https://registry.npmjs.org/globby/-/globby-11.0.3.tgz",
|
||||
"integrity": "sha512-ffdmosjA807y7+lA1NM0jELARVmYul/715xiILEjo3hBLPTcirgQNnXECn5g3mtR8TOLCVbkfua1Hpen25/Xcg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@ -2397,12 +2388,6 @@
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
},
|
||||
"xhr2": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.2.1.tgz",
|
||||
"integrity": "sha512-sID0rrVCqkVNUn8t6xuv9+6FViXjUVXq8H5rWOH2rz9fDNQEd4g0EA2XlcEdJXRz5BMEn4O1pJFdT+z4YHhoWw==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -13,6 +13,6 @@ import Secrets
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[]
|
||||
|
@ -9,6 +9,6 @@ import Route exposing (Route)
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[]
|
||||
|
@ -535,7 +535,7 @@ maybeToString maybeString =
|
||||
|
||||
|
||||
|
||||
routePatterns : ApiRoute.Done ApiRoute.Response
|
||||
routePatterns : ApiRoute.ApiRoute ApiRoute.Response
|
||||
routePatterns =
|
||||
ApiRoute.succeed
|
||||
(Json.Encode.list
|
||||
@ -599,7 +599,7 @@ getStaticRoutes =
|
||||
|> DataSource.map List.concat
|
||||
|
||||
|
||||
pathsToGenerateHandler : ApiRoute.Done ApiRoute.Response
|
||||
pathsToGenerateHandler : ApiRoute.ApiRoute ApiRoute.Response
|
||||
pathsToGenerateHandler =
|
||||
ApiRoute.succeed
|
||||
(DataSource.map2
|
||||
@ -630,7 +630,7 @@ pathsToGenerateHandler =
|
||||
|> ApiRoute.single
|
||||
|
||||
|
||||
manifestHandler : ApiRoute.Done ApiRoute.Response
|
||||
manifestHandler : ApiRoute.ApiRoute ApiRoute.Response
|
||||
manifestHandler =
|
||||
ApiRoute.succeed
|
||||
(getStaticRoutes
|
||||
|
@ -9,6 +9,6 @@ import Route exposing (Route)
|
||||
routes :
|
||||
DataSource (List Route)
|
||||
-> (Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
routes getStaticRoutes htmlToString =
|
||||
[]
|
||||
|
@ -1,31 +1,31 @@
|
||||
module ApiRoute exposing (Done, Handler, Response, buildTimeRoutes, capture, int, literal, single, slash, succeed, getBuildTimeRoutes)
|
||||
module ApiRoute exposing (ApiRoute, ApiRouteBuilder, Response, buildTimeRoutes, capture, int, literal, single, slash, succeed, getBuildTimeRoutes)
|
||||
|
||||
{-|
|
||||
|
||||
@docs Done, Handler, Response, buildTimeRoutes, capture, int, literal, single, slash, succeed, getBuildTimeRoutes
|
||||
@docs ApiRoute, ApiRouteBuilder, Response, buildTimeRoutes, capture, int, literal, single, slash, succeed, getBuildTimeRoutes
|
||||
|
||||
-}
|
||||
|
||||
import DataSource exposing (DataSource)
|
||||
import Internal.ApiRoute exposing (Done(..), Handler(..))
|
||||
import Internal.ApiRoute exposing (ApiRoute(..), ApiRouteBuilder(..))
|
||||
import Regex
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias Done response =
|
||||
Internal.ApiRoute.Done response
|
||||
type alias ApiRoute response =
|
||||
Internal.ApiRoute.ApiRoute response
|
||||
|
||||
|
||||
{-| -}
|
||||
single : Handler (DataSource Response) (List String) -> Done Response
|
||||
single : ApiRouteBuilder (DataSource Response) (List String) -> ApiRoute Response
|
||||
single handler =
|
||||
handler
|
||||
|> buildTimeRoutes (\constructor -> DataSource.succeed [ constructor ])
|
||||
|
||||
|
||||
{-| -}
|
||||
buildTimeRoutes : (constructor -> DataSource (List (List String))) -> Handler (DataSource Response) constructor -> Done Response
|
||||
buildTimeRoutes buildUrls ((Handler pattern _ toString constructor) as fullHandler) =
|
||||
buildTimeRoutes : (constructor -> DataSource (List (List String))) -> ApiRouteBuilder (DataSource Response) constructor -> ApiRoute Response
|
||||
buildTimeRoutes buildUrls ((ApiRouteBuilder pattern _ toString constructor) as fullHandler) =
|
||||
let
|
||||
buildTimeRoutes__ : DataSource (List String)
|
||||
buildTimeRoutes__ =
|
||||
@ -36,7 +36,7 @@ buildTimeRoutes buildUrls ((Handler pattern _ toString constructor) as fullHandl
|
||||
preBuiltMatches =
|
||||
buildUrls (constructor [])
|
||||
in
|
||||
Done
|
||||
ApiRoute
|
||||
{ regex = Regex.fromString ("^" ++ pattern ++ "$") |> Maybe.withDefault Regex.never
|
||||
, matchesToResponse =
|
||||
\path ->
|
||||
@ -75,8 +75,8 @@ buildTimeRoutes buildUrls ((Handler pattern _ toString constructor) as fullHandl
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias Handler a constructor =
|
||||
Internal.ApiRoute.Handler a constructor
|
||||
type alias ApiRouteBuilder a constructor =
|
||||
Internal.ApiRoute.ApiRouteBuilder a constructor
|
||||
|
||||
|
||||
{-| -}
|
||||
@ -85,29 +85,29 @@ type alias Response =
|
||||
|
||||
|
||||
{-| -}
|
||||
succeed : a -> Handler a (List String)
|
||||
succeed : a -> ApiRouteBuilder a (List String)
|
||||
succeed a =
|
||||
Handler "" (\_ -> a) (\_ -> "") (\list -> list)
|
||||
ApiRouteBuilder "" (\_ -> a) (\_ -> "") (\list -> list)
|
||||
|
||||
|
||||
{-| -}
|
||||
literal : String -> Handler a constructor -> Handler a constructor
|
||||
literal segment (Handler pattern handler toString constructor) =
|
||||
Handler (pattern ++ segment) handler (\values -> toString values ++ segment) constructor
|
||||
literal : String -> ApiRouteBuilder a constructor -> ApiRouteBuilder a constructor
|
||||
literal segment (ApiRouteBuilder pattern handler toString constructor) =
|
||||
ApiRouteBuilder (pattern ++ segment) handler (\values -> toString values ++ segment) constructor
|
||||
|
||||
|
||||
{-| -}
|
||||
slash : Handler a constructor -> Handler a constructor
|
||||
slash (Handler pattern handler toString constructor) =
|
||||
Handler (pattern ++ "/") handler (\arg -> toString arg ++ "/") constructor
|
||||
slash : ApiRouteBuilder a constructor -> ApiRouteBuilder a constructor
|
||||
slash (ApiRouteBuilder pattern handler toString constructor) =
|
||||
ApiRouteBuilder (pattern ++ "/") handler (\arg -> toString arg ++ "/") constructor
|
||||
|
||||
|
||||
{-| -}
|
||||
capture :
|
||||
Handler (String -> a) constructor
|
||||
-> Handler a (String -> constructor)
|
||||
capture (Handler pattern previousHandler toString constructor) =
|
||||
Handler
|
||||
ApiRouteBuilder (String -> a) constructor
|
||||
-> ApiRouteBuilder a (String -> constructor)
|
||||
capture (ApiRouteBuilder pattern previousHandler toString constructor) =
|
||||
ApiRouteBuilder
|
||||
(pattern ++ "(.*)")
|
||||
(\matches ->
|
||||
case matches of
|
||||
@ -133,10 +133,10 @@ capture (Handler pattern previousHandler toString constructor) =
|
||||
|
||||
{-| -}
|
||||
int :
|
||||
Handler (Int -> a) constructor
|
||||
-> Handler a (Int -> constructor)
|
||||
int (Handler pattern previousHandler toString constructor) =
|
||||
Handler
|
||||
ApiRouteBuilder (Int -> a) constructor
|
||||
-> ApiRouteBuilder a (Int -> constructor)
|
||||
int (ApiRouteBuilder pattern previousHandler toString constructor) =
|
||||
ApiRouteBuilder
|
||||
(pattern ++ "(\\d+)")
|
||||
(\matches ->
|
||||
case matches of
|
||||
@ -161,12 +161,12 @@ int (Handler pattern previousHandler toString constructor) =
|
||||
|
||||
|
||||
{-| -}
|
||||
getBuildTimeRoutes : Done response -> DataSource (List String)
|
||||
getBuildTimeRoutes (Done handler) =
|
||||
getBuildTimeRoutes : ApiRoute response -> DataSource (List String)
|
||||
getBuildTimeRoutes (ApiRoute handler) =
|
||||
handler.buildTimeRoutes
|
||||
|
||||
|
||||
|
||||
--captureRest : Handler (List String -> a) b -> Handler a b
|
||||
--captureRest : ApiRouteBuilder (List String -> a) b -> ApiRouteBuilder a b
|
||||
--captureRest previousHandler =
|
||||
-- Debug.todo ""
|
||||
|
@ -160,8 +160,8 @@ map fn requestInfo =
|
||||
map fn (lookupFn keepOrDiscard appType rawResponses)
|
||||
)
|
||||
|
||||
Done stripped value ->
|
||||
Done stripped (fn value)
|
||||
ApiRoute stripped value ->
|
||||
ApiRoute stripped (fn value)
|
||||
|
||||
|
||||
dontSaveData : DataSource a -> DataSource a
|
||||
@ -177,7 +177,7 @@ dontSaveData requestInfo =
|
||||
lookupFn KeepOrDiscard.Discard appType rawResponses
|
||||
)
|
||||
|
||||
Done _ _ ->
|
||||
ApiRoute _ _ ->
|
||||
requestInfo
|
||||
|
||||
|
||||
@ -225,7 +225,7 @@ distill uniqueKey encode decode dataSource =
|
||||
|> distill uniqueKey encode decode
|
||||
)
|
||||
|
||||
Done strippedResponses value ->
|
||||
ApiRoute strippedResponses value ->
|
||||
Request
|
||||
(strippedResponses
|
||||
|> Dict.insert
|
||||
@ -334,7 +334,7 @@ toResult result =
|
||||
RequestError error
|
||||
|
||||
Ok ( stripped, okValue ) ->
|
||||
Done stripped okValue
|
||||
ApiRoute stripped okValue
|
||||
|
||||
|
||||
{-| -}
|
||||
@ -451,26 +451,26 @@ map2 fn request1 request2 =
|
||||
(lookupFn2 keepOrDiscard appType rawResponses)
|
||||
)
|
||||
|
||||
( Request dict1 ( urls1, lookupFn1 ), Done stripped2 value2 ) ->
|
||||
( Request dict1 ( urls1, lookupFn1 ), ApiRoute stripped2 value2 ) ->
|
||||
Request dict1
|
||||
( urls1
|
||||
, \keepOrDiscard appType rawResponses ->
|
||||
map2 fn
|
||||
(lookupFn1 keepOrDiscard appType rawResponses)
|
||||
(Done stripped2 value2)
|
||||
(ApiRoute stripped2 value2)
|
||||
)
|
||||
|
||||
( Done stripped2 value2, Request dict1 ( urls1, lookupFn1 ) ) ->
|
||||
( ApiRoute stripped2 value2, Request dict1 ( urls1, lookupFn1 ) ) ->
|
||||
Request dict1
|
||||
( urls1
|
||||
, \keepOrDiscard appType rawResponses ->
|
||||
map2 fn
|
||||
(Done stripped2 value2)
|
||||
(ApiRoute stripped2 value2)
|
||||
(lookupFn1 keepOrDiscard appType rawResponses)
|
||||
)
|
||||
|
||||
( Done stripped1 value1, Done stripped2 value2 ) ->
|
||||
Done
|
||||
( ApiRoute stripped1 value1, ApiRoute stripped2 value2 ) ->
|
||||
ApiRoute
|
||||
(combineReducedDicts stripped1 stripped2)
|
||||
(fn value1 value2)
|
||||
|
||||
@ -511,7 +511,7 @@ lookupHelp strippedSoFar keepOrDiscard appType requestInfo rawResponses =
|
||||
(addUrls urls (lookupFn keepOrDiscard appType rawResponses))
|
||||
rawResponses
|
||||
|
||||
Done stripped value ->
|
||||
ApiRoute stripped value ->
|
||||
Ok ( combineReducedDicts stripped strippedSoFar, value )
|
||||
|
||||
|
||||
@ -524,8 +524,8 @@ addUrls urlsToAdd requestInfo =
|
||||
Request stripped ( initialUrls, function ) ->
|
||||
Request stripped ( initialUrls ++ urlsToAdd, function )
|
||||
|
||||
Done stripped value ->
|
||||
Done stripped value
|
||||
ApiRoute stripped value ->
|
||||
ApiRoute stripped value
|
||||
|
||||
|
||||
{-| The full details to perform a StaticHttp request.
|
||||
@ -548,7 +548,7 @@ lookupUrls requestInfo =
|
||||
Request _ ( urls, _ ) ->
|
||||
urls
|
||||
|
||||
Done _ _ ->
|
||||
ApiRoute _ _ ->
|
||||
[]
|
||||
|
||||
|
||||
@ -595,8 +595,8 @@ andThen fn requestInfo =
|
||||
RequestError error ->
|
||||
RequestError error
|
||||
|
||||
Done dict finalValue ->
|
||||
Done (combineReducedDicts strippedResponses dict) finalValue
|
||||
ApiRoute dict finalValue ->
|
||||
ApiRoute (combineReducedDicts strippedResponses dict) finalValue
|
||||
)
|
||||
)
|
||||
|
||||
@ -637,7 +637,7 @@ succeed value =
|
||||
Request Dict.empty
|
||||
( []
|
||||
, \_ _ _ ->
|
||||
Done Dict.empty value
|
||||
ApiRoute Dict.empty value
|
||||
)
|
||||
|
||||
|
||||
|
@ -464,4 +464,4 @@ toResult result =
|
||||
RequestError error
|
||||
|
||||
Ok ( stripped, okValue ) ->
|
||||
Done stripped okValue
|
||||
ApiRoute stripped okValue
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Internal.ApiRoute exposing
|
||||
( Done(..)
|
||||
, Handler(..)
|
||||
( ApiRoute(..)
|
||||
, ApiRouteBuilder(..)
|
||||
, firstMatch
|
||||
, pathToMatches
|
||||
, tryMatch
|
||||
@ -12,7 +12,7 @@ import Regex exposing (Regex)
|
||||
|
||||
|
||||
{-| -}
|
||||
firstMatch : String -> List (Done response) -> Maybe (Done response)
|
||||
firstMatch : String -> List (ApiRoute response) -> Maybe (ApiRoute response)
|
||||
firstMatch path handlers =
|
||||
case handlers of
|
||||
[] ->
|
||||
@ -28,18 +28,18 @@ firstMatch path handlers =
|
||||
|
||||
|
||||
{-| -}
|
||||
tryMatchDone : String -> Done response -> Maybe (Done response)
|
||||
tryMatchDone path (Done handler) =
|
||||
tryMatchDone : String -> ApiRoute response -> Maybe (ApiRoute response)
|
||||
tryMatchDone path (ApiRoute handler) =
|
||||
if Regex.contains handler.regex path then
|
||||
Just (Done handler)
|
||||
Just (ApiRoute handler)
|
||||
|
||||
else
|
||||
Nothing
|
||||
|
||||
|
||||
{-| -}
|
||||
type Done response
|
||||
= Done
|
||||
type ApiRoute response
|
||||
= ApiRoute
|
||||
{ regex : Regex
|
||||
, matchesToResponse : String -> DataSource (Maybe response)
|
||||
, buildTimeRoutes : DataSource (List String)
|
||||
@ -48,8 +48,8 @@ type Done response
|
||||
|
||||
|
||||
{-| -}
|
||||
pathToMatches : String -> Handler a constructor -> List String
|
||||
pathToMatches path (Handler pattern _ _ _) =
|
||||
pathToMatches : String -> ApiRouteBuilder a constructor -> List String
|
||||
pathToMatches path (ApiRouteBuilder pattern _ _ _) =
|
||||
Regex.find
|
||||
(Regex.fromString pattern
|
||||
|> Maybe.withDefault Regex.never
|
||||
@ -60,15 +60,15 @@ pathToMatches path (Handler pattern _ _ _) =
|
||||
|
||||
|
||||
{-| -}
|
||||
withRoutes : (constructor -> List (List String)) -> Handler a constructor -> List String
|
||||
withRoutes buildUrls (Handler _ _ toString constructor) =
|
||||
withRoutes : (constructor -> List (List String)) -> ApiRouteBuilder a constructor -> List String
|
||||
withRoutes buildUrls (ApiRouteBuilder _ _ toString constructor) =
|
||||
buildUrls (constructor [])
|
||||
|> List.map toString
|
||||
|
||||
|
||||
{-| -}
|
||||
tryMatch : String -> Handler response constructor -> Maybe response
|
||||
tryMatch path (Handler pattern handler _ _) =
|
||||
tryMatch : String -> ApiRouteBuilder response constructor -> Maybe response
|
||||
tryMatch path (ApiRouteBuilder pattern handler _ _) =
|
||||
let
|
||||
matches : List String
|
||||
matches =
|
||||
@ -85,5 +85,5 @@ tryMatch path (Handler pattern handler _ _) =
|
||||
|
||||
|
||||
{-| -}
|
||||
type Handler a constructor
|
||||
= Handler String (List String -> a) (List String -> String) (List String -> constructor)
|
||||
type ApiRouteBuilder a constructor
|
||||
= ApiRouteBuilder String (List String -> a) (List String -> String) (List String -> constructor)
|
||||
|
@ -17,7 +17,7 @@ import Head
|
||||
import Html exposing (Html)
|
||||
import HtmlPrinter
|
||||
import Http
|
||||
import Internal.ApiRoute exposing (Done(..))
|
||||
import Internal.ApiRoute exposing (ApiRoute(..))
|
||||
import Json.Decode as Decode
|
||||
import Json.Encode
|
||||
import Pages.ContentCache as ContentCache exposing (ContentCache)
|
||||
@ -405,7 +405,7 @@ initLegacy renderRequest { secrets, staticHttpCache } contentCache config flags
|
||||
)
|
||||
(config.handleRoute serverRequestPayload.frontmatter)
|
||||
|
||||
RenderRequest.Api ( path, Done apiRequest ) ->
|
||||
RenderRequest.Api ( path, ApiRoute apiRequest ) ->
|
||||
StaticResponses.renderApiRequest
|
||||
(apiRequest.matchesToResponse path)
|
||||
|
||||
@ -623,7 +623,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
|
||||
case model.maybeRequestJson of
|
||||
RenderRequest.SinglePage includeHtml requestPayload value ->
|
||||
case requestPayload of
|
||||
RenderRequest.Api ( path, Done apiHandler ) ->
|
||||
RenderRequest.Api ( path, ApiRoute apiHandler ) ->
|
||||
let
|
||||
thing : DataSource (Maybe ApiRoute.Response)
|
||||
thing =
|
||||
|
@ -8,7 +8,7 @@ import Dict exposing (Dict)
|
||||
import Dict.Extra
|
||||
import Html exposing (Html)
|
||||
import HtmlPrinter exposing (htmlToString)
|
||||
import Internal.ApiRoute exposing (Done(..))
|
||||
import Internal.ApiRoute exposing (ApiRoute(..))
|
||||
import Pages.Internal.ApplicationType as ApplicationType
|
||||
import Pages.Internal.NotFoundReason exposing (NotFoundReason)
|
||||
import Pages.SiteConfig exposing (SiteConfig)
|
||||
@ -41,13 +41,13 @@ buildTimeFilesRequest :
|
||||
{ config
|
||||
| apiRoutes :
|
||||
(Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
}
|
||||
-> DataSource (List (Result String { path : List String, content : String }))
|
||||
buildTimeFilesRequest config =
|
||||
config.apiRoutes htmlToString
|
||||
|> List.map
|
||||
(\(Done handler) ->
|
||||
(\(ApiRoute handler) ->
|
||||
handler.buildTimeRoutes
|
||||
|> DataSource.andThen
|
||||
(\paths ->
|
||||
@ -190,7 +190,7 @@ nextStep :
|
||||
, data : route -> DataSource pageData
|
||||
, sharedData : DataSource sharedData
|
||||
, site : SiteConfig route siteData
|
||||
, apiRoutes : (Html Never -> String) -> List (ApiRoute.Done ApiRoute.Response)
|
||||
, apiRoutes : (Html Never -> String) -> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
}
|
||||
->
|
||||
{ model
|
||||
|
@ -67,7 +67,7 @@ type alias ProgramConfig userMsg userModel route siteData pageData sharedData =
|
||||
-> userMsg
|
||||
, apiRoutes :
|
||||
(Html Never -> String)
|
||||
-> List (ApiRoute.Done ApiRoute.Response)
|
||||
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
, pathPatterns : List RoutePattern
|
||||
, basePath : List String
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import TerminalText as Terminal
|
||||
type RawRequest value
|
||||
= Request (Dict String WhatToDo) ( List (Secrets.Value Pages.StaticHttp.Request.Request), KeepOrDiscard -> ApplicationType -> RequestsAndPending -> RawRequest value )
|
||||
| RequestError Error
|
||||
| Done (Dict String WhatToDo) value
|
||||
| ApiRoute (Dict String WhatToDo) value
|
||||
|
||||
|
||||
type WhatToDo
|
||||
@ -186,7 +186,7 @@ strippedResponsesHelp usedSoFar appType request rawResponses =
|
||||
followupRequest
|
||||
rawResponses
|
||||
|
||||
Done partiallyStrippedResponses _ ->
|
||||
ApiRoute partiallyStrippedResponses _ ->
|
||||
Dict.merge
|
||||
(\key a -> Dict.insert key a)
|
||||
(\key a b -> Dict.insert key (merge key a b))
|
||||
@ -244,7 +244,7 @@ resolve appType request rawResponses =
|
||||
nextRequest ->
|
||||
resolve appType nextRequest rawResponses
|
||||
|
||||
Done _ value ->
|
||||
ApiRoute _ value ->
|
||||
Ok value
|
||||
|
||||
|
||||
@ -271,7 +271,7 @@ resolveUrlsHelp appType rawResponses soFar request =
|
||||
(soFar ++ urlList)
|
||||
(lookupFn KeepOrDiscard.Keep appType rawResponses)
|
||||
|
||||
Done _ _ ->
|
||||
ApiRoute _ _ ->
|
||||
soFar
|
||||
|
||||
|
||||
@ -316,5 +316,5 @@ cacheRequestResolutionHelp foundUrls appType rawResponses request =
|
||||
rawResponses
|
||||
(lookupFn KeepOrDiscard.Keep appType rawResponses)
|
||||
|
||||
Done _ _ ->
|
||||
ApiRoute _ _ ->
|
||||
Complete
|
||||
|
@ -20,7 +20,7 @@ import Url exposing (Url)
|
||||
|
||||
type RequestPayload route
|
||||
= Page { path : Path, frontmatter : route }
|
||||
| Api ( String, ApiRoute.Done ApiRoute.Response )
|
||||
| Api ( String, ApiRoute.ApiRoute ApiRoute.Response )
|
||||
| NotFound Path
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ requestPayloadDecoder config =
|
||||
route =
|
||||
pathToUrl path |> config.urlToRoute
|
||||
|
||||
apiRoute : Maybe (ApiRoute.Done ApiRoute.Response)
|
||||
apiRoute : Maybe (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
apiRoute =
|
||||
Internal.ApiRoute.firstMatch (String.dropLeft 1 path)
|
||||
(config.apiRoutes HtmlPrinter.htmlToString)
|
||||
|
@ -988,7 +988,7 @@ startWithHttpCache =
|
||||
|
||||
|
||||
startLowLevel :
|
||||
List (ApiRoute.Done ApiRoute.Response)
|
||||
List (ApiRoute.ApiRoute ApiRoute.Response)
|
||||
-> List ( Request.Request, String )
|
||||
-> List ( List String, DataSource a )
|
||||
-> ProgramTest (Model Route) Msg Effect
|
||||
|
Loading…
Reference in New Issue
Block a user