libero
RPC dispatch and client stub generator.
Scans server/src/server/**/*.gleam for pub fns marked with a
/// @rpc doc comment and produces:
-
client/src/client/rpc/<module>.gleam, per-module labeled stub functions that look like ordinary Gleam functions to the client developer. Each stub takes the same labels as the server function (minus the first “session context” param) plus anon_responsecallback, and returnsEffect(msg). -
server/src/server/rpc_dispatch_generated.gleam, a flat case expression that receives a decoded call envelope, looks up the function by wire name, coerces the positional args, and calls the real server function with the session context prepended.
Conventions
-
The first parameter of an @rpc function is the session context (e.g.
sqlight.Connection) and is injected from the dispatch’sdbargument. It is NOT part of the wire args. -
The wire name is derived from the server file path and function name:
server/src/server/records.gleam+save→"records.save". Nested modules work:server/src/server/admin/items.gleam+create→"admin.items.create". -
Types in parameter positions and return types should be reachable from the generated stub (i.e. from a shared package). The generator walks the server file’s imports to resolve unqualified type names and emits matching imports in the stub.
-
Doc comments are discarded by glance, so
/// @rpcis found by preprocessing the source text to build a set of annotated function names, then each function’s signature is extracted via glance.