Current section
Files
Jump to
Current section
Files
src/libero@rpc.erl
-module(libero@rpc).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/libero/rpc.gleam").
-export([call_by_name/4]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Client-side RPC machinery.\n"
"\n"
" `call_by_name` is the low-level entrypoint used by Libero-generated\n"
" stubs. It takes the WebSocket URL, the wire name, the args, and a\n"
" wrap callback that produces the Lustre message to dispatch when\n"
" the response arrives.\n"
"\n"
" The JS FFI (rpc_ffi.mjs) auto-opens the WebSocket on first call\n"
" and caches the connection. Calls issued before the socket is open\n"
" are queued and flushed on the open event.\n"
"\n"
" Developers don't usually call this module directly. They import\n"
" the per-module stubs the Libero generator writes into their\n"
" client package, and those stubs internally delegate here.\n"
).
-file("src/libero/rpc.gleam", 47).
-spec ffi_call(
binary(),
binary(),
any(),
fun((gleam@dynamic:dynamic_()) -> nil)
) -> nil.
ffi_call(Url, Name, Args, On_response) ->
_ = Url,
_ = Name,
_ = Args,
_ = On_response,
erlang:error(#{gleam_error => panic,
message => <<"libero/rpc is a JavaScript-only module, unreachable on Erlang target"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"libero/rpc"/utf8>>,
function => <<"ffi_call"/utf8>>,
line => 57}).
-file("src/libero/rpc.gleam", 61).
-spec unsafe_coerce(gleam@dynamic:dynamic_()) -> any().
unsafe_coerce(Value) ->
_ = Value,
erlang:error(#{gleam_error => panic,
message => <<"libero/rpc is a JavaScript-only module, unreachable on Erlang target"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"libero/rpc"/utf8>>,
function => <<"unsafe_coerce"/utf8>>,
line => 63}).
-file("src/libero/rpc.gleam", 25).
?DOC(
" Invoke a server RPC by wire name, with typed args and a wrap\n"
" callback. Called by generated stubs.\n"
"\n"
" The `url` is read from a generated `rpc_config` module in the\n"
" consumer's client package, not from this library, so each\n"
" consumer can configure their own WebSocket endpoint.\n"
).
-spec call_by_name(binary(), binary(), any(), fun((any()) -> TWV)) -> lustre@effect:effect(TWV).
call_by_name(Url, Name, Args, Wrap) ->
lustre@effect:from(
fun(Dispatch) ->
ffi_call(
Url,
Name,
Args,
fun(Dyn) -> Dispatch(Wrap(unsafe_coerce(Dyn))) end
)
end
).