refactor air scripts

This commit is contained in:
DieMyst 2020-11-26 15:14:12 +03:00
parent 5bac4d8e6f
commit d8aa521f60
4 changed files with 46 additions and 50 deletions

View File

@ -0,0 +1,31 @@
module AirScripts.CallPeers exposing (..)
import Air exposing (Air)
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
import Json.Encode exposing (list, string)
air : String -> String -> (String, String, String) -> List String -> Air
air peerId relayId (event, service, fnName) peers =
let
clientIdSet =
set "clientId" <| string peerId
relayIdSet =
set "relayId" <| string relayId
peersSet =
set "peers" <| list string peers
airScript =
seq
(callBI "relayId" ( "op", "identity" ) [] Nothing)
(fold "peers" "p" <|
par
(seq
(callBI "p" ( service, fnName ) [] (Just "result"))
(relayEvent event [ "p", "result" ])
)
(next "p")
)
in
clientIdSet <| relayIdSet <| peersSet <| airScript

View File

@ -1,31 +1,9 @@
module Modules.Air exposing (..)
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
import Json.Encode exposing (list, string)
import Air exposing (Air)
import AirScripts.CallPeers
air : String -> String -> List String -> Air
air peerId relayId peers =
let
clientIdSet =
set "clientId" <| string peerId
relayIdSet =
set "relayId" <| string relayId
peersSet =
set "peers" <| list string peers
airScript =
seq
(callBI "relayId" ( "op", "identity" ) [] Nothing)
(fold "peers" "p" <|
par
(seq
(callBI "p" ( "dist", "get_modules" ) [] (Just "modules"))
(relayEvent "modules_discovered" [ "p", "modules" ])
)
(next "p")
)
in
clientIdSet <| relayIdSet <| peersSet <| airScript
AirScripts.CallPeers.air peerId relayId ("modules_discovered", "dist", "get_modules") peers

9
src/Nodes/Air.elm Normal file
View File

@ -0,0 +1,9 @@
module Nodes.Air exposing (..)
import Air exposing (Air)
import AirScripts.CallPeers
air : String -> String -> List String -> Air
air peerId relayId peers =
AirScripts.CallPeers.air peerId relayId ("peer_identity", "op", "identify") peers

View File

@ -1,31 +1,9 @@
module Services.Air exposing (..)
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
import Json.Encode exposing (list, string)
import Air exposing (Air)
import AirScripts.CallPeers
air : String -> String -> List String -> Air
air peerId relayId peers =
let
clientIdSet =
set "clientId" <| string peerId
relayIdSet =
set "relayId" <| string relayId
peersSet =
set "peers" <| list string peers
airScript =
seq
(callBI "relayId" ( "op", "identity" ) [] Nothing)
(fold "peers" "p" <|
par
(seq
(callBI "p" ( "srv", "get_interfaces" ) [] (Just "interfaces"))
(relayEvent "services_discovered" [ "p", "interfaces" ])
)
(next "p")
)
in
clientIdSet <| relayIdSet <| peersSet <| airScript
AirScripts.CallPeers.air peerId relayId ("services_discovered", "srv", "get_interfaces") peers