Skip to content

Commit

Permalink
Update program code to use new platform name in Elm API
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Jun 21, 2023
1 parent bfcc3eb commit 6e77e72
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
43 changes: 23 additions & 20 deletions implement/alternate-ui/source/src/Backend/Main.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Backend.Main exposing
( State
, webServerMain
, webServiceMain
)

import Base64
Expand All @@ -14,7 +14,7 @@ import EveOnline.VolatileProcessInterface
import InterfaceToFrontendClient
import Json.Decode
import Json.Encode
import Platform.WebServer
import Platform.WebService
import Url
import Url.Parser

Expand Down Expand Up @@ -56,14 +56,14 @@ routeFromUrl =
)


webServerMain : Platform.WebServer.WebServerConfig State
webServerMain =
webServiceMain : Platform.WebService.WebServiceConfig State
webServiceMain =
{ init = ( initState, [] )
, subscriptions = subscriptions
}


subscriptions : State -> Platform.WebServer.Subscriptions State
subscriptions : State -> Platform.WebService.Subscriptions State
subscriptions _ =
{ httpRequest = updateForHttpRequestEvent
, posixTimeIsPast = Nothing
Expand All @@ -78,13 +78,13 @@ initSetup =
}


maintainVolatileProcessTaskFromState : State -> Platform.WebServer.Commands State
maintainVolatileProcessTaskFromState : State -> Platform.WebService.Commands State
maintainVolatileProcessTaskFromState state =
if state.setup.createVolatileProcessResult /= Nothing then
[]

else
[ Platform.WebServer.CreateVolatileProcess
[ Platform.WebService.CreateVolatileProcess
{ programCode = CompilationInterface.SourceFiles.file____src_EveOnline_VolatileProcess_csx.utf8
, update =
\createVolatileProcessResult stateBefore ->
Expand All @@ -101,7 +101,10 @@ maintainVolatileProcessTaskFromState state =
]


updateForHttpRequestEvent : Platform.WebServer.HttpRequestEventStruct -> State -> ( State, Platform.WebServer.Commands State )
updateForHttpRequestEvent :
Platform.WebService.HttpRequestEventStruct
-> State
-> ( State, Platform.WebService.Commands State )
updateForHttpRequestEvent httpRequestEvent stateBefore =
let
( state, cmds ) =
Expand All @@ -111,9 +114,9 @@ updateForHttpRequestEvent httpRequestEvent stateBefore =


updateForHttpRequestEventWithoutVolatileProcessMaintenance :
Platform.WebServer.HttpRequestEventStruct
Platform.WebService.HttpRequestEventStruct
-> State
-> ( State, Platform.WebServer.Commands State )
-> ( State, Platform.WebService.Commands State )
updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stateBefore =
let
contentHttpHeaders { contentType, contentEncoding } =
Expand All @@ -124,7 +127,7 @@ updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stat

continueWithStaticHttpResponse httpResponse =
( stateBefore
, [ Platform.WebServer.RespondToHttpRequest
, [ Platform.WebService.RespondToHttpRequest
{ httpRequestId = httpRequestEvent.httpRequestId
, response = httpResponse
}
Expand Down Expand Up @@ -193,7 +196,7 @@ updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stat
}
in
( { stateBefore | posixTimeMilli = httpRequestEvent.posixTimeMilli }
, [ Platform.WebServer.RespondToHttpRequest httpResponse ]
, [ Platform.WebService.RespondToHttpRequest httpResponse ]
)

Ok requestFromClient ->
Expand All @@ -214,7 +217,7 @@ updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stat
}
in
( { stateBefore | posixTimeMilli = httpRequestEvent.posixTimeMilli }
, [ Platform.WebServer.RespondToHttpRequest httpResponse ]
, [ Platform.WebService.RespondToHttpRequest httpResponse ]
)

InterfaceToFrontendClient.RunInVolatileProcessRequest runInVolatileProcessRequest ->
Expand All @@ -238,7 +241,7 @@ updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stat
}
in
( { stateBefore | posixTimeMilli = httpRequestEvent.posixTimeMilli }
, [ Platform.WebServer.RespondToHttpRequest httpResponse ]
, [ Platform.WebService.RespondToHttpRequest httpResponse ]
)

Just (Ok createVolatileProcessOk) ->
Expand All @@ -249,13 +252,13 @@ updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stat
:: stateBefore.httpRequestsTasks

requestToVolatileProcessTask =
Platform.WebServer.RequestToVolatileProcess
Platform.WebService.RequestToVolatileProcess
{ processId = createVolatileProcessOk.processId
, request = EveOnline.VolatileProcessInterface.buildRequestStringToGetResponseFromVolatileHost runInVolatileProcessRequest
, update =
\requestToVolatileProcessResult stateBeforeResult ->
case requestToVolatileProcessResult of
Err Platform.WebServer.ProcessNotFound ->
Err Platform.WebService.ProcessNotFound ->
( { stateBeforeResult
| setup = initSetup
}
Expand Down Expand Up @@ -297,15 +300,15 @@ updateForHttpRequestEventWithoutVolatileProcessMaintenance httpRequestEvent stat
}
in
( { stateBefore | posixTimeMilli = httpRequestEvent.posixTimeMilli }
, [ Platform.WebServer.RespondToHttpRequest httpResponse ]
, [ Platform.WebService.RespondToHttpRequest httpResponse ]
)


processRequestToVolatileProcessComplete :
{ httpRequestId : String }
-> Platform.WebServer.RequestToVolatileProcessComplete
-> Platform.WebService.RequestToVolatileProcessComplete
-> State
-> ( State, Platform.WebServer.Commands State )
-> ( State, Platform.WebService.Commands State )
processRequestToVolatileProcessComplete { httpRequestId } runInVolatileProcessComplete stateBefore =
let
httpRequestsTasks =
Expand Down Expand Up @@ -337,7 +340,7 @@ processRequestToVolatileProcessComplete { httpRequestId } runInVolatileProcessCo
in
( { stateBefore | httpRequestsTasks = httpRequestsTasks }
|> addLogEntries exceptionLogEntries
, [ Platform.WebServer.RespondToHttpRequest httpResponse ]
, [ Platform.WebService.RespondToHttpRequest httpResponse ]
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
module Platform.WebServer exposing (..)
module Platform.WebService exposing (..)

{-| This module contains the types describing the Elm-Time web server platform.
To build a web server app in Elm, copy this module file into your project and add a declaration with the name `webServerMain` to an Elm module.
{-| This module contains the types describing the Elm-Time web service platform.
To build a web service app in Elm, copy this module file into your project and add a declaration with the name `webServiceMain` to an Elm module.
For the latest version of the documentation, see <https://elm-time.org>
-}


{-| Use the type `WebServerConfig` on a declaration named `webServerMain` to declare a web server program in an Elm module.
A web server can subscribe to incoming HTTP requests and respond to them. It can also start and manage volatile processes to integrate other software.
{-| Use the type `WebServiceConfig` on a declaration named `webServiceMain` to declare a web service program in an Elm module.
A web service can subscribe to incoming HTTP requests and respond to them. It can also start and manage volatile processes to integrate other software.
-}
type alias WebServerConfig state =
type alias WebServiceConfig state =
{ init : ( state, Commands state )
, subscriptions : state -> Subscriptions state
}


type alias WebServerConfig state =
WebServiceConfig state


type alias Subscriptions state =
{ httpRequest : HttpRequestEventStruct -> state -> ( state, Commands state )
, posixTimeIsPast :
Expand Down

0 comments on commit 6e77e72

Please sign in to comment.