-module(omnimessage_server). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([pipe/3, application/3, start_actor/2, subscribe/2, dispatch/1, shutdown/0, wisp_http_middleware/5, mist_websocket_pipe/4, mist_websocket_application/4]). -export_type([encoder_decoder/3, app/3, composed_app/5]). -type encoder_decoder(AAVX, AAVY, AAVZ) :: {encoder_decoder, fun((AAVX) -> {ok, AAVY} | {error, nil}), fun((AAVY) -> {ok, AAVX} | {error, AAVZ})}. -opaque app(AAWA, AAWB, AAWC) :: {app, fun((AAWA) -> {AAWB, lustre@effect:effect(AAWC)}), fun((AAWB, AAWC) -> {AAWB, lustre@effect:effect(AAWC)}), fun((AAWB) -> lustre@internals@vdom:element(AAWC)), gleam@option:option(gleam@dict:dict(binary(), fun((gleam@dynamic:dynamic_()) -> {ok, AAWC} | {error, list(gleam@dynamic:decode_error())})))}. -opaque composed_app(AAWD, AAWE, AAWF, AAWG, AAWH) :: {composed_app, app(AAWD, AAWE, AAWF), encoder_decoder(AAWF, AAWG, AAWH)}. -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 80). -spec pipe(AAWI, encoder_decoder(AAWJ, AAWI, AAWK), fun((AAWJ) -> AAWJ)) -> {ok, gleam@option:option(AAWI)} | {error, AAWK}. pipe(Msg, Encoder_decoder, Handler) -> _pipe = Msg, _pipe@1 = (erlang:element(3, Encoder_decoder))(_pipe), _pipe@2 = gleam@result:map(_pipe@1, Handler), _pipe@3 = gleam@result:map(_pipe@2, erlang:element(2, Encoder_decoder)), gleam@result:map(_pipe@3, fun gleam@option:from_result/1). -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 123). -spec application( fun((ABBB) -> {ABAU, lustre@effect:effect(ABAV)}), fun((ABAU, ABAV) -> {ABAU, lustre@effect:effect(ABAV)}), encoder_decoder(ABAV, ABAZ, ABBA) ) -> composed_app(ABBB, ABAU, ABAV, ABAZ, ABBA). application(Init, Update, Encoder_decoder) -> View = fun(_) -> lustre@element:none() end, {composed_app, {app, Init, Update, View, none}, Encoder_decoder}. -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 142). -spec do_start_actor(app(AAXK, any(), AAXM), AAXK) -> {ok, gleam@erlang@process:subject(omnimessage_server@internal@lustre@runtime:action(AAXM, lustre:server_component()))} | {error, lustre:error()}. do_start_actor(App, Flags) -> On_attribute_change = gleam@option:unwrap( erlang:element(5, App), gleam@dict:new() ), _pipe = (erlang:element(2, App))(Flags), _pipe@1 = omnimessage_server@internal@lustre@runtime:start( _pipe, erlang:element(3, App), erlang:element(4, App), On_attribute_change ), gleam@result:map_error(_pipe@1, fun(Field@0) -> {actor_error, Field@0} end). -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 134). -spec start_actor(composed_app(AAWV, any(), AAWX, any(), any()), AAWV) -> {ok, gleam@erlang@process:subject(omnimessage_server@internal@lustre@runtime:action(AAWX, lustre:server_component()))} | {error, lustre:error()}. start_actor(App, Flags) -> do_start_actor(erlang:element(2, App), Flags). -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 155). -spec subscribe(binary(), fun((AAXV) -> nil)) -> omnimessage_server@internal@lustre@runtime:action(AAXV, any()). subscribe(Id, Dispatch) -> {update_subscribe, Id, Dispatch}. -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 161). -spec dispatch(AAXX) -> omnimessage_server@internal@lustre@runtime:action(AAXX, any()). dispatch(Message) -> {dispatch, Message}. -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 167). -spec shutdown() -> omnimessage_server@internal@lustre@runtime:action(any(), any()). shutdown() -> shutdown. -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 180). -spec wisp_http_middleware( gleam@http@request:request(wisp@internal:connection()), binary(), encoder_decoder(ABCU, binary(), any()), fun((ABCU) -> ABCU), fun(() -> gleam@http@response:response(wisp:body())) ) -> gleam@http@response:response(wisp:body()). wisp_http_middleware(Req, Path, Encoder_decoder, Handler, Fun) -> case {erlang:element(8, Req) =:= Path, erlang:element(2, Req)} of {true, post} -> wisp:require_string_body( Req, fun(Req_body) -> case begin _pipe = Req_body, pipe(_pipe, Encoder_decoder, Handler) end of {ok, {some, Res_body}} -> _pipe@1 = wisp:response(200), wisp:string_body(_pipe@1, Res_body); {ok, none} -> wisp:response(200); {error, _} -> wisp:unprocessable_entity() end end ); {_, _} -> Fun() end. -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 215). -spec mist_websocket_pipe( gleam@http@request:request(mist@internal@http:connection()), encoder_decoder(AAYD, binary(), AAYE), fun((AAYD) -> AAYD), fun((AAYE) -> nil) ) -> gleam@http@response:response(mist:response_data()). mist_websocket_pipe(Req, Encoder_decoder, Handler, On_error) -> mist:websocket(Req, fun(Runtime, Conn, Msg) -> case Msg of {text, Msg@1} -> _ = case pipe(Msg@1, Encoder_decoder, Handler) of {ok, {some, Encoded_msg}} -> mist:send_text_frame(Conn, Encoded_msg); {ok, none} -> {ok, nil}; {error, Decode_error} -> {ok, On_error(Decode_error)} end, gleam@otp@actor:continue(Runtime); {binary, _} -> gleam@otp@actor:continue(Runtime); {custom, _} -> gleam@otp@actor:continue(Runtime); closed -> {stop, normal}; shutdown -> {stop, normal} end end, fun(_) -> {none, none} end, fun(_) -> nil end). -file("/home/ofek/weedonandscott/Tech/lustre_omnistate/omnimessage_server/src/omnimessage_server.gleam", 260). -spec mist_websocket_application( gleam@http@request:request(mist@internal@http:connection()), composed_app(AAYK, any(), any(), binary(), AAYN), AAYK, fun((AAYN) -> nil) ) -> gleam@http@response:response(mist:response_data()). mist_websocket_application(Req, App, Flags, On_error) -> mist:websocket(Req, fun(Runtime, Conn, Msg) -> case Msg of {text, Msg@1} -> case (erlang:element(3, erlang:element(3, App)))(Msg@1) of {ok, Decoded_msg} -> gleam@erlang@process:send( Runtime, dispatch(Decoded_msg) ); {error, Decode_error} -> On_error(Decode_error) end, gleam@otp@actor:continue(Runtime); {binary, _} -> gleam@otp@actor:continue(Runtime); {custom, Msg@2} -> _assert_subject = case (erlang:element( 2, erlang:element(3, App) ))(Msg@2) of {ok, Msg@3} -> mist:send_text_frame(Conn, Msg@3); {error, _} -> {ok, nil} end, {ok, _} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"omnimessage_server"/utf8>>, function => <<"mist_websocket_application"/utf8>>, line => 297}) end, gleam@otp@actor:continue(Runtime); closed -> {stop, normal}; shutdown -> {stop, normal} end end, fun(_) -> Self = gleam@erlang@process:new_subject(), _assert_subject@1 = start_actor(App, Flags), {ok, Runtime@1} = case _assert_subject@1 of {ok, _} -> _assert_subject@1; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@1, module => <<"omnimessage_server"/utf8>>, function => <<"mist_websocket_application"/utf8>>, line => 270}) end, gleam@erlang@process:send( Runtime@1, subscribe( <<"OMNIMESSAGE_AUTO_MIST"/utf8>>, fun(_capture) -> gleam@erlang@process:send(Self, _capture) end ) ), {Runtime@1, {some, begin _pipe = gleam_erlang_ffi:new_selector(), gleam@erlang@process:selecting( _pipe, Self, fun gleam@function:identity/1 ) end}} end, fun(Runtime@2) -> gleam@erlang@process:send(Runtime@2, shutdown()) end).