Wire through request json.

This commit is contained in:
Dillon Kearns 2021-03-26 15:39:39 -07:00
parent 650a3e9cee
commit da3ef40e7f
3 changed files with 27 additions and 15 deletions

View File

@ -53,6 +53,7 @@ type alias Model pathKey metadata =
, mode : Mode , mode : Mode
, pendingRequests : List { masked : RequestDetails, unmasked : RequestDetails } , pendingRequests : List { masked : RequestDetails, unmasked : RequestDetails }
, unprocessedPages : List ( PagePath pathKey, metadata ) , unprocessedPages : List ( PagePath pathKey, metadata )
, maybeRequestJson : Maybe Decode.Value
} }
@ -141,14 +142,19 @@ cliApplication cliMsgConstructor narrowMsg toModel fromModel config =
Platform.worker Platform.worker
{ init = { init =
\flags -> \flags ->
init toModel contentCache siteMetadata config flags let
|> Tuple.mapSecond (perform config cliMsgConstructor config.toJsPort) maybeRequestJson =
Decode.decodeValue (optionalField "request" Decode.value) flags
|> Result.withDefault Nothing
in
init maybeRequestJson toModel contentCache siteMetadata config flags
|> Tuple.mapSecond (perform maybeRequestJson config cliMsgConstructor config.toJsPort)
, update = , update =
\msg model -> \msg model ->
case ( narrowMsg msg, fromModel model ) of case ( narrowMsg msg, fromModel model ) of
( Just cliMsg, Just cliModel ) -> ( Just cliMsg, Just cliModel ) ->
update contentCache siteMetadata config cliMsg cliModel update contentCache siteMetadata config cliMsg cliModel
|> Tuple.mapSecond (perform config cliMsgConstructor config.toJsPort) |> Tuple.mapSecond (perform cliModel.maybeRequestJson config cliMsgConstructor config.toJsPort)
|> Tuple.mapFirst toModel |> Tuple.mapFirst toModel
_ -> _ ->
@ -185,8 +191,8 @@ asJsonView x =
Json.Encode.string "REPLACE_ME_WITH_JSON_STRINGIFY" Json.Encode.string "REPLACE_ME_WITH_JSON_STRINGIFY"
perform : Config pathKey userMsg userModel metadata view -> (Msg -> msg) -> (Json.Encode.Value -> Cmd Never) -> Effect pathKey -> Cmd msg perform : Maybe Decode.Value -> Config pathKey userMsg userModel metadata view -> (Msg -> msg) -> (Json.Encode.Value -> Cmd Never) -> Effect pathKey -> Cmd msg
perform config cliMsgConstructor toJsPort effect = perform maybeRequest config cliMsgConstructor toJsPort effect =
case effect of case effect of
Effect.NoEffect -> Effect.NoEffect ->
Cmd.none Cmd.none
@ -199,7 +205,7 @@ perform config cliMsgConstructor toJsPort effect =
Effect.Batch list -> Effect.Batch list ->
list list
|> List.map (perform config cliMsgConstructor toJsPort) |> List.map (perform maybeRequest config cliMsgConstructor toJsPort)
|> Cmd.batch |> Cmd.batch
Effect.FetchHttp ({ unmasked, masked } as requests) -> Effect.FetchHttp ({ unmasked, masked } as requests) ->
@ -298,13 +304,14 @@ flagsDecoder =
init : init :
(Model pathKey metadata -> model) Maybe Decode.Value
-> (Model pathKey metadata -> model)
-> ContentCache.ContentCache metadata view -> ContentCache.ContentCache metadata view
-> Result (List BuildError) (List ( PagePath pathKey, metadata )) -> Result (List BuildError) (List ( PagePath pathKey, metadata ))
-> Config pathKey userMsg userModel metadata view -> Config pathKey userMsg userModel metadata view
-> Decode.Value -> Decode.Value
-> ( model, Effect pathKey ) -> ( model, Effect pathKey )
init toModel contentCache siteMetadata config flags = init maybeRequestJson toModel contentCache siteMetadata config flags =
case Decode.decodeValue flagsDecoder flags of case Decode.decodeValue flagsDecoder flags of
Ok { secrets, mode, staticHttpCache } -> Ok { secrets, mode, staticHttpCache } ->
case mode of case mode of
@ -312,7 +319,7 @@ init toModel contentCache siteMetadata config flags =
-- elmToHtmlBetaInit { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache siteMetadata config flags -- elmToHtmlBetaInit { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache siteMetadata config flags
-- --
_ -> _ ->
initLegacy { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache siteMetadata config flags initLegacy maybeRequestJson { secrets = secrets, mode = mode, staticHttpCache = staticHttpCache } toModel contentCache siteMetadata config flags
Err error -> Err error ->
updateAndSendPortIfDone updateAndSendPortIfDone
@ -330,6 +337,7 @@ init toModel contentCache siteMetadata config flags =
Mode.Dev Mode.Dev
[] []
(siteMetadata |> Result.withDefault []) (siteMetadata |> Result.withDefault [])
maybeRequestJson
) )
toModel toModel
@ -367,7 +375,7 @@ optionalField fieldName decoder =
|> Decode.andThen finishDecoding |> Decode.andThen finishDecoding
initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata config flags = initLegacy maybeRequestJson { secrets, mode, staticHttpCache } toModel contentCache siteMetadata config flags =
let let
maybeRequestPayload = maybeRequestPayload =
Decode.decodeValue requestPayloadDecoder flags Decode.decodeValue requestPayloadDecoder flags
@ -414,7 +422,7 @@ initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata
StaticResponses.init staticHttpCache filteredMetadata config [] StaticResponses.init staticHttpCache filteredMetadata config []
in in
StaticResponses.nextStep config filteredMetadata (filteredMetadata |> Result.map (List.take 1)) mode secrets staticHttpCache [] staticResponses StaticResponses.nextStep config filteredMetadata (filteredMetadata |> Result.map (List.take 1)) mode secrets staticHttpCache [] staticResponses
|> nextStepToEffect contentCache config (Model staticResponses secrets [] staticHttpCache mode [] (filteredMetadata |> Result.withDefault [])) |> nextStepToEffect contentCache config (Model staticResponses secrets [] staticHttpCache mode [] (filteredMetadata |> Result.withDefault []) maybeRequestJson)
|> Tuple.mapFirst toModel |> Tuple.mapFirst toModel
pageErrors -> pageErrors ->
@ -448,6 +456,7 @@ initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata
mode mode
[] []
(filteredMetadata |> Result.withDefault []) (filteredMetadata |> Result.withDefault [])
maybeRequestJson
) )
toModel toModel
@ -463,6 +472,7 @@ initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata
mode mode
[] []
(filteredMetadata |> Result.withDefault []) (filteredMetadata |> Result.withDefault [])
maybeRequestJson
) )
toModel toModel

View File

@ -102,7 +102,8 @@ startWithHttpCache =
startLowLevel : startLowLevel :
StaticHttp.Request StaticHttp.Request
(List (List
(Result String (Result
String
{ path : List String { path : List String
, content : String , content : String
} }
@ -212,7 +213,7 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages =
-> ( model, Effect pathKey ) -> ( model, Effect pathKey )
-} -}
ProgramTest.createDocument ProgramTest.createDocument
{ init = Main.init identity contentCache siteMetadata config { init = Main.init Nothing identity contentCache siteMetadata config
, update = Main.update contentCache siteMetadata config , update = Main.update contentCache siteMetadata config
, view = \_ -> { title = "", body = [] } , view = \_ -> { title = "", body = [] }
} }

View File

@ -787,7 +787,8 @@ startWithHttpCache =
startLowLevel : startLowLevel :
StaticHttp.Request StaticHttp.Request
(List (List
(Result String (Result
String
{ path : List String { path : List String
, content : String , content : String
} }
@ -893,7 +894,7 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages =
-> ( model, Effect pathKey ) -> ( model, Effect pathKey )
-} -}
ProgramTest.createDocument ProgramTest.createDocument
{ init = Main.init identity contentCache siteMetadata config { init = Main.init Nothing identity contentCache siteMetadata config
, update = Main.update contentCache siteMetadata config , update = Main.update contentCache siteMetadata config
, view = \_ -> { title = "", body = [] } , view = \_ -> { title = "", body = [] }
} }